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

Attributes inherited from BaseComponent

#html_attributes

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseComponent

classname_merger, #initialize, stimulus_merger, use_stimulus?, #with_html_attributes, #with_html_class

Methods inherited from Base

fox_tail_config

Constructor Details

This class inherits a constructor from FoxTail::BaseComponent

Class Method Details

.stimulus_controller_nameObject



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_renderObject



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

#callObject



42
43
44
# File 'app/components/fox_tail/radio_button_component.rb', line 42

def call
  tag.input(html_attributes)
end

#checked?Boolean

Returns:

  • (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_optionsObject



28
29
30
# File 'app/components/fox_tail/radio_button_component.rb', line 28

def stimulus_controller_options
  {}
end

#use_stimulus?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/components/fox_tail/radio_button_component.rb', line 24

def use_stimulus?
  super && controlled?
end

#valueObject



13
14
15
# File 'app/components/fox_tail/radio_button_component.rb', line 13

def value
  options[:value] ||= value_from_object
end