Class: Daisy::DataInput::FilterComponent::FilterOptionComponent

Inherits:
RadioButtonComponent show all
Defined in:
app/components/daisy/data_input/filter_component.rb

Constant Summary

Constants inherited from LocoMotion::BaseComponent

LocoMotion::BaseComponent::EMPTY_PART_IGNORED_TAGS, LocoMotion::BaseComponent::SELF_CLOSING_TAGS

Instance Attribute Summary

Attributes inherited from RadioButtonComponent

#checked, #disabled, #id, #name, #required, #value

Attributes inherited from LocoMotion::BaseComponent

#config, #loco_parent

Instance Method Summary collapse

Methods inherited from RadioButtonComponent

#call, #setup_component

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) ⇒ FilterOptionComponent

Initialize a new filter option component.

Options Hash (**kws):

  • label (String)

    The aria-label for the radio button.



48
49
50
51
52
53
54
# File 'app/components/daisy/data_input/filter_component.rb', line 48

def initialize(**kws)
  super(**kws)

  @label = config_option(:label)
  @index = config_option(:index)
  @skip_styling = true
end

Instance Method Details

#before_renderObject

Setup the component before rendering.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/components/daisy/data_input/filter_component.rb', line 59

def before_render
  # Make sure to pull the default name from the parent
  @name = config_option(:name, loco_parent.name)
  @id = config_option(:id, "#{loco_parent.id}_#{@index}")

  # Call the parent setup first
  super

  # Add btn class for styling
  add_css(:component, "btn")
  add_html(:component, { id: @id })

  # Add aria-label if specified
  if @label.present?
    add_html(:component, { "aria-label": @label })
  end
end