Class: Daisy::DataInput::RadioButtonComponent
- Inherits:
-
LocoMotion::BaseComponent
- Object
- ViewComponent::Base
- LocoMotion::BaseComponent
- Daisy::DataInput::RadioButtonComponent
- Defined in:
- app/components/daisy/data_input/radio_button_component.rb
Overview
The Radio Button component renders a DaisyUI styled radio button input. It can be used standalone or with a form builder, and is ideal for creating option groups where users must select exactly one choice.
Direct Known Subclasses
FilterComponent::FilterOptionComponent, FilterComponent::FilterResetComponent
Constant Summary
Constants inherited from LocoMotion::BaseComponent
LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS
Instance Attribute Summary collapse
-
#checked ⇒ Object
readonly
Returns the value of attribute checked.
-
#disabled ⇒ Object
readonly
Returns the value of attribute disabled.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Attributes inherited from LocoMotion::BaseComponent
Instance Method Summary collapse
-
#before_render ⇒ Object
Calls the #setup_component method before rendering the component.
-
#call ⇒ Object
Renders the component inline with no additional whitespace.
-
#initialize(**kws) ⇒ RadioButtonComponent
constructor
Instantiate a new Radio Button component.
-
#setup_component ⇒ Object
Sets up the component by configuring the tag name, CSS classes, and HTML attributes.
Methods inherited from LocoMotion::BaseComponent
build, #component_ref, #config_option, #cssify, define_modifier, define_modifiers, define_part, define_parts, define_size, define_sizes, #empty_part_content, #inspect, #part, register_component_initializer, register_component_setup, #rendered_css, #rendered_data, #rendered_html, #rendered_stimulus_controllers, #rendered_tag_name, renders_many, renders_one, set_component_name, #set_loco_parent, #strip_spaces
Constructor Details
#initialize(**kws) ⇒ RadioButtonComponent
Instantiate a new Radio Button component.
40 41 42 43 44 45 46 47 48 49 |
# File 'app/components/daisy/data_input/radio_button_component.rb', line 40 def initialize(**kws) super @name = config_option(:name) @id = config_option(:id) @value = config_option(:value) @checked = config_option(:checked, false) @disabled = config_option(:disabled, false) @required = config_option(:required, false) end |
Instance Attribute Details
#checked ⇒ Object (readonly)
Returns the value of attribute checked.
18 19 20 |
# File 'app/components/daisy/data_input/radio_button_component.rb', line 18 def checked @checked end |
#disabled ⇒ Object (readonly)
Returns the value of attribute disabled.
18 19 20 |
# File 'app/components/daisy/data_input/radio_button_component.rb', line 18 def disabled @disabled end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
18 19 20 |
# File 'app/components/daisy/data_input/radio_button_component.rb', line 18 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
18 19 20 |
# File 'app/components/daisy/data_input/radio_button_component.rb', line 18 def name @name end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
18 19 20 |
# File 'app/components/daisy/data_input/radio_button_component.rb', line 18 def required @required end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
18 19 20 |
# File 'app/components/daisy/data_input/radio_button_component.rb', line 18 def value @value end |
Instance Method Details
#before_render ⇒ Object
Calls the #setup_component method before rendering the component.
54 55 56 |
# File 'app/components/daisy/data_input/radio_button_component.rb', line 54 def before_render setup_component end |
#call ⇒ Object
Renders the component inline with no additional whitespace.
84 85 86 |
# File 'app/components/daisy/data_input/radio_button_component.rb', line 84 def call part(:component) end |
#setup_component ⇒ Object
Sets up the component by configuring the tag name, CSS classes, and HTML attributes. Sets the tag to input with type ‘radio’ and adds the ‘radio’ CSS class.
This configures the name, id, value, disabled state, required state, and checked state of the radio button.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/components/daisy/data_input/radio_button_component.rb', line 65 def setup_component set_tag_name(:component, :input) add_css(:component, "radio") unless @skip_styling add_html(:component, { type: "radio", name: @name, id: @id, value: @value, checked: @checked, disabled: @disabled, required: @required }) end |