Class: Shadcn::Select::Item::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/shadcn/select/item/component.rb

Overview

SelectItem

Constant Summary collapse

INDICATOR_CLASSES =
"absolute right-2 flex size-3.5 items-center justify-center"

Constants inherited from ApplicationViewComponent

ApplicationViewComponent::CONTENTS_STYLE, ApplicationViewComponent::VOID_TAGS

Instance Attribute Summary collapse

Attributes inherited from ApplicationViewComponent

#attributes

Instance Method Summary collapse

Methods inherited from ApplicationViewComponent

#css_classes, default_tag, #merged_style, #render_element, #shadcn_t, slot_name, #style_variants, #tag_name

Constructor Details

#initialize(value:, selected: false, disabled: false, **attributes) ⇒ Component

Returns a new instance of Component.



27
28
29
30
31
32
# File 'app/components/shadcn/select/item/component.rb', line 27

def initialize(value:, selected: false, disabled: false, **attributes)
  @value = value.to_s
  @selected = selected
  @disabled = disabled
  super(**attributes)
end

Instance Attribute Details

#disabledObject (readonly)

Returns the value of attribute disabled.



25
26
27
# File 'app/components/shadcn/select/item/component.rb', line 25

def disabled
  @disabled
end

#selectedObject (readonly)

Returns the value of attribute selected.



25
26
27
# File 'app/components/shadcn/select/item/component.rb', line 25

def selected
  @selected
end

#valueObject (readonly)

Returns the value of attribute value.



25
26
27
# File 'app/components/shadcn/select/item/component.rb', line 25

def value
  @value
end

Instance Method Details

#callObject



48
49
50
# File 'app/components/shadcn/select/item/component.rb', line 48

def call
  render_element(body: safe_join([ indicator, item_text ]))
end

#element_attributes(**defaults) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/components/shadcn/select/item/component.rb', line 34

def element_attributes(**defaults)
  super(**{
    role: "option",
    tabindex: "-1",
    "aria-selected" => selected.to_s,
    "data-value" => value,
    "data-state" => (selected ? "checked" : "unchecked"),
    "data-disabled" => (true if disabled),
    "data-shadcn--select-target" => "item",
    "data-action" => "click->shadcn--select#select " \
                     "pointerenter->shadcn--select#pointerenter"
  }.merge(defaults))
end