Class: Daisy::DataInput::SelectComponent::SelectOptionComponent

Inherits:
LocoMotion::BasicComponent show all
Defined in:
app/components/daisy/data_input/select_component.rb

Constant Summary

Constants inherited from LocoMotion::BaseComponent

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

Instance Attribute Summary collapse

Attributes inherited from LocoMotion::BaseComponent

#config, #loco_parent

Instance Method Summary collapse

Methods inherited from LocoMotion::BasicComponent

name

Methods inherited from LocoMotion::BaseComponent

#before_render, 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(value:, label:, selected: false, disabled: false, css: "", html: {}, **kws) ⇒ SelectOptionComponent

Initialize a new select option component.

Parameters:

  • value (String, Symbol, Integer)

    The value of the option.

  • label (String)

    The label to display for the option.

  • selected (Boolean) (defaults to: false)

    Whether the option is selected. Defaults to false.

  • disabled (Boolean) (defaults to: false)

    Whether the option is disabled. Defaults to false.

  • css (String) (defaults to: "")

    CSS classes to apply to the option.

  • html (Hash) (defaults to: {})

    HTML attributes to apply to the option.



63
64
65
66
67
68
69
70
71
# File 'app/components/daisy/data_input/select_component.rb', line 63

def initialize(value:, label:, selected: false, disabled: false, css: "", html: {}, **kws)
  @value = value
  @label = label
  @selected = selected
  @disabled = disabled
  @css = css
  @html = html
  super(**kws)
end

Instance Attribute Details

#disabledObject (readonly)

Returns the value of attribute disabled.



46
47
48
# File 'app/components/daisy/data_input/select_component.rb', line 46

def disabled
  @disabled
end

#labelObject (readonly)

Returns the value of attribute label.



46
47
48
# File 'app/components/daisy/data_input/select_component.rb', line 46

def label
  @label
end

#selectedObject (readonly)

Returns the value of attribute selected.



46
47
48
# File 'app/components/daisy/data_input/select_component.rb', line 46

def selected
  @selected
end

#valueObject (readonly)

Returns the value of attribute value.



46
47
48
# File 'app/components/daisy/data_input/select_component.rb', line 46

def value
  @value
end

Instance Method Details

#callString

Renders the option element with the appropriate attributes.

Returns:

  • (String)

    The rendered HTML for the option element.



78
79
80
81
82
83
84
85
# File 'app/components/daisy/data_input/select_component.rb', line 78

def call
  (:option, label, {
    value: value,
    selected: selected,
    disabled: disabled,
    class: @css
  }.merge(@html))
end