Skip to content

Commit a82ea29

Browse files
committed
[Bug Fix] Match shadcn sonner styling tokens with Tailwind utilities
Item: - gap-3 -> gap-1.5 (6px, sonner) - text-[13px] (sonner font-size) - p-4 only (close moved out of right side via translate) - shadow-lg -> shadow-[0_4px_12px_rgba(0,0,0,0.1)] (matches sonner) Title: drop text-sm so it inherits 13px; leading-tight -> leading-normal. Description: drop text-sm; add font-normal leading-[1.4]. Content wrapper (skeleton): gap-1 -> gap-0.5 (2px). Icon span: justify-start, relative, size-4, -ml-[3px] mr-1 (sonner icon margins). SVG: add -ml-px. Action button: solid dark style — h-6 px-2 text-xs rounded bg-foreground text-background ml-auto hover:opacity-90. Cancel button: soft fill — bg-foreground/10 text-foreground ml-auto hover:bg-foreground/15. Close button: moved to top-left with -translate-x-[35%] -translate-y-[35%]; size-5 rounded-full border bg-popover; SVG size-3. Toaster JS: spawn-time action/cancel buttons mirror new classes. Docs: shorten Header description; move triggering blurb + sonner credit to an About section after Installation tabs.
1 parent f379a08 commit a82ea29

11 files changed

Lines changed: 32 additions & 18 deletions

File tree

docs/app/javascript/controllers/ruby_ui/toaster_controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export default class extends Controller {
101101
const btn = document.createElement("button")
102102
btn.type = "button"
103103
btn.dataset.slot = "action"
104-
btn.className = "inline-flex h-8 shrink-0 cursor-pointer items-center justify-center rounded-md border border-input bg-transparent px-3 text-sm font-medium hover:bg-secondary"
104+
btn.className = "inline-flex h-6 shrink-0 cursor-pointer items-center justify-center rounded px-2 text-xs font-medium bg-foreground text-background border-0 ml-auto hover:opacity-90 focus:outline-none focus:ring-2 focus:ring-ring transition-opacity"
105105
btn.textContent = detail.action.label
106106
btn.addEventListener("click", (ev) => {
107107
try { detail.action.onClick?.(ev) } finally {
@@ -116,7 +116,7 @@ export default class extends Controller {
116116
btn.type = "button"
117117
btn.dataset.slot = "cancel"
118118
btn.dataset.action = "click->ruby-ui--toast#dismiss"
119-
btn.className = "inline-flex h-8 shrink-0 cursor-pointer items-center justify-center rounded-md px-3 text-sm font-medium text-muted-foreground hover:bg-muted"
119+
btn.className = "inline-flex h-6 shrink-0 cursor-pointer items-center justify-center rounded px-2 text-xs font-medium bg-foreground/10 text-foreground border-0 ml-auto hover:bg-foreground/15 focus:outline-none focus:ring-2 focus:ring-ring transition-colors"
120120
btn.textContent = detail.cancel.label
121121
node.appendChild(btn)
122122
}

docs/app/views/docs/toast.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def view_template
2222
div(class: "max-w-2xl mx-auto w-full py-10 space-y-10") do
2323
render Docs::Header.new(
2424
title: "Toast",
25-
description: "Toast notifications, Hotwire-native. Trigger from the server with Turbo Streams or from JavaScript via window.RubyUI.toast.*. Heavily inspired by the original sonner: https://github.com/emilkowalski/sonner."
25+
description: "An opinionated toast component."
2626
)
2727

2828
Heading(level: 2) { "Mount" }
@@ -100,6 +100,20 @@ def view_template
100100

101101
render Components::ComponentSetup::Tabs.new(component_name: component)
102102

103+
Heading(level: 2) { "About" }
104+
p(class: "text-muted-foreground text-sm leading-relaxed") do
105+
plain "Trigger toasts from the server with Turbo Streams or from JavaScript via "
106+
code(class: "rounded bg-muted px-1.5 py-0.5 text-xs") { "window.RubyUI.toast.*" }
107+
plain ". Heavily inspired by the original "
108+
a(
109+
href: "https://github.com/emilkowalski/sonner",
110+
target: "_blank",
111+
rel: "noopener",
112+
class: "underline underline-offset-2 hover:text-foreground"
113+
) { "sonner" }
114+
plain "."
115+
end
116+
103117
render Docs::ComponentsTable.new(component_files(component))
104118
end
105119
end

gem/lib/ruby_ui/toast/toast_action.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def default_attrs
2020
{
2121
type: "button",
2222
data: data,
23-
class: "inline-flex h-8 shrink-0 cursor-pointer items-center justify-center rounded-md border border-input bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary hover:text-secondary-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"
23+
class: "inline-flex h-6 shrink-0 cursor-pointer items-center justify-center rounded px-2 text-xs font-medium bg-foreground text-background border-0 ml-auto hover:opacity-90 focus:outline-none focus:ring-2 focus:ring-ring transition-opacity disabled:pointer-events-none disabled:opacity-50"
2424
}
2525
end
2626
end

gem/lib/ruby_ui/toast/toast_cancel.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def default_attrs
2020
slot: "cancel",
2121
action: "click->ruby-ui--toast#dismiss"
2222
},
23-
class: "inline-flex h-8 shrink-0 cursor-pointer items-center justify-center rounded-md px-3 text-sm font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground focus:outline-none focus:ring-2 focus:ring-ring"
23+
class: "inline-flex h-6 shrink-0 cursor-pointer items-center justify-center rounded px-2 text-xs font-medium bg-foreground/10 text-foreground border-0 ml-auto hover:bg-foreground/15 focus:outline-none focus:ring-2 focus:ring-ring transition-colors"
2424
}
2525
end
2626
end

gem/lib/ruby_ui/toast/toast_close.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ def view_template
66
button(**attrs) do
77
svg(
88
xmlns: "http://www.w3.org/2000/svg",
9-
width: "15",
10-
height: "15",
9+
width: "12",
10+
height: "12",
1111
viewbox: "0 0 24 24",
1212
fill: "none",
1313
stroke: "currentColor",
1414
stroke_width: "2",
1515
stroke_linecap: "round",
1616
stroke_linejoin: "round",
17-
class: "size-4"
17+
class: "size-3"
1818
) do |s|
1919
s.path(d: "M18 6 6 18")
2020
s.path(d: "m6 6 12 12")
@@ -33,7 +33,7 @@ def default_attrs
3333
slot: "close",
3434
action: "click->ruby-ui--toast#dismiss"
3535
},
36-
class: "absolute right-1 top-1 cursor-pointer rounded-md p-1 text-foreground/60 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-1 focus:ring-ring group-hover/toast:opacity-100 group-data-[close-button=always]/toaster:opacity-100"
36+
class: "absolute left-0 top-0 -translate-x-[35%] -translate-y-[35%] size-5 cursor-pointer rounded-full border border-border bg-popover text-foreground p-0 flex items-center justify-center opacity-0 z-10 transition-opacity hover:bg-muted focus:opacity-100 focus:outline-none focus:ring-1 focus:ring-ring group-hover/toast:opacity-100 group-data-[close-button=always]/toaster:opacity-100"
3737
}
3838
end
3939
end

gem/lib/ruby_ui/toast/toast_description.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def view_template(&)
1111
def default_attrs
1212
{
1313
data: {slot: "description"},
14-
class: "text-sm text-muted-foreground"
14+
class: "font-normal leading-[1.4] text-muted-foreground"
1515
}
1616
end
1717
end

gem/lib/ruby_ui/toast/toast_icon.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def view_template
2020
stroke_width: "2",
2121
stroke_linecap: "round",
2222
stroke_linejoin: "round",
23-
class: svg_classes
23+
class: "#{svg_classes} -ml-px"
2424
) { |s| paths(s) }
2525
end
2626
end
@@ -59,7 +59,7 @@ def paths(s)
5959
end
6060

6161
def default_attrs
62-
{data: {slot: "icon"}, class: "shrink-0 inline-flex items-center justify-center text-foreground"}
62+
{data: {slot: "icon"}, class: "shrink-0 inline-flex items-center justify-start relative size-4 -ml-[3px] mr-1 text-foreground"}
6363
end
6464
end
6565
end

gem/lib/ruby_ui/toast/toast_item.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ def default_attrs
5555
def item_classes
5656
<<~CLASSES.tr("\n", " ").squeeze(" ").strip
5757
group/toast pointer-events-auto absolute left-0 right-0
58-
flex w-[356px] max-w-full items-center gap-3
58+
flex w-[356px] max-w-full items-center gap-1.5
5959
overflow-hidden rounded-lg border bg-popover text-popover-foreground
60-
border-border p-4 pr-8 shadow-lg
60+
border-border p-4 text-[13px] shadow-[0_4px_12px_rgba(0,0,0,0.1)]
6161
transition-[transform,opacity] duration-300 ease-out
6262
will-change-transform
6363
opacity-[var(--opacity,1)]

gem/lib/ruby_ui/toast/toast_region.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def skeleton(variant)
6666
) do
6767
render RubyUI::ToastItem.new(variant: variant) do
6868
render RubyUI::ToastIcon.new(variant: variant)
69-
div(class: "flex flex-col gap-1 flex-1 min-w-0") do
69+
div(class: "flex flex-col gap-0.5 flex-1 min-w-0") do
7070
render RubyUI::ToastTitle.new
7171
render RubyUI::ToastDescription.new
7272
end

gem/lib/ruby_ui/toast/toast_title.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def view_template(&)
1111
def default_attrs
1212
{
1313
data: {slot: "title"},
14-
class: "text-sm font-medium leading-tight"
14+
class: "font-medium leading-normal"
1515
}
1616
end
1717
end

0 commit comments

Comments
 (0)