Class: Shadcn::DropdownMenuItemComponent

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

Overview

Dropdown Menu Item component

Constant Summary collapse

BASE_CLASSES =
"relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0"
VARIANTS =
{
  default: "",
  destructive: "text-destructive focus:bg-destructive focus:text-destructive-foreground"
}.freeze

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(href: nil, variant: :default, disabled: false, inset: false, **options, &block) ⇒ DropdownMenuItemComponent

Returns a new instance of DropdownMenuItemComponent.

Parameters:

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

    Link URL

  • variant (Symbol) (defaults to: :default)

    Item variant (:default, :destructive)

  • disabled (Boolean) (defaults to: false)

    Whether item is disabled

  • inset (Boolean) (defaults to: false)

    Whether to add left padding for icons



21
22
23
24
25
26
27
# File 'app/components/shadcn/dropdown_menu_item_component.rb', line 21

def initialize(href: nil, variant: :default, disabled: false, inset: false, **options, &block)
  super(**options, &block)
  @href = href
  @variant = variant.to_sym
  @disabled = disabled
  @inset = inset
end

Instance Method Details

#callObject



29
30
31
32
# File 'app/components/shadcn/dropdown_menu_item_component.rb', line 29

def call
  tag_name = @href ? :a : :div
  (tag_name, item_content, item_attributes)
end