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
Overview
The Label component renders a DaisyUI styled label for form inputs. It can be used with any form input component and provides visual styling consistent with other Daisy UI elements.
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
Constructor Details
#initialize(title = nil, **kws) ⇒ LabelComponent
Instantiate a new Label component.
37 38 39 40 41 42 43 |
# File 'app/components/daisy/data_input/label_component.rb', line 37 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.
20 21 22 |
# File 'app/components/daisy/data_input/label_component.rb', line 20 def for @for end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
20 21 22 |
# File 'app/components/daisy/data_input/label_component.rb', line 20 def required @required end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
20 21 22 |
# File 'app/components/daisy/data_input/label_component.rb', line 20 def title @title end |
Instance Method Details
#before_render ⇒ Object
Calls the #setup_component method before rendering the component.
48 49 50 |
# File 'app/components/daisy/data_input/label_component.rb', line 48 def before_render setup_component end |
#call ⇒ Object
Renders the component with its content.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/components/daisy/data_input/label_component.rb', line 72 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.
59 60 61 62 63 64 65 66 67 |
# File 'app/components/daisy/data_input/label_component.rb', line 59 def setup_component set_tag_name(:component, :label) add_css(:component, "label") add_html(:component, { for: @for }) end |