Skip to content

Commit 24ed7a2

Browse files
committed
replace public_send with tag
1 parent 7814ba3 commit 24ed7a2

File tree

5 files changed

+31
-17
lines changed

5 files changed

+31
-17
lines changed

lib/ruby_ui/sidebar/sidebar_group_action.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
module RubyUI
44
class SidebarGroupAction < Base
5-
def initialize(as: "button", **attrs)
5+
def initialize(as: :button, **attrs)
66
@as = as
77
super(**attrs)
88
end
99

1010
def view_template(&)
11-
public_send(@as, **attrs, &)
11+
tag(@as, **attrs, &)
1212
end
1313

1414
private

lib/ruby_ui/sidebar/sidebar_menu_action.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
module RubyUI
44
class SidebarMenuAction < Base
5-
def initialize(as: "button", show_on_hover: false, **attrs)
5+
def initialize(as: :button, show_on_hover: false, **attrs)
66
@as = as
77
super(**attrs)
88
end
99

1010
def view_template(&)
11-
public_send(@as, **attrs, &)
11+
tag(@as, **attrs, &)
1212
end
1313

1414
private

lib/ruby_ui/sidebar/sidebar_menu_button.rb

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
module 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
}

lib/ruby_ui/sidebar/sidebar_menu_sub_button.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class SidebarMenuSubButton < Base
77
md: "text-sm"
88
}.freeze
99

10-
def initialize(as: "button", size: :md, active: false, **attrs)
10+
def initialize(as: :button, size: :md, active: false, **attrs)
1111
raise ArgumentError, "Invalid size: #{size}" unless SIZE_CLASSES.key?(size)
1212

1313
@as = as
@@ -17,7 +17,7 @@ def initialize(as: "button", size: :md, active: false, **attrs)
1717
end
1818

1919
def view_template(&)
20-
public_send(@as, **attrs, &)
20+
tag(@as, **attrs, &)
2121
end
2222

2323
private

test/ruby_ui/sidebar_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ def test_render_with_all_items
2323
RubyUI.SidebarMenuItem do
2424
RubyUI.SidebarMenuSub do
2525
RubyUI.SidebarMenuSubItem do
26-
RubyUI.SidebarMenuSubButton(as: "a", href: "#") { "Sub Item 1" }
26+
RubyUI.SidebarMenuSubButton(as: :a, href: "#") { "Sub Item 1" }
2727
end
2828
end
2929
end
3030
RubyUI.SidebarMenuItem do
31-
RubyUI.SidebarMenuButton(as: "a", href: "#") { "Settings" }
31+
RubyUI.SidebarMenuButton(as: :a, href: "#") { "Settings" }
3232
RubyUI.SidebarMenuAction { "Settings" }
3333
end
3434
RubyUI.SidebarMenuItem do

0 commit comments

Comments
 (0)