Class: Anchor::CheckBoxCollectionComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/anchor/check_box_collection_component.rb

Constant Summary

Constants included from ViewHelper

ViewHelper::ANCHOR_HELPERS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Component

generate_id

Methods included from ViewHelper

#anchor_form_with, #anchor_svg, #deep_blank?, #merge_options, #popover_trigger_attributes

Methods included from FetchOrFallbackHelper

#fetch_or_fallback

Constructor Details

#initialize(form_builder:, attribute:, collection:, value_method:, text_method:, descriptions: nil, **options) ⇒ CheckBoxCollectionComponent

Returns a new instance of CheckBoxCollectionComponent.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/components/anchor/check_box_collection_component.rb', line 5

def initialize(
  form_builder:,
  attribute:,
  collection:,
  value_method:,
  text_method:,
  descriptions: nil,
  **options
)
  @form_builder = form_builder
  @attribute = attribute
  @collection = collection
  @value_method = value_method
  @text_method = text_method
  @descriptions = descriptions
  @options = options

  super()
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



3
4
5
# File 'app/components/anchor/check_box_collection_component.rb', line 3

def attribute
  @attribute
end

#descriptionsObject (readonly)

Returns the value of attribute descriptions.



3
4
5
# File 'app/components/anchor/check_box_collection_component.rb', line 3

def descriptions
  @descriptions
end

#form_builderObject (readonly)

Returns the value of attribute form_builder.



3
4
5
# File 'app/components/anchor/check_box_collection_component.rb', line 3

def form_builder
  @form_builder
end

Instance Method Details

#check_box(check_box:) ⇒ Object



31
32
33
# File 'app/components/anchor/check_box_collection_component.rb', line 31

def check_box(check_box:)
  CheckBoxComponent.new(check_box:, attribute:, form_builder:)
end

#optionsObject



25
26
27
28
29
# File 'app/components/anchor/check_box_collection_component.rb', line 25

def options
  @options.merge(
    class: Array(@options.delete(:class)) + CheckBoxComponent::INPUT_CLASSES
  )
end