Class: Daisy::DataInput::FilterComponent
- Inherits:
-
LocoMotion::BaseComponent
- Object
- ViewComponent::Base
- LocoMotion::BaseComponent
- Daisy::DataInput::FilterComponent
- Includes:
- ViewComponent::SlotableDefault
- Defined in:
- app/components/daisy/data_input/filter_component.rb
Defined Under Namespace
Classes: FilterOptionComponent, FilterResetComponent
Constant Summary
Constants inherited from LocoMotion::BaseComponent
LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from LocoMotion::BaseComponent
Instance Method Summary collapse
-
#before_render ⇒ Object
Setup the component before rendering.
- #default_reset_button ⇒ Object
-
#initialize(**kws) ⇒ FilterComponent
constructor
Initialize a new filter component.
-
#render_filter_options ⇒ String
Renders the filter options based on the configuration.
-
#standard_options ⇒ Array<FilterOptionComponent>
Converts the options array into FilterOptionComponent instances.
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) ⇒ FilterComponent
Initialize a new filter component.
130 131 132 133 134 135 136 137 |
# File 'app/components/daisy/data_input/filter_component.rb', line 130 def initialize(**kws) super(**kws) @name = config_option(:name) @id = config_option(:id, SecureRandom.uuid) = config_option(:options) @value = config_option(:value) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
116 117 118 |
# File 'app/components/daisy/data_input/filter_component.rb', line 116 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
116 117 118 |
# File 'app/components/daisy/data_input/filter_component.rb', line 116 def name @name end |
Instance Method Details
#before_render ⇒ Object
Setup the component before rendering.
142 143 144 145 146 |
# File 'app/components/daisy/data_input/filter_component.rb', line 142 def before_render super setup_component end |
#default_reset_button ⇒ Object
148 149 150 |
# File 'app/components/daisy/data_input/filter_component.rb', line 148 def FilterResetComponent.new(name: @name) end |
#render_filter_options ⇒ String
Renders the filter options based on the configuration. This method is used by the template to render options consistently.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'app/components/daisy/data_input/filter_component.rb', line 185 def result = "" if .each do |option| result += render(option) end elsif .present? .each do |option| result += render(option) end end result.html_safe end |
#standard_options ⇒ Array<FilterOptionComponent>
Converts the options array into FilterOptionComponent instances. Handles both hash options (with label keys) and simple string/symbol options.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'app/components/daisy/data_input/filter_component.rb', line 158 def return [] unless .map.with_index do |option, index| label = option.is_a?(Hash) ? option[:label] : option.to_s value = option.is_a?(Hash) ? option[:value] : option # Check if this option should be selected based on the component's value checked = @value.present? && @value.to_s == value.to_s Daisy::DataInput::FilterComponent::FilterOptionComponent.new( loco_parent: component_ref, name: @name, label: label, value: value, checked: checked, index: index.to_s # Ensure index is a string ) end end |