33module RubyUI
44 class SidebarMenuButton < Base
55 VARIANT_CLASSES = {
6- default : " hover:bg-sidebar-accent hover:text-sidebar-accent-foreground" ,
6+ default : ' hover:bg-sidebar-accent hover:text-sidebar-accent-foreground' ,
77 outline :
8- " 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))]"
8+ ' 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))]'
99 } . freeze
1010
1111 SIZE_CLASSES = {
12- default : " h-8 text-sm" ,
13- sm : " h-7 text-xs" ,
14- lg : " h-12 text-sm group-data-[collapsible=icon]:!p-0"
12+ default : ' h-8 text-sm' ,
13+ sm : ' h-7 text-xs' ,
14+ lg : ' h-12 text-sm group-data-[collapsible=icon]:!p-0'
1515 } . freeze
1616
17- def initialize ( as : " button" , variant : :default , size : :default , active : false , **attrs )
17+ def initialize ( as : : button, variant : :default , size : :default , active : false , **attrs )
1818 raise ArgumentError , "Invalid variant: #{ variant } " unless VARIANT_CLASSES . key? ( variant )
1919 raise ArgumentError , "Invalid size: #{ size } " unless SIZE_CLASSES . key? ( size )
2020
@@ -26,20 +26,34 @@ def initialize(as: "button", variant: :default, size: :default, active: false, *
2626 end
2727
2828 def view_template ( &)
29- public_send ( @as , **attrs , &)
29+ tag ( @as , **attrs , &)
3030 end
3131
3232 private
3333
3434 def default_attrs
3535 {
3636 class : [
37- "peer/menu-button flex w-full items-center gap-2 overflow-hidden rounded-md p-2 text-left text-sm 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" ,
37+ 'peer/menu-button flex w-full items-center gap-2 overflow-hidden' ,
38+ 'rounded-md p-2 text-left text-sm outline-none ring-sidebar-ring' ,
39+ 'transition-[width,height,padding] hover:bg-sidebar-accent' ,
40+ 'hover:text-sidebar-accent-foreground focus-visible:ring-2' ,
41+ 'active:bg-sidebar-accent active:text-sidebar-accent-foreground' ,
42+ 'disabled:pointer-events-none disabled:opacity-50' ,
43+ 'group-has-[[data-sidebar=menu-action]]/menu-item:pr-8' ,
44+ 'aria-disabled:pointer-events-none aria-disabled:opacity-50' ,
45+ 'data-[active=true]:bg-sidebar-accent data-[active=true]:font-medium' ,
46+ 'data-[active=true]:text-sidebar-accent-foreground' ,
47+ 'data-[state=open]:hover:bg-sidebar-accent' ,
48+ 'data-[state=open]:hover:text-sidebar-accent-foreground' ,
49+ 'group-data-[collapsible=icon]:!size-8' ,
50+ 'group-data-[collapsible=icon]:!p-2 [&>span:last-child]:truncate' ,
51+ '[&>svg]:size-4 [&>svg]:shrink-0' ,
3852 VARIANT_CLASSES [ @variant ] ,
3953 SIZE_CLASSES [ @size ]
4054 ] ,
4155 data : {
42- sidebar : " menu-button" ,
56+ sidebar : ' menu-button' ,
4357 size : @size ,
4458 active : @active . to_s
4559 }
0 commit comments