You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Documentation] Match shadcn sonner demo style + visual polish
- Drop variant-tinted borders; icons monochrome (currentColor) — matches
shadcn sonner exactly.
- Rewrite docs page: shadcn-style "Examples > Types" grid (2-col) with
one box per variant, each containing a 'Show toast' button.
- Position section: 6-button grid; click spawns toast in chosen corner
via new `position` override in spawn detail (toaster_controller
swaps data-position before spawning).
- JS API section explains it's sugar over a window CustomEvent
(Hotwire-friendly: any source can dispatch `ruby-ui:toast`).
- Server-pushed example: fix button_to to use form-level data-turbo-stream.
- toaster_controller: register window.RubyUI.toast earlier so click
handlers don't race with controller connect.
Copy file name to clipboardExpand all lines: docs/app/javascript/controllers/toast_demo_controller.js
+38-12Lines changed: 38 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,48 @@
1
1
import{Controller}from"@hotwired/stimulus"
2
2
3
+
constPRESETS={
4
+
default: {variant: "default",title: "Event has been created",description: "Sunday, December 03, 2023 at 9:00 AM"},
5
+
success: {variant: "success",title: "Event has been created"},
6
+
info: {variant: "info",title: "Be at the area 10 minutes before the event time"},
7
+
warning: {variant: "warning",title: "Event start time cannot be earlier than 8am"},
8
+
error: {variant: "error",title: "Event has not been created"},
9
+
with_action: {variant: "default",title: "Event has been created",action: {label: "Undo"}},
10
+
}
11
+
3
12
exportdefaultclassextendsController{
4
13
fire(e){
5
-
constvariant=e.params.variant||"default"
14
+
constkind=e.params.kind||"default"
6
15
constt=window.RubyUI?.toast
7
-
if(!t)return
8
-
consttitles={success: "Saved",error: "Boom",info: "Heads up",warning: "Storage almost full",default: "Hello"}
9
-
constdescs={success: "Project updated.",error: "Server returned 500.",info: "New version available.",warning: "Almost out of space.",default: "Just so you know."}
description: "Hotwire-native sonner port. Push toasts from the server with Turbo Streams or trigger from JavaScript via window.RubyUI.toast."
24
+
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."
13
25
)
14
26
15
-
Heading(level: 2){"Usage"}
16
-
17
-
renderDocs::VisualCodeExample.new(title: "Mount in your layout",context: self)do
18
-
<<~RUBY
19
-
# In application_layout.rb (Phlex) or application.html.erb (ERB), once globally:
27
+
Heading(level: 2){"Mount"}
28
+
div(class: "rounded-md border bg-muted/30 p-4")do
29
+
Codeblock(<<~RUBY,syntax: :ruby)
30
+
# In application_layout.rb (Phlex), once globally:
20
31
render RubyUI::ToastRegion.new
32
+
33
+
# Pass flash to render Rails flash on initial load:
0 commit comments