Class: Daisy::DataInput::LabelComponent
- Inherits:
-
LocoMotion::BaseComponent
- Object
- ViewComponent::Base
- LocoMotion::BaseComponent
- Daisy::DataInput::LabelComponent
- Defined in:
- app/components/daisy/data_input/label_component.rb
Constant Summary
Constants inherited from LocoMotion::BaseComponent
LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS
Instance Attribute Summary collapse
-
#for ⇒ Object
readonly
Returns the value of attribute for.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
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 with its content.
-
#initialize(title = nil, **kws) ⇒ LabelComponent
constructor
Instantiate a new Label 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
Methods included from LocoMotion::Concerns::InspectableComponent
Constructor Details
#initialize(title = nil, **kws) ⇒ LabelComponent
Instantiate a new Label component.
39 40 41 42 43 44 45 |
# File 'app/components/daisy/data_input/label_component.rb', line 39 def initialize(title = nil, **kws) super @for = config_option(:for) @title = config_option(:title, title) @required = config_option(:required, false) end |
Instance Attribute Details
#for ⇒ Object (readonly)
Returns the value of attribute for.
22 23 24 |
# File 'app/components/daisy/data_input/label_component.rb', line 22 def for @for end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
22 23 24 |
# File 'app/components/daisy/data_input/label_component.rb', line 22 def required @required end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
22 23 24 |
# File 'app/components/daisy/data_input/label_component.rb', line 22 def title @title end |
Instance Method Details
#before_render ⇒ Object
Calls the #setup_component method before rendering the component.
50 51 52 |
# File 'app/components/daisy/data_input/label_component.rb', line 50 def before_render setup_component end |
#call ⇒ Object
Renders the component with its content.
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/components/daisy/data_input/label_component.rb', line 74 def call part(:component) do if content? content elsif @title content_tag(:span, @title, class: "label-text") else # Fallback to empty content "" end end end |
#setup_component ⇒ Object
Sets up the component by configuring the tag name, CSS classes, and HTML attributes. Sets the tag to ‘label’ and adds the ‘label’ CSS class.
This configures the ‘for’ attribute to connect the label to its input and adds appropriate styling for required inputs when needed.
61 62 63 64 65 66 67 68 69 |
# File 'app/components/daisy/data_input/label_component.rb', line 61 def setup_component set_tag_name(:component, :label) add_css(:component, "label") add_html(:component, { for: @for }) end |