Class: Shadcn::CommandItemComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/shadcn/command_item_component.rb

Overview

Command Item component - individual selectable command

Constant Summary collapse

BASE_CLASSES =
"relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0"

Instance Attribute Summary

Attributes inherited from BaseComponent

#class_name, #data, #html_options

Instance Method Summary collapse

Methods inherited from BaseComponent

#content

Methods included from Rails::Helpers::ClassNameHelper

#cn

Constructor Details

#initialize(value: nil, disabled: false, on_select: nil, **options) ⇒ CommandItemComponent

Returns a new instance of CommandItemComponent.

Parameters:

  • value (String, nil) (defaults to: nil)

    The searchable value (defaults to content text)

  • disabled (Boolean) (defaults to: false)

    Whether the item is disabled

  • on_select (String) (defaults to: nil)

    JavaScript to execute on select



16
17
18
19
20
21
# File 'app/components/shadcn/command_item_component.rb', line 16

def initialize(value: nil, disabled: false, on_select: nil, **options)
  super(**options)
  @value = value
  @disabled = disabled
  @on_select = on_select
end

Instance Method Details

#callObject



23
24
25
# File 'app/components/shadcn/command_item_component.rb', line 23

def call
  (:div, item_content, **item_attributes)
end