@@ -11,7 +11,8 @@ class Views::Docs::Toast < Views::Base
1111 { key : "error" , label : "Error" , title : "Event has not been created" } ,
1212 { key : "with_action" , label : "With Action" , title : "Event has been created" , action_label : "Undo" } ,
1313 { key : "promise" , label : "Promise" , title : nil } ,
14- { key : "text_only" , label : "Text Only" , title : "Event has been created" }
14+ { key : "text_only" , label : "Text Only" , title : "Event has been created" } ,
15+ { key : "close_button" , label : "Close Button" , title : "Event has been created" }
1516 ] . freeze
1617
1718 POSITIONS = %w[ top-left top-center top-right bottom-left bottom-center bottom-right ] . freeze
@@ -114,10 +115,93 @@ def view_template
114115 plain "."
115116 end
116117
118+ Heading ( level : 2 ) { "API Reference" }
119+
120+ Heading ( level : 3 ) { "Toaster (Region)" }
121+ props_table ( REGION_PROPS )
122+
123+ Heading ( level : 3 ) { "ToastItem" }
124+ props_table ( ITEM_PROPS )
125+
126+ Heading ( level : 3 ) { "JS API options" }
127+ p ( class : "text-muted-foreground text-sm" ) do
128+ plain "Second argument to "
129+ code ( class : "rounded bg-muted px-1.5 py-0.5 text-xs" ) { "RubyUI.toast.<variant>(message, options)" }
130+ plain " or "
131+ code ( class : "rounded bg-muted px-1.5 py-0.5 text-xs" ) { "ruby-ui:toast" }
132+ plain " CustomEvent detail."
133+ end
134+ props_table ( JS_OPTIONS )
135+
117136 render Docs ::ComponentsTable . new ( component_files ( component ) )
118137 end
119138 end
120139
140+ REGION_PROPS = [
141+ { name : "position" , default : ":bottom_right" , values : ":top_left | :top_center | :top_right | :bottom_left | :bottom_center | :bottom_right" , description : "Where the toaster mounts on the viewport." } ,
142+ { name : "expand" , default : "false" , values : "Boolean" , description : "Always show items expanded (no stack peek)." } ,
143+ { name : "max" , default : "3" , values : "Integer" , description : "Max visible toasts before oldest auto-evicts." } ,
144+ { name : "duration" , default : "4000" , values : "Integer (ms)" , description : "Default lifetime per toast. Pass 0 or Infinity to disable auto-dismiss." } ,
145+ { name : "gap" , default : "14" , values : "Integer (px)" , description : "Spacing between toasts when expanded." } ,
146+ { name : "offset" , default : "24" , values : "Integer (px)" , description : "Distance from the viewport edge." } ,
147+ { name : "theme" , default : ":system" , values : ":system | :light | :dark" , description : "Color scheme override." } ,
148+ { name : "rich_colors" , default : "false" , values : "Boolean" , description : "Enable variant-tinted backgrounds." } ,
149+ { name : "close_button" , default : "false" , values : "Boolean" , description : "Render an X button in every toast (top-right)." } ,
150+ { name : "hotkey" , default : '%w[alt t]' , values : "Array<String>" , description : "Keyboard shortcut to focus the first toast." } ,
151+ { name : "dir" , default : ":ltr" , values : ":ltr | :rtl" , description : "Text direction." } ,
152+ { name : "flash" , default : "nil" , values : "Hash | nil" , description : "Pass `helpers.flash.to_h` to render Rails flash on initial load." }
153+ ] . freeze
154+
155+ ITEM_PROPS = [
156+ { name : "variant" , default : ":default" , values : ":default | :success | :error | :warning | :info | :loading" , description : "Visual + a11y role + icon." } ,
157+ { name : "id" , default : "nil" , values : "String" , description : "DOM id; auto-generated when not provided." } ,
158+ { name : "duration" , default : "nil" , values : "Integer | nil" , description : "Override the Region default. nil inherits." } ,
159+ { name : "dismissible" , default : "true" , values : "Boolean" , description : "Allow Escape, swipe, X, and force-dismiss to close." } ,
160+ { name : "invert" , default : "false" , values : "Boolean" , description : "Invert background/foreground (light-on-dark in light theme)." } ,
161+ { name : "on_dismiss" , default : "nil" , values : "String" , description : "Stimulus action descriptor fired when the user dismisses." } ,
162+ { name : "on_auto_close" , default : "nil" , values : "String" , description : "Stimulus action descriptor fired when the timer expires." }
163+ ] . freeze
164+
165+ JS_OPTIONS = [
166+ { name : "title" , default : "—" , values : "String" , description : "Headline text. Falls back to the first positional argument." } ,
167+ { name : "description" , default : "—" , values : "String" , description : "Secondary line under the title." } ,
168+ { name : "duration" , default : "(Region default)" , values : "Number | Infinity" , description : "ms before auto-dismiss. Infinity = sticky." } ,
169+ { name : "action" , default : "—" , values : "{ label, onClick }" , description : "Primary action button rendered inside the toast." } ,
170+ { name : "cancel" , default : "—" , values : "{ label, onClick }" , description : "Secondary dismiss button." } ,
171+ { name : "closeButton" , default : "false" , values : "Boolean" , description : "Force an X close button on this toast." } ,
172+ { name : "position" , default : "(Region default)" , values : "String" , description : "Per-toast position override (changes Region's data-position before append)." } ,
173+ { name : "id" , default : "(auto)" , values : "String" , description : "Set a stable id (used by .dismiss(id) and .promise)." } ,
174+ { name : "dismissible" , default : "true" , values : "Boolean" , description : "Disable Escape / swipe / dismiss-all for this toast." } ,
175+ { name : "className" , default : "—" , values : "String" , description : "Extra classes appended to the rendered <li>." }
176+ ] . freeze
177+
178+ private
179+
180+ def props_table ( rows )
181+ div ( class : "border rounded-lg overflow-hidden" ) do
182+ Table do
183+ TableHeader do
184+ TableRow do
185+ TableHead { "Prop" }
186+ TableHead { "Default" }
187+ TableHead { "Values" }
188+ TableHead ( class : "w-full" ) { "Description" }
189+ end
190+ end
191+ TableBody do
192+ rows . each do |r |
193+ TableRow do
194+ TableCell { InlineCode { r [ :name ] } }
195+ TableCell { InlineCode { r [ :default ] } }
196+ TableCell ( class : "whitespace-normal" ) { InlineCode { r [ :values ] } }
197+ TableCell ( class : "text-muted-foreground" ) { r [ :description ] }
198+ end
199+ end
200+ end
201+ end
202+ end
203+ end
204+
121205 private
122206
123207 def example_box ( ex )
0 commit comments