Module: LocoMotion::Concerns::LabelableComponent
- Extended by:
- ActiveSupport::Concern
- Included in:
- Daisy::DataInput::CallyInputComponent, Daisy::DataInput::CheckboxComponent, Daisy::DataInput::SelectComponent, Daisy::DataInput::TextInputComponent
- Defined in:
- lib/loco_motion/concerns/labelable_component.rb
Overview
Can be included in relevant components to add labeling functionality. This adds support for start, end, and floating labels that can either be provided as plain text or customized via slots.
Instance Method Summary collapse
-
#before_render ⇒ Object
Sets up the tag names for the label parts before rendering the component.
-
#has_any_label? ⇒ Boolean
Checks if any type of label is present.
-
#has_end_label? ⇒ Boolean
Checks if an end label is present.
-
#has_floating_label? ⇒ Boolean
Checks if a floating label is present.
-
#has_start_label? ⇒ Boolean
Checks if a start label is present.
-
#initialize(*instance_args, **instance_kws, &instance_block) ⇒ Object
Initializes the component and sets up the label options.
Instance Method Details
#before_render ⇒ Object
Sets up the tag names for the label parts before rendering the component. This method is called automatically during the component rendering lifecycle.
Note that CSS classes for labels must be handled by the implementing component since requirements differ for each type of input component.
96 97 98 99 100 101 102 103 |
# File 'lib/loco_motion/concerns/labelable_component.rb', line 96 def before_render super set_tag_name(:label_wrapper, :label) set_tag_name(:start, :span) set_tag_name(:end, :span) set_tag_name(:floating, :span) end |
#has_any_label? ⇒ Boolean
Checks if any type of label is present.
110 111 112 |
# File 'lib/loco_motion/concerns/labelable_component.rb', line 110 def has_any_label? has_start_label? || has_end_label? || has_floating_label? end |
#has_end_label? ⇒ Boolean
Checks if an end label is present.
128 129 130 |
# File 'lib/loco_motion/concerns/labelable_component.rb', line 128 def has_end_label? end? || @end || config_option(:end).present? end |
#has_floating_label? ⇒ Boolean
Checks if a floating label is present.
137 138 139 |
# File 'lib/loco_motion/concerns/labelable_component.rb', line 137 def has_floating_label? floating? || @floating || config_option(:floating).present? end |
#has_start_label? ⇒ Boolean
Checks if a start label is present.
119 120 121 |
# File 'lib/loco_motion/concerns/labelable_component.rb', line 119 def has_start_label? start? || @start || config_option(:start).present? end |
#initialize(*instance_args, **instance_kws, &instance_block) ⇒ Object
Initializes the component and sets up the label options.
77 78 79 80 81 82 83 84 85 86 |
# File 'lib/loco_motion/concerns/labelable_component.rb', line 77 def initialize(*instance_args, **instance_kws, &instance_block) super(*instance_args, **instance_kws, &instance_block) @floating_placeholder = config_option(:floating_placeholder) @start = config_option(:start) @end = config_option(:end) @floating = config_option(:floating, @floating_placeholder) @placeholder = config_option(:placeholder, @floating_placeholder) end |