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
Methods included from LocoMotion::Concerns::InspectableComponent
Constructor Details
#initialize(**kws) ⇒ FilterComponent
Initialize a new filter component.
128 129 130 131 132 133 134 135 |
# File 'app/components/daisy/data_input/filter_component.rb', line 128 def initialize(**kws) super(**kws) @name = config_option(:name) @id = config_option(:id, SecureRandom.uuid) @options_list = config_option(:options) @value = config_option(:value) end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
114 115 116 |
# File 'app/components/daisy/data_input/filter_component.rb', line 114 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
114 115 116 |
# File 'app/components/daisy/data_input/filter_component.rb', line 114 def name @name end |
Instance Method Details
#before_render ⇒ Object
Setup the component before rendering.
140 141 142 143 144 |
# File 'app/components/daisy/data_input/filter_component.rb', line 140 def before_render super setup_component end |
#default_reset_button ⇒ Object
146 147 148 |
# File 'app/components/daisy/data_input/filter_component.rb', line 146 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.
183 184 185 186 187 188 189 190 191 192 193 |
# File 'app/components/daisy/data_input/filter_component.rb', line 183 def result = +"" if .each { |option| result << render(option) } elsif .present? .each { |option| result << render(option) } 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.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'app/components/daisy/data_input/filter_component.rb', line 156 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 |