Class: Anchor::RadioButtonCollectionComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/anchor/radio_button_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) ⇒ RadioButtonCollectionComponent

Returns a new instance of RadioButtonCollectionComponent.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/components/anchor/radio_button_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/radio_button_collection_component.rb', line 3

def attribute
  @attribute
end

#descriptionsObject (readonly)

Returns the value of attribute descriptions.



3
4
5
# File 'app/components/anchor/radio_button_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/radio_button_collection_component.rb', line 3

def form_builder
  @form_builder
end

Instance Method Details

#optionsObject



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

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

#radio(radio:) ⇒ Object



32
33
34
35
36
37
38
# File 'app/components/anchor/radio_button_collection_component.rb', line 32

def radio(radio:)
  RadioButtonComponent.new(
    radio:,
    attribute:,
    form_builder:
  )
end