Class: Shadcn::SidebarMenuButtonComponent

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

Overview

SidebarMenuButton component - button/link within menu item

Constant Summary collapse

VARIANTS =
{
  default: "hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
  outline: "bg-background shadow-[0_0_0_1px_hsl(var(--sidebar-border))] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground hover:shadow-[0_0_0_1px_hsl(var(--sidebar-accent))]"
}.freeze
SIZES =
{
  default: "h-8 text-sm",
  sm: "h-7 text-xs",
  lg: "h-12 text-sm group-data-[collapsible=icon]:!p-0"
}.freeze
BASE_CLASSES =
"peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left outline-none ring-sidebar-ring transition-[width,height,padding] hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 active:bg-sidebar-accent active:text-sidebar-accent-foreground disabled:pointer-events-none disabled:opacity-50 group-has-[[data-sidebar=menu-action]]/menu-item:pr-8 aria-disabled:pointer-events-none aria-disabled:opacity-50 data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium data-[active=true]:text-sidebar-accent-foreground data-[state=open]:hover:bg-sidebar-accent data-[state=open]:hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:!size-8 group-data-[collapsible=icon]:!p-2 [&>span:last-child]:truncate [&>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(variant: :default, size: :default, is_active: false, as_child: false, tooltip: nil, href: nil, **options) ⇒ SidebarMenuButtonComponent

Returns a new instance of SidebarMenuButtonComponent.



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

def initialize(variant: :default, size: :default, is_active: false, as_child: false, tooltip: nil, href: nil, **options)
  super(**options)
  @variant = variant.to_sym
  @size = size.to_sym
  @is_active = is_active
  @as_child = as_child
  @tooltip = tooltip
  @href = href
end

Instance Method Details

#callObject



29
30
31
32
33
34
35
# File 'app/components/shadcn/sidebar_menu_button_component.rb', line 29

def call
  if @href
    (:a, content, button_attributes.merge(href: @href))
  else
    (:button, content, button_attributes.merge(type: "button"))
  end
end