Class: Polaris::BaseRadioButton

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

Constant Summary

Constants included from ViewHelper

ViewHelper::POLARIS_HELPERS, ViewHelper::POLARIS_TEXT_STYLES

Constants included from FetchOrFallbackHelper

FetchOrFallbackHelper::InvalidValueError

Instance Method Summary collapse

Methods included from ViewHelper

#polaris_body_styles, #polaris_html_classes, #polaris_html_styles, #polaris_icon_source

Methods included from StylesListHelper

#styles_list

Methods included from OptionHelper

#append_option, #prepend_option

Methods included from FetchOrFallbackHelper

#fetch_or_fallback, #fetch_or_fallback_boolean, #fetch_or_fallback_nested

Methods included from ClassNameHelper

#class_names

Constructor Details

#initialize(form: nil, attribute: nil, name: nil, checked: false, disabled: false, value: nil, **system_arguments) ⇒ BaseRadioButton

Returns a new instance of BaseRadioButton.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/components/polaris/base_radio_button.rb', line 3

def initialize(
  form: nil,
  attribute: nil,
  name: nil,
  checked: false,
  disabled: false,
  value: nil,
  **system_arguments
)
  @form = form
  @attribute = attribute
  @name = name
  @checked = checked
  @disabled = disabled
  @value = value
  @system_arguments = system_arguments
end

Instance Method Details

#callObject



30
31
32
33
34
35
36
# File 'app/components/polaris/base_radio_button.rb', line 30

def call
  if @form.present? && @attribute.present?
    @form.radio_button(@attribute, @value, system_arguments)
  else
    radio_button_tag(@name, @value, @checked, system_arguments)
  end
end

#system_argumentsObject



21
22
23
24
25
26
27
28
# File 'app/components/polaris/base_radio_button.rb', line 21

def system_arguments
  @system_arguments.tap do |opts|
    opts[:disabled] = true if @disabled
    opts[:aria] ||= {}
    opts[:aria][:checked] = @checked
    opts[:class] = opts.delete(:classes)
  end
end