Class: Shadcn::Combobox::Chip::Component

Inherits:
ApplicationViewComponent show all
Defined in:
app/components/shadcn/combobox/chip/component.rb

Overview

One chosen value, with the X that takes it back off. show_remove: is upstream's showRemove, on by default there too.

Constant Summary collapse

REMOVE_CLASSES =
"-ml-1 opacity-50 hover:opacity-100"

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: nil, show_remove: true, **attributes) ⇒ Component

Returns a new instance of Component.



25
26
27
28
29
# File 'app/components/shadcn/combobox/chip/component.rb', line 25

def initialize(value: nil, show_remove: true, **attributes)
  @value = value
  @show_remove = show_remove
  super(**attributes)
end

Instance Attribute Details

#show_removeObject (readonly)

Returns the value of attribute show_remove.



23
24
25
# File 'app/components/shadcn/combobox/chip/component.rb', line 23

def show_remove
  @show_remove
end

#valueObject (readonly)

Returns the value of attribute value.



23
24
25
# File 'app/components/shadcn/combobox/chip/component.rb', line 23

def value
  @value
end

Instance Method Details

#callObject



38
39
40
# File 'app/components/shadcn/combobox/chip/component.rb', line 38

def call
  render_element(body: safe_join([ content, remove ].compact))
end

#element_attributes(**defaults) ⇒ Object



31
32
33
34
35
36
# File 'app/components/shadcn/combobox/chip/component.rb', line 31

def element_attributes(**defaults)
  super(**{
    "data-value" => value,
    "data-shadcn--combobox-target" => "chip"
  }.compact.merge(defaults))
end