Class: FoxTail::RadioButtonComponent
- Inherits:
-
BaseComponent
show all
- Includes:
- Concerns::Formable, Concerns::HasStimulusController
- Defined in:
- app/components/fox_tail/radio_button_component.rb
Defined Under Namespace
Classes: StimulusController
Instance Attribute Summary
#html_attributes
Class Method Summary
collapse
Instance Method Summary
collapse
classname_merger, #initialize, stimulus_merger, use_stimulus?, #with_html_attributes, #with_html_class
Methods inherited from Base
fox_tail_config
Class Method Details
.stimulus_controller_name ⇒ Object
47
48
49
|
# File 'app/components/fox_tail/radio_button_component.rb', line 47
def stimulus_controller_name
"form-field"
end
|
Instance Method Details
#before_render ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'app/components/fox_tail/radio_button_component.rb', line 32
def before_render
super
add_default_name_and_id_for_value value
html_attributes[:type] = :radio
html_attributes[:class] = classnames theme.apply(:root, self), html_class
html_attributes[:value] = value
html_attributes[:checked] = checked?
end
|
#call ⇒ Object
42
43
44
|
# File 'app/components/fox_tail/radio_button_component.rb', line 42
def call
tag.input(html_attributes)
end
|
#checked? ⇒ Boolean
17
18
19
20
21
22
|
# File 'app/components/fox_tail/radio_button_component.rb', line 17
def checked?
return !!options[:checked] if options.key? :checked
return false if object.blank?
value.to_s == value_from_object.to_s
end
|
#stimulus_controller_options ⇒ Object
28
29
30
|
# File 'app/components/fox_tail/radio_button_component.rb', line 28
def stimulus_controller_options
{}
end
|
#use_stimulus? ⇒ Boolean
24
25
26
|
# File 'app/components/fox_tail/radio_button_component.rb', line 24
def use_stimulus?
super && controlled?
end
|
#value ⇒ Object
13
14
15
|
# File 'app/components/fox_tail/radio_button_component.rb', line 13
def value
options[:value] ||= value_from_object
end
|