Class: Polaris::OptionList::RadioButtonComponent

Inherits:
Component
  • Object
show all
Defined in:
app/components/polaris/option_list/radio_button_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(label:, value:, wrapper_arguments: {}, **system_arguments) ⇒ RadioButtonComponent

Returns a new instance of RadioButtonComponent.



2
3
4
5
6
7
8
9
10
11
12
# File 'app/components/polaris/option_list/radio_button_component.rb', line 2

def initialize(
  label:,
  value:,
  wrapper_arguments: {},
  **system_arguments
)
  @label = label
  @value = value
  @wrapper_arguments = wrapper_arguments
  @system_arguments = system_arguments
end

Instance Method Details

#callObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/components/polaris/option_list/radio_button_component.rb', line 34

def call
  render(Polaris::BaseComponent.new(**wrapper_arguments)) do
    tag.label(
      class: "Polaris-OptionList-Option__SingleSelectOption",
      data: {
        polaris_option_list_target: "radioButton",
        action: "click->polaris-option-list#update"
      }
    ) do
      safe_join [
        radio_button,
        @label
      ]
    end
  end
end

#radio_buttonObject



51
52
53
# File 'app/components/polaris/option_list/radio_button_component.rb', line 51

def radio_button
  render Polaris::BaseRadioButton.new(value: @value, **system_arguments)
end

#system_argumentsObject



25
26
27
28
29
30
31
32
# File 'app/components/polaris/option_list/radio_button_component.rb', line 25

def system_arguments
  @system_arguments.tap do |opts|
    opts[:classes] = class_names(
      @system_arguments[:classes],
      "Polaris--hidden"
    )
  end
end

#wrapper_argumentsObject



14
15
16
17
18
19
20
21
22
23
# File 'app/components/polaris/option_list/radio_button_component.rb', line 14

def wrapper_arguments
  @wrapper_arguments.tap do |opts|
    opts[:tag] = "li"
    opts[:tabindex] = "-1"
    opts[:classes] = class_names(
      @wrapper_arguments[:classes],
      "Polaris-OptionList-Option"
    )
  end
end