@ui-sdk/vue 0.0.0-stage → 0.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +10 -2
  3. package/dist/accordion.d.ts +561 -0
  4. package/dist/accordion.js +24 -0
  5. package/dist/agent.d.ts +2 -0
  6. package/dist/agent.js +7 -0
  7. package/dist/alert-dialog.d.ts +231 -0
  8. package/dist/alert-dialog.js +33 -0
  9. package/dist/async-options.d.ts +18 -0
  10. package/dist/async-options.js +40 -0
  11. package/dist/autocomplete.d.ts +384 -0
  12. package/dist/autocomplete.js +344 -0
  13. package/dist/avatar.d.ts +40 -0
  14. package/dist/avatar.js +28 -0
  15. package/dist/button.d.ts +52 -0
  16. package/dist/button.js +43 -0
  17. package/dist/calendar-context.d.ts +10 -0
  18. package/dist/calendar-context.js +7 -0
  19. package/dist/calendar.d.ts +311 -0
  20. package/dist/calendar.js +349 -0
  21. package/dist/carousel.d.ts +236 -0
  22. package/dist/carousel.js +204 -0
  23. package/dist/checkbox.d.ts +211 -0
  24. package/dist/checkbox.js +151 -0
  25. package/dist/children.d.ts +41 -0
  26. package/dist/children.js +135 -0
  27. package/dist/collapsible.d.ts +54 -0
  28. package/dist/collapsible.js +18 -0
  29. package/dist/color-picker.d.ts +187 -0
  30. package/dist/color-picker.js +158 -0
  31. package/dist/color.d.ts +2 -0
  32. package/dist/color.js +21 -0
  33. package/dist/combobox.d.ts +517 -0
  34. package/dist/combobox.js +531 -0
  35. package/dist/command.d.ts +322 -0
  36. package/dist/command.js +345 -0
  37. package/dist/controller-target.d.ts +49 -0
  38. package/dist/controller-target.js +112 -0
  39. package/dist/create-parts.d.ts +126 -0
  40. package/dist/create-parts.js +206 -0
  41. package/dist/date-input.d.ts +133 -0
  42. package/dist/date-input.js +31 -0
  43. package/dist/date-picker.d.ts +328 -0
  44. package/dist/date-picker.js +354 -0
  45. package/dist/date.d.ts +2 -0
  46. package/dist/date.js +59 -0
  47. package/dist/dialog-parts.d.ts +259 -0
  48. package/dist/dialog-parts.js +300 -0
  49. package/dist/dialog.d.ts +251 -0
  50. package/dist/dialog.js +25 -0
  51. package/dist/drawer.d.ts +304 -0
  52. package/dist/drawer.js +373 -0
  53. package/dist/editor-context.d.ts +4 -0
  54. package/dist/editor-context.js +5 -0
  55. package/dist/field-context.d.ts +26 -0
  56. package/dist/field-context.js +44 -0
  57. package/dist/field.d.ts +154 -0
  58. package/dist/field.js +240 -0
  59. package/dist/file-input.d.ts +212 -0
  60. package/dist/file-input.js +255 -0
  61. package/dist/form-inputs.d.ts +16 -0
  62. package/dist/form-inputs.js +25 -0
  63. package/dist/gesture.d.ts +1 -0
  64. package/dist/gesture.js +15 -0
  65. package/dist/history.d.ts +2 -0
  66. package/dist/history.js +11 -0
  67. package/dist/hover-card.d.ts +137 -0
  68. package/dist/hover-card.js +153 -0
  69. package/dist/image-cropper.d.ts +74 -0
  70. package/dist/image-cropper.js +36 -0
  71. package/dist/image.d.ts +2 -0
  72. package/dist/image.js +5 -0
  73. package/dist/index.d.ts +59 -0
  74. package/dist/index.js +60 -0
  75. package/dist/input.d.ts +120 -0
  76. package/dist/input.js +73 -0
  77. package/dist/item-icon.d.ts +34 -0
  78. package/dist/item-icon.js +63 -0
  79. package/dist/label.d.ts +16 -0
  80. package/dist/label.js +8 -0
  81. package/dist/lifecycle.d.ts +11 -0
  82. package/dist/lifecycle.js +91 -0
  83. package/dist/list-items.d.ts +38 -0
  84. package/dist/list-items.js +59 -0
  85. package/dist/list-text.d.ts +7 -0
  86. package/dist/list-text.js +15 -0
  87. package/dist/listbox.d.ts +273 -0
  88. package/dist/listbox.js +126 -0
  89. package/dist/menu.d.ts +678 -0
  90. package/dist/menu.js +607 -0
  91. package/dist/menubar-context.d.ts +5 -0
  92. package/dist/menubar-context.js +5 -0
  93. package/dist/menubar.d.ts +61 -0
  94. package/dist/menubar.js +48 -0
  95. package/dist/meter.d.ts +41 -0
  96. package/dist/meter.js +37 -0
  97. package/dist/navigation-menu.d.ts +228 -0
  98. package/dist/navigation-menu.js +195 -0
  99. package/dist/number-input.d.ts +176 -0
  100. package/dist/number-input.js +231 -0
  101. package/dist/number.d.ts +2 -0
  102. package/dist/number.js +39 -0
  103. package/dist/nuxt/entries.json +977 -0
  104. package/dist/nuxt/module.d.ts +18 -0
  105. package/dist/nuxt/module.js +31 -0
  106. package/dist/nuxt/registrations.d.ts +22 -0
  107. package/dist/nuxt/registrations.js +22 -0
  108. package/dist/observe.d.ts +2 -0
  109. package/dist/observe.js +7 -0
  110. package/dist/otp-input.d.ts +142 -0
  111. package/dist/otp-input.js +130 -0
  112. package/dist/overlays.d.ts +40 -0
  113. package/dist/overlays.js +118 -0
  114. package/dist/pagination.d.ts +201 -0
  115. package/dist/pagination.js +146 -0
  116. package/dist/password-input.d.ts +144 -0
  117. package/dist/password-input.js +134 -0
  118. package/dist/popover.d.ts +211 -0
  119. package/dist/popover.js +258 -0
  120. package/dist/popup.d.ts +60 -0
  121. package/dist/popup.js +89 -0
  122. package/dist/preferences.d.ts +44 -0
  123. package/dist/preferences.js +102 -0
  124. package/dist/primitive.d.ts +2 -0
  125. package/dist/primitive.js +11 -0
  126. package/dist/progress.d.ts +41 -0
  127. package/dist/progress.js +37 -0
  128. package/dist/radio.d.ts +164 -0
  129. package/dist/radio.js +145 -0
  130. package/dist/rating.d.ts +149 -0
  131. package/dist/rating.js +146 -0
  132. package/dist/renderless.d.ts +4 -0
  133. package/dist/renderless.js +28 -0
  134. package/dist/resizable.d.ts +54 -0
  135. package/dist/resizable.js +22 -0
  136. package/dist/scroll-area.d.ts +72 -0
  137. package/dist/scroll-area.js +77 -0
  138. package/dist/segmented-control.d.ts +151 -0
  139. package/dist/segmented-control.js +110 -0
  140. package/dist/segmented-input.d.ts +76 -0
  141. package/dist/segmented-input.js +115 -0
  142. package/dist/select.d.ts +458 -0
  143. package/dist/select.js +468 -0
  144. package/dist/separator.d.ts +14 -0
  145. package/dist/separator.js +8 -0
  146. package/dist/shortcuts.d.ts +32 -0
  147. package/dist/shortcuts.js +56 -0
  148. package/dist/slider.d.ts +65 -0
  149. package/dist/slider.js +194 -0
  150. package/dist/switch.d.ts +103 -0
  151. package/dist/switch.js +71 -0
  152. package/dist/tabs.d.ts +338 -0
  153. package/dist/tabs.js +27 -0
  154. package/dist/text-control.d.ts +89 -0
  155. package/dist/text-control.js +51 -0
  156. package/dist/text-match.d.ts +2 -0
  157. package/dist/text-match.js +7 -0
  158. package/dist/textarea.d.ts +106 -0
  159. package/dist/textarea.js +68 -0
  160. package/dist/time-input.d.ts +131 -0
  161. package/dist/time-input.js +32 -0
  162. package/dist/timeline.d.ts +81 -0
  163. package/dist/timeline.js +30 -0
  164. package/dist/toast-parts.d.ts +203 -0
  165. package/dist/toast-parts.js +270 -0
  166. package/dist/toast.d.ts +2 -0
  167. package/dist/toast.js +21 -0
  168. package/dist/toggle-props.d.ts +22 -0
  169. package/dist/toggle-props.js +14 -0
  170. package/dist/toggle.d.ts +199 -0
  171. package/dist/toggle.js +129 -0
  172. package/dist/token-input.d.ts +136 -0
  173. package/dist/token-input.js +214 -0
  174. package/dist/toolbar-context.d.ts +7 -0
  175. package/dist/toolbar-context.js +20 -0
  176. package/dist/toolbar.d.ts +120 -0
  177. package/dist/toolbar.js +77 -0
  178. package/dist/tooltip.d.ts +160 -0
  179. package/dist/tooltip.js +224 -0
  180. package/dist/tree.d.ts +300 -0
  181. package/dist/tree.js +209 -0
  182. package/dist/trigger-menu.d.ts +452 -0
  183. package/dist/trigger-menu.js +254 -0
  184. package/dist/use-primitive.d.ts +132 -0
  185. package/dist/use-primitive.js +462 -0
  186. package/dist/waterfall.d.ts +201 -0
  187. package/dist/waterfall.js +171 -0
  188. package/docs/README.md +89 -0
  189. package/docs/agents.md +1523 -0
  190. package/docs/components/accordion.md +1369 -0
  191. package/docs/components/alert-dialog.md +799 -0
  192. package/docs/components/autocomplete.md +1857 -0
  193. package/docs/components/avatar.md +272 -0
  194. package/docs/components/button.md +435 -0
  195. package/docs/components/calendar.md +1589 -0
  196. package/docs/components/carousel.md +1171 -0
  197. package/docs/components/checkbox.md +1008 -0
  198. package/docs/components/collapsible.md +536 -0
  199. package/docs/components/color-picker.md +706 -0
  200. package/docs/components/combobox.md +3504 -0
  201. package/docs/components/command.md +1481 -0
  202. package/docs/components/date-input.md +536 -0
  203. package/docs/components/date-picker.md +1244 -0
  204. package/docs/components/dialog.md +1397 -0
  205. package/docs/components/drawer.md +1166 -0
  206. package/docs/components/field.md +538 -0
  207. package/docs/components/file-input.md +611 -0
  208. package/docs/components/hover-card.md +505 -0
  209. package/docs/components/image-cropper.md +556 -0
  210. package/docs/components/input.md +306 -0
  211. package/docs/components/label.md +203 -0
  212. package/docs/components/listbox.md +1004 -0
  213. package/docs/components/menu.md +1229 -0
  214. package/docs/components/menubar.md +443 -0
  215. package/docs/components/meter.md +315 -0
  216. package/docs/components/navigation-menu.md +1523 -0
  217. package/docs/components/number-input.md +1029 -0
  218. package/docs/components/otp-input.md +512 -0
  219. package/docs/components/pagination.md +613 -0
  220. package/docs/components/password-input.md +649 -0
  221. package/docs/components/popover.md +1448 -0
  222. package/docs/components/preferences.md +208 -0
  223. package/docs/components/progress.md +423 -0
  224. package/docs/components/radio.md +785 -0
  225. package/docs/components/rating.md +416 -0
  226. package/docs/components/resizable.md +910 -0
  227. package/docs/components/scroll-area.md +915 -0
  228. package/docs/components/segmented-control.md +435 -0
  229. package/docs/components/select.md +2015 -0
  230. package/docs/components/separator.md +229 -0
  231. package/docs/components/slider.md +1084 -0
  232. package/docs/components/switch.md +565 -0
  233. package/docs/components/tabs.md +944 -0
  234. package/docs/components/textarea.md +299 -0
  235. package/docs/components/time-input.md +224 -0
  236. package/docs/components/timeline.md +654 -0
  237. package/docs/components/toast.md +1224 -0
  238. package/docs/components/toggle.md +500 -0
  239. package/docs/components/token-input.md +953 -0
  240. package/docs/components/toolbar.md +739 -0
  241. package/docs/components/tooltip.md +818 -0
  242. package/docs/components/tree.md +1306 -0
  243. package/docs/components/trigger-menu.md +1223 -0
  244. package/docs/components/waterfall.md +717 -0
  245. package/docs/controllers.md +71 -0
  246. package/docs/core.md +8027 -0
  247. package/docs/custom-parts.md +89 -0
  248. package/docs/first-component.md +83 -0
  249. package/docs/forms.md +122 -0
  250. package/docs/installation.md +72 -0
  251. package/docs/introduction.md +32 -0
  252. package/docs/lists-and-menus.md +122 -0
  253. package/docs/llms.txt +1502 -0
  254. package/docs/parts-and-composition.md +85 -0
  255. package/docs/popups.md +108 -0
  256. package/docs/rendering.md +56 -0
  257. package/docs/server-rendering.md +180 -0
  258. package/docs/state-and-events.md +100 -0
  259. package/docs/styling-and-animation.md +148 -0
  260. package/docs/utilities/async-options.md +348 -0
  261. package/docs/utilities/shortcuts.md +159 -0
  262. package/package.json +352 -3
@@ -0,0 +1,1224 @@
1
+ # Toast
2
+
3
+ Show notifications with actions, timed dismissal, and screen reader announcements.
4
+
5
+ A toast tells someone that something happened, like a saved change or a sent message, and goes away on its own. It can offer an action such as Undo, stacks with the toasts before it, and is announced to screen readers without taking focus.
6
+
7
+ ```vue title="demo.vue"
8
+ <script setup lang="ts">
9
+ import {
10
+ Toast,
11
+ ToastAction,
12
+ ToastDescription,
13
+ ToastRegion,
14
+ ToastTitle,
15
+ createToaster,
16
+ } from "@ui-sdk/vue/toast"
17
+ import { onUnmounted } from "vue"
18
+ import { useLog } from "./log"
19
+
20
+ const log = useLog()
21
+ const toast = createToaster()
22
+ onUnmounted(() => {
23
+ toast.dismiss()
24
+ })
25
+
26
+ function createEvent() {
27
+ toast("Event created", {
28
+ description: "Friday, June 12 at 10:00 AM",
29
+ action: { label: "Undo", onAction: () => log("Event removed") },
30
+ })
31
+ }
32
+ </script>
33
+
34
+ <template>
35
+ <button @click="createEvent">Create Event</button>
36
+ <ToastRegion :toaster="toast">
37
+ <Toast>
38
+ <div data-slot="stack">
39
+ <ToastTitle />
40
+ <ToastDescription />
41
+ </div>
42
+ <ToastAction data-variant="solid" />
43
+ </Toast>
44
+ </ToastRegion>
45
+ </template>
46
+ ```
47
+
48
+ Press Create Event. Choose Undo, swipe the toast away, or wait for it to close. Undo logs Event removed.
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ npm install @ui-sdk/vue @ui-sdk/core
54
+ ```
55
+
56
+ ## Composition
57
+
58
+ Use the following composition to build a `ToastRegion`:
59
+
60
+ ```text
61
+ ToastRegion
62
+ ├── Toast
63
+ │ ├── ToastTitle
64
+ │ ├── ToastDescription
65
+ │ ├── ToastAction
66
+ │ └── ToastClose
67
+ └── Toast
68
+ ├── ToastTitle
69
+ └── ToastDescription
70
+ ```
71
+
72
+ The region renders one `Toast` for each toast in its queue, newest first, through its default slot. A toast is named by its title and described by its description. Empty title, description and action parts show the text from the toast's data, so a region's slot is usually the same few parts.
73
+
74
+ ## Usage
75
+
76
+ Import the parts and put them together, then call `toast()` when an action finishes:
77
+
78
+ ```vue
79
+ <script setup lang="ts">
80
+ import {
81
+ Toast,
82
+ ToastDescription,
83
+ ToastRegion,
84
+ ToastTitle,
85
+ toast,
86
+ } from "@ui-sdk/vue/toast"
87
+ </script>
88
+
89
+ <template>
90
+ <button
91
+ type="button"
92
+ @click="toast('Event created', { description: 'Friday at 10:00 AM' })"
93
+ >
94
+ Create Event
95
+ </button>
96
+ <ToastRegion>
97
+ <Toast>
98
+ <ToastTitle />
99
+ <ToastDescription />
100
+ </Toast>
101
+ </ToastRegion>
102
+ </template>
103
+ ```
104
+
105
+ `toast()` works from anywhere, not only from components, and returns the toast's id. Place the region once, near your app's root. Without a default slot, it renders each toast's title, description, action and cancel button with unstyled parts.
106
+
107
+ The examples below each call `createToaster()` for a queue of their own and pass it to their region as `toaster`, so their toasts don't mix.
108
+
109
+ ## Types
110
+
111
+ `toast.success`, `.info`, `.warning`, `.error` and `.loading` set the toast's type, which the toast exposes as `data-type` for an icon or a color. Errors are announced right away and other types wait for a pause; set `priority` to change that. A loading toast stays until it's updated or dismissed.
112
+
113
+ ```vue title="types.vue"
114
+ <script setup lang="ts">
115
+ import {
116
+ CircleCheckIcon,
117
+ InfoIcon,
118
+ LoaderCircleIcon,
119
+ OctagonXIcon,
120
+ TriangleAlertIcon,
121
+ } from "@lucide/vue"
122
+ import {
123
+ Toast,
124
+ ToastRegion,
125
+ ToastTitle,
126
+ createToaster,
127
+ } from "@ui-sdk/vue/toast"
128
+ import { onUnmounted } from "vue"
129
+
130
+ const toast = createToaster()
131
+ onUnmounted(() => {
132
+ toast.dismiss()
133
+ })
134
+
135
+ function upload() {
136
+ return new Promise((resolve) => setTimeout(resolve, 2000))
137
+ }
138
+
139
+ function uploadPhotos() {
140
+ toast.promise(upload, {
141
+ loading: "Uploading photos…",
142
+ success: "Photos uploaded",
143
+ error: "Upload failed",
144
+ })
145
+ }
146
+ </script>
147
+
148
+ <template>
149
+ <div data-slot="row">
150
+ <button @click="toast('Event created')">Default</button>
151
+ <button @click="toast.success('Changes saved')">Success</button>
152
+ <button @click="toast.info('A new version is available')">Info</button>
153
+ <button @click="toast.warning('Storage is almost full')">Warning</button>
154
+ <button @click="toast.error(`Couldn't save changes`)">Error</button>
155
+ <button @click="uploadPhotos">Loading</button>
156
+ </div>
157
+ <ToastRegion :toaster="toast">
158
+ <Toast>
159
+ <CircleCheckIcon data-show="success" aria-hidden="true" />
160
+ <InfoIcon data-show="info" aria-hidden="true" />
161
+ <TriangleAlertIcon data-show="warning" aria-hidden="true" />
162
+ <OctagonXIcon data-show="error" aria-hidden="true" />
163
+ <LoaderCircleIcon data-show="loading" aria-hidden="true" />
164
+ <ToastTitle />
165
+ </Toast>
166
+ </ToastRegion>
167
+ </template>
168
+ ```
169
+
170
+ Choose a type. Each toast shows its type's icon, and Loading turns into Photos uploaded when it finishes.
171
+
172
+ ## Position
173
+
174
+ Set the region's `side` to `top` or `bottom`, and `align` to `start`, `center` or `end`. Start and end follow the writing direction. A toast can be swiped toward the side and, unless it's centered, toward the end it's aligned to.
175
+
176
+ ```vue title="position.vue"
177
+ <script setup lang="ts">
178
+ import { CheckIcon, ChevronDownIcon } from "@lucide/vue"
179
+ import {
180
+ Select,
181
+ SelectContent,
182
+ SelectItem,
183
+ SelectItemIndicator,
184
+ SelectLabel,
185
+ SelectTrigger,
186
+ SelectValue,
187
+ } from "@ui-sdk/vue/select"
188
+ import {
189
+ Toast,
190
+ ToastDescription,
191
+ ToastRegion,
192
+ ToastTitle,
193
+ createToaster,
194
+ } from "@ui-sdk/vue/toast"
195
+ import { onUnmounted, ref } from "vue"
196
+
197
+ const sides = [
198
+ { value: "top", label: "Top" },
199
+ { value: "bottom", label: "Bottom" },
200
+ ]
201
+ const aligns = [
202
+ { value: "start", label: "Start" },
203
+ { value: "center", label: "Center" },
204
+ { value: "end", label: "End" },
205
+ ]
206
+ type Side = "top" | "bottom"
207
+ type Align = "start" | "center" | "end"
208
+
209
+ const toast = createToaster()
210
+ const side = ref<Side>("bottom")
211
+ const align = ref<Align>("end")
212
+ onUnmounted(() => {
213
+ toast.dismiss()
214
+ })
215
+ </script>
216
+
217
+ <template>
218
+ <div data-slot="stack">
219
+ <div data-slot="controls">
220
+ <Select
221
+ :items="sides"
222
+ :value="side"
223
+ @value-change="(next) => next && (side = next as Side)"
224
+ >
225
+ <SelectLabel>Side</SelectLabel>
226
+ <SelectTrigger>
227
+ <SelectValue />
228
+ <ChevronDownIcon aria-hidden="true" />
229
+ </SelectTrigger>
230
+ <SelectContent>
231
+ <SelectItem v-for="option in sides" :key="option.value" :value="option.value">
232
+ {{ option.label }}
233
+ <SelectItemIndicator>
234
+ <CheckIcon aria-hidden="true" />
235
+ </SelectItemIndicator>
236
+ </SelectItem>
237
+ </SelectContent>
238
+ </Select>
239
+ <Select
240
+ :items="aligns"
241
+ :value="align"
242
+ @value-change="(next) => next && (align = next as Align)"
243
+ >
244
+ <SelectLabel>Align</SelectLabel>
245
+ <SelectTrigger>
246
+ <SelectValue />
247
+ <ChevronDownIcon aria-hidden="true" />
248
+ </SelectTrigger>
249
+ <SelectContent>
250
+ <SelectItem v-for="option in aligns" :key="option.value" :value="option.value">
251
+ {{ option.label }}
252
+ <SelectItemIndicator>
253
+ <CheckIcon aria-hidden="true" />
254
+ </SelectItemIndicator>
255
+ </SelectItem>
256
+ </SelectContent>
257
+ </Select>
258
+ </div>
259
+ <button @click=" toast('Event created', { description: 'Friday, June 12 at 10:00 AM' }) ">
260
+ Create Event
261
+ </button>
262
+ <ToastRegion :toaster="toast" :side="side" :align="align">
263
+ <Toast>
264
+ <div data-slot="stack">
265
+ <ToastTitle />
266
+ <ToastDescription />
267
+ </div>
268
+ </Toast>
269
+ </ToastRegion>
270
+ </div>
271
+ </template>
272
+ ```
273
+
274
+ Choose a side and an alignment, then press Create Event and look for the toast at that edge of the page.
275
+
276
+ ## Action and Cancel
277
+
278
+ Add an `action`, like Undo, and a `cancel` button that dismisses the toast. Their callbacks can update your app. `onDismiss` tells you why the toast is closing, and `details.cancel()` keeps it open; a canceled timeout starts the countdown again.
279
+
280
+ ```vue title="action.vue"
281
+ <script setup lang="ts">
282
+ import {
283
+ Toast,
284
+ ToastAction,
285
+ ToastClose,
286
+ ToastRegion,
287
+ ToastTitle,
288
+ createToaster,
289
+ } from "@ui-sdk/vue/toast"
290
+ import { onUnmounted } from "vue"
291
+ import { useLog } from "./log"
292
+
293
+ const log = useLog()
294
+ const toast = createToaster()
295
+ onUnmounted(() => {
296
+ toast.dismiss()
297
+ })
298
+
299
+ function archive() {
300
+ toast("Message archived", {
301
+ action: { label: "Undo", onAction: () => log("Message restored") },
302
+ cancel: { label: "Dismiss", onCancel: () => log("Kept archived") },
303
+ onDismiss: ({ reason }) => log(`Closed (${reason})`),
304
+ })
305
+ }
306
+ </script>
307
+
308
+ <template>
309
+ <button @click="archive">Archive Message</button>
310
+ <ToastRegion :toaster="toast">
311
+ <template #default="{ toast: item }">
312
+ <Toast>
313
+ <ToastTitle />
314
+ <ToastClose v-if="item.cancel" :action="item.cancel.onCancel">{{
315
+ item.cancel.label
316
+ }}</ToastClose>
317
+ <ToastAction data-variant="solid" />
318
+ </Toast>
319
+ </template>
320
+ </ToastRegion>
321
+ </template>
322
+ ```
323
+
324
+ Press Archive Message, then choose Undo or Dismiss, swipe the toast away, or let it time out. The console logs why it closed.
325
+
326
+ ## Link
327
+
328
+ Give an action an `href` to render it as a link. It keeps normal link behavior, including opening in a new tab.
329
+
330
+ ```vue title="link.vue"
331
+ <script setup lang="ts">
332
+ import {
333
+ Toast,
334
+ ToastAction,
335
+ ToastDescription,
336
+ ToastRegion,
337
+ ToastTitle,
338
+ createToaster,
339
+ } from "@ui-sdk/vue/toast"
340
+ import { onUnmounted } from "vue"
341
+
342
+ const toast = createToaster()
343
+ onUnmounted(() => {
344
+ toast.dismiss()
345
+ })
346
+
347
+ function sendInvoice() {
348
+ toast("Invoice sent", {
349
+ description: "Hollis Grant · $240.00",
350
+ action: { label: "View", href: "#" },
351
+ })
352
+ }
353
+ </script>
354
+
355
+ <template>
356
+ <button @click="sendInvoice">Send Invoice</button>
357
+ <ToastRegion :toaster="toast">
358
+ <Toast>
359
+ <div data-slot="stack">
360
+ <ToastTitle />
361
+ <ToastDescription />
362
+ </div>
363
+ <ToastAction data-variant="solid" />
364
+ </Toast>
365
+ </ToastRegion>
366
+ </template>
367
+ ```
368
+
369
+ Press Send Invoice, then follow View in the toast.
370
+
371
+ ## Promise
372
+
373
+ `toast.promise()` shows a loading toast, then updates the same toast when the promise resolves or rejects. Each message can be a string, options with a description or an action, or a function of the result. A toast dismissed while loading stays closed.
374
+
375
+ ```vue title="promise.vue"
376
+ <script setup lang="ts">
377
+ import {
378
+ Toast,
379
+ ToastAction,
380
+ ToastDescription,
381
+ ToastRegion,
382
+ ToastTitle,
383
+ createToaster,
384
+ } from "@ui-sdk/vue/toast"
385
+ import { onUnmounted } from "vue"
386
+
387
+ const toast = createToaster()
388
+ let attempts = 0
389
+ onUnmounted(() => {
390
+ toast.dismiss()
391
+ })
392
+
393
+ function save() {
394
+ const succeeds = ++attempts % 2 === 1
395
+ return new Promise<void>((resolve, reject) =>
396
+ setTimeout(
397
+ () => (succeeds ? resolve() : reject(new Error("Network error"))),
398
+ 1500
399
+ )
400
+ )
401
+ }
402
+
403
+ function saveChanges() {
404
+ toast.promise(save, {
405
+ loading: "Saving changes…",
406
+ success: "Changes saved",
407
+ error: {
408
+ title: "Couldn't save changes",
409
+ description: "Check your connection and try again.",
410
+ action: { label: "Retry", onAction: saveChanges },
411
+ },
412
+ })
413
+ }
414
+ </script>
415
+
416
+ <template>
417
+ <button @click="saveChanges">Save Changes</button>
418
+ <ToastRegion :toaster="toast">
419
+ <Toast>
420
+ <div data-slot="stack">
421
+ <ToastTitle />
422
+ <ToastDescription />
423
+ </div>
424
+ <ToastAction data-variant="solid" />
425
+ </Toast>
426
+ </ToastRegion>
427
+ </template>
428
+ ```
429
+
430
+ Press Save Changes to see Saving changes become Changes saved. Press it again for the error, then choose Retry.
431
+
432
+ ## Stacking
433
+
434
+ `max-visible` limits how many toasts show at once, three by default; the rest wait in the queue, and their timers start when they show. The stack expands while the pointer or focus is in it. Set `expanded` to keep it open. [Styling](#styling) shows the CSS that lays out the stack.
435
+
436
+ ```vue title="stacking.vue"
437
+ <script setup lang="ts">
438
+ import { CheckIcon } from "@lucide/vue"
439
+ import { Checkbox, CheckboxIndicator } from "@ui-sdk/vue/checkbox"
440
+ import {
441
+ Toast,
442
+ ToastDescription,
443
+ ToastRegion,
444
+ ToastTitle,
445
+ createToaster,
446
+ } from "@ui-sdk/vue/toast"
447
+ import { onUnmounted, ref } from "vue"
448
+
449
+ const notifications = [
450
+ { title: "Event created", description: "Friday, June 12 at 10:00 AM" },
451
+ { title: "Message sent" },
452
+ {
453
+ title: "Hollis Grant joined",
454
+ description: "They can now edit the Launch plan and see its comments.",
455
+ },
456
+ { title: "Changes saved" },
457
+ { title: "Invoice sent", description: "Inès Moreau · $240.00" },
458
+ { title: "Photos uploaded", description: "12 photos added to Summer trip" },
459
+ ]
460
+
461
+ const toast = createToaster()
462
+ const expanded = ref(false)
463
+ let count = 0
464
+ onUnmounted(() => {
465
+ toast.dismiss()
466
+ })
467
+ </script>
468
+
469
+ <template>
470
+ <div data-slot="stack">
471
+ <div data-slot="controls">
472
+ <label data-slot="label">
473
+ <Checkbox
474
+ :checked="expanded"
475
+ @checked-change="(next) => (expanded = next === true)"
476
+ >
477
+ <CheckboxIndicator>
478
+ <CheckIcon aria-hidden="true" />
479
+ </CheckboxIndicator>
480
+ </Checkbox>
481
+ Always expanded
482
+ </label>
483
+ </div>
484
+ <button @click="toast(notifications[count++ % notifications.length])">
485
+ Add Toast
486
+ </button>
487
+ <ToastRegion :toaster="toast" :max-visible="4" :expanded="expanded">
488
+ <Toast>
489
+ <div data-slot="stack">
490
+ <ToastTitle />
491
+ <ToastDescription />
492
+ </div>
493
+ </Toast>
494
+ </ToastRegion>
495
+ </div>
496
+ </template>
497
+ ```
498
+
499
+ Press Add Toast a few times, then hover the stack to expand it. Past four toasts, the rest wait their turn. Check Always expanded to keep it open.
500
+
501
+ ## Duration
502
+
503
+ Set `duration` in milliseconds, on the toaster or on one toast, or `Infinity` for a toast that stays until it's dismissed. The default is five seconds. Timers pause while the pointer or focus is in the region, and while the page is hidden or its window is inactive.
504
+
505
+ ```vue title="duration.vue"
506
+ <script setup lang="ts">
507
+ import {
508
+ Toast,
509
+ ToastClose,
510
+ ToastRegion,
511
+ ToastTitle,
512
+ createToaster,
513
+ } from "@ui-sdk/vue/toast"
514
+ import { onUnmounted } from "vue"
515
+
516
+ const toast = createToaster()
517
+ onUnmounted(() => {
518
+ toast.dismiss()
519
+ })
520
+
521
+ function untilDismissed() {
522
+ toast("Your session expires in 5 minutes", {
523
+ duration: Infinity,
524
+ dismissible: false,
525
+ cancel: { label: "Got It" },
526
+ })
527
+ }
528
+ </script>
529
+
530
+ <template>
531
+ <div data-slot="row">
532
+ <button @click="toast('Link copied', { duration: 1000 })">1 Second</button>
533
+ <button @click="toast('Changes saved')">5 Seconds</button>
534
+ <button @click="untilDismissed">Until Dismissed</button>
535
+ </div>
536
+ <ToastRegion :toaster="toast">
537
+ <template #default="{ toast: item }">
538
+ <Toast>
539
+ <ToastTitle />
540
+ <ToastClose v-if="item.cancel" data-variant="solid" :action="item.cancel.onCancel">
541
+ {{ item.cancel.label }}
542
+ </ToastClose>
543
+ </Toast>
544
+ </template>
545
+ </ToastRegion>
546
+ </template>
547
+ ```
548
+
549
+ Press each button. Hover a toast to pause its timer. The session toast stays until you press Got It.
550
+
551
+ ## Update and Dismiss
552
+
553
+ Keep the id `toast()` returns to update or dismiss that toast, or pass your own `id`. `toast.update()` returns whether the toast was still there, and `toast.dismiss()` without an id closes every toast.
554
+
555
+ ```vue title="update.vue"
556
+ <script setup lang="ts">
557
+ import { CircleCheckIcon, LoaderCircleIcon } from "@lucide/vue"
558
+ import {
559
+ Toast,
560
+ ToastRegion,
561
+ ToastTitle,
562
+ createToaster,
563
+ } from "@ui-sdk/vue/toast"
564
+ import { onUnmounted } from "vue"
565
+ import { useLog } from "./log"
566
+
567
+ const log = useLog()
568
+ const toast = createToaster()
569
+ let timer: ReturnType<typeof setInterval> | undefined
570
+ onUnmounted(() => {
571
+ clearInterval(timer)
572
+ toast.dismiss()
573
+ })
574
+
575
+ function upload() {
576
+ clearInterval(timer)
577
+ const id = toast.loading("Uploading report.pdf… 0%", { id: "upload" })
578
+ let progress = 0
579
+ timer = setInterval(() => {
580
+ progress += 20
581
+ const done = progress >= 100
582
+ const open = toast.update(
583
+ id,
584
+ done
585
+ ? { title: "Report uploaded", type: "success" }
586
+ : { title: `Uploading report.pdf… ${progress}%` }
587
+ )
588
+ if (!open) {
589
+ log("Upload canceled")
590
+ }
591
+ if (done || !open) {
592
+ clearInterval(timer)
593
+ }
594
+ }, 700)
595
+ }
596
+ </script>
597
+
598
+ <template>
599
+ <div data-slot="row">
600
+ <button @click="upload">Upload Report</button>
601
+ <button @click="toast.dismiss('upload')">Cancel Upload</button>
602
+ <button @click="toast.dismiss()">Dismiss All</button>
603
+ </div>
604
+ <ToastRegion :toaster="toast">
605
+ <Toast>
606
+ <CircleCheckIcon data-show="success" aria-hidden="true" />
607
+ <LoaderCircleIcon data-show="loading" aria-hidden="true" />
608
+ <ToastTitle />
609
+ </Toast>
610
+ </ToastRegion>
611
+ </template>
612
+ ```
613
+
614
+ Press Upload Report and watch one toast count up to Report uploaded. Cancel Upload closes it early, and Dismiss All clears every toast.
615
+
616
+ ## Async Action
617
+
618
+ Return a promise from an action to keep the toast open while it runs. The action's state has `pending` while it runs and `error` if it fails, so the button can say Restoring… or offer a retry, and presses are ignored until it settles. See [Button](./button.md#changes-after-an-await) for changes made after an `await`.
619
+
620
+ ```vue title="async-action.vue"
621
+ <script setup lang="ts">
622
+ import {
623
+ Toast,
624
+ ToastAction,
625
+ ToastDescription,
626
+ ToastRegion,
627
+ ToastTitle,
628
+ createToaster,
629
+ } from "@ui-sdk/vue/toast"
630
+ import { onUnmounted } from "vue"
631
+ import { useLog } from "./log"
632
+
633
+ const log = useLog()
634
+ const toast = createToaster({ duration: 6000 })
635
+ onUnmounted(() => {
636
+ toast.dismiss()
637
+ })
638
+
639
+ function restore() {
640
+ return new Promise((resolve) => setTimeout(resolve, 1500))
641
+ }
642
+
643
+ function deleteFile() {
644
+ toast("File deleted", {
645
+ description: "Q3 report.pdf",
646
+ action: {
647
+ label: "Undo",
648
+ onAction: async () => {
649
+ await restore()
650
+ log("Q3 report.pdf restored")
651
+ },
652
+ },
653
+ })
654
+ }
655
+ </script>
656
+
657
+ <template>
658
+ <button @click="deleteFile">Delete File</button>
659
+ <ToastRegion :toaster="toast">
660
+ <Toast>
661
+ <div data-slot="stack">
662
+ <ToastTitle />
663
+ <ToastDescription />
664
+ </div>
665
+ <ToastAction v-slot="{ state }" data-variant="solid">
666
+ {{ state.pending ? "Restoring…" : state.error ? "Retry" : "Undo" }}
667
+ </ToastAction>
668
+ </Toast>
669
+ </ToastRegion>
670
+ </template>
671
+ ```
672
+
673
+ Press Delete File, then Undo. The button shows Restoring… until the restore finishes, then the toast closes.
674
+
675
+ ## Keyboard Shortcut
676
+
677
+ F6 moves focus to the newest toast and back. Set the region's `shortcut` to use another key, or `null` to turn it off. The region advertises it through `aria-keyshortcuts`.
678
+
679
+ ```vue title="shortcut.vue"
680
+ <script setup lang="ts">
681
+ import {
682
+ Toast,
683
+ ToastAction,
684
+ ToastRegion,
685
+ ToastTitle,
686
+ createToaster,
687
+ } from "@ui-sdk/vue/toast"
688
+ import { onUnmounted } from "vue"
689
+ import { useLog } from "./log"
690
+
691
+ const log = useLog()
692
+ const toast = createToaster({ duration: 10000 })
693
+ onUnmounted(() => {
694
+ toast.dismiss()
695
+ })
696
+
697
+ function sendMessage() {
698
+ toast("Message sent", {
699
+ action: { label: "Undo", onAction: () => log("Message unsent") },
700
+ })
701
+ }
702
+ </script>
703
+
704
+ <template>
705
+ <button @click="sendMessage">Send Message</button>
706
+ <ToastRegion :toaster="toast" shortcut="alt+t" aria-label="Alerts">
707
+ <Toast>
708
+ <ToastTitle />
709
+ <ToastAction data-variant="solid" />
710
+ </Toast>
711
+ </ToastRegion>
712
+ </template>
713
+ ```
714
+
715
+ Press Send Message, then Alt+T (Option+T on a Mac) to focus the toast. Press Escape to dismiss it, or Alt+T again to go back.
716
+
717
+ ## Overlay Host and Confirm
718
+
719
+ Instead of placing a region, render `OverlayHost` once near your app's root. It renders the toaster's region, with the `#toast` slot you give it, and `confirm()` questions as alert dialogs. A region you place yourself takes over from the host for its toaster.
720
+
721
+ To style the question, render an `AlertDialog` with the confirm controller and read the question from its content's `payload`. [Alert Dialog](./alert-dialog.md) covers `createConfirm()` in more detail.
722
+
723
+ ```vue title="overlay-host.vue"
724
+ <script setup lang="ts">
725
+ import { CircleCheckIcon } from "@lucide/vue"
726
+ import {
727
+ AlertDialog,
728
+ AlertDialogBackdrop,
729
+ AlertDialogClose,
730
+ AlertDialogContent,
731
+ AlertDialogDescription,
732
+ AlertDialogTitle,
733
+ createConfirm,
734
+ type ConfirmOptions,
735
+ } from "@ui-sdk/vue/alert-dialog"
736
+ import { OverlayHost, createOverlays } from "@ui-sdk/vue/overlays"
737
+ import { Toast, ToastTitle, createToaster } from "@ui-sdk/vue/toast"
738
+ import { onUnmounted, ref, useTemplateRef } from "vue"
739
+
740
+ const overlays = createOverlays()
741
+ const toast = createToaster({ overlays })
742
+ const confirm = createConfirm({ overlays })
743
+ const ConfirmAlertDialogContent = AlertDialogContent<ConfirmOptions>
744
+ const projects = ref(["Acme", "Globex", "Initech"])
745
+ const reset = useTemplateRef<HTMLButtonElement>("reset")
746
+ onUnmounted(() => {
747
+ toast.dismiss()
748
+ })
749
+
750
+ async function remove(name: string, button: HTMLButtonElement) {
751
+ const confirmed = await confirm({
752
+ title: `Delete ${name}?`,
753
+ description:
754
+ "The project and its files will be deleted for everyone on your team.",
755
+ confirmLabel: "Delete",
756
+ cancelLabel: "Cancel",
757
+ })
758
+ if (!confirmed) {
759
+ return
760
+ }
761
+ const row = button.closest("li")
762
+ const next = (
763
+ row?.nextElementSibling ?? row?.previousElementSibling
764
+ )?.querySelector("button")
765
+ ;(next ?? reset.value)?.focus()
766
+ projects.value = projects.value.filter((project) => project !== name)
767
+ toast.success(`${name} deleted`, { priority: "assertive" })
768
+ }
769
+ </script>
770
+
771
+ <template>
772
+ <div data-slot="stack">
773
+ <div data-slot="controls">
774
+ <button ref="reset" type="button" @click="projects = ['Acme', 'Globex', 'Initech']">
775
+ Reset Projects
776
+ </button>
777
+ </div>
778
+ <ul data-slot="list" aria-label="Projects">
779
+ <li v-for="name in projects" :key="name" data-slot="row">
780
+ {{ name }}
781
+ <button
782
+ type="button"
783
+ data-size="sm"
784
+ :aria-label="`Delete ${name}`"
785
+ @click="remove(name, $event.currentTarget as HTMLButtonElement)"
786
+ >
787
+ Delete
788
+ </button>
789
+ </li>
790
+ <li v-if="projects.length === 0" data-slot="row">
791
+ All projects deleted.
792
+ </li>
793
+ </ul>
794
+ <OverlayHost :overlays="overlays">
795
+ <template #toast>
796
+ <Toast>
797
+ <CircleCheckIcon data-show="success" aria-hidden="true" />
798
+ <ToastTitle />
799
+ </Toast>
800
+ </template>
801
+ </OverlayHost>
802
+ <AlertDialog :controller="confirm.controller">
803
+ <AlertDialogBackdrop />
804
+ <ConfirmAlertDialogContent v-slot="{ state }">
805
+ <div data-slot="stack">
806
+ <AlertDialogTitle>{{ state.payload?.title }}</AlertDialogTitle>
807
+ <AlertDialogDescription>{{
808
+ state.payload?.description
809
+ }}</AlertDialogDescription>
810
+ </div>
811
+ <div data-slot="row">
812
+ <AlertDialogClose>{{ state.payload?.cancelLabel }}</AlertDialogClose>
813
+ <AlertDialogClose data-variant="solid" value="confirm">
814
+ {{ state.payload?.confirmLabel }}
815
+ </AlertDialogClose>
816
+ </div>
817
+ </ConfirmAlertDialogContent>
818
+ </AlertDialog>
819
+ </div>
820
+ </template>
821
+ ```
822
+
823
+ Press Delete on a project and confirm. The row goes away and a toast says so. Reset Projects brings them back.
824
+
825
+ ## Custom Rendering
826
+
827
+ Pass anything else your toast needs in `data`, and read it from the `toast` the region's default slot receives. Every part also takes a `#render` slot; this example renders each toast's `li` itself, making the ones hidden behind a collapsed stack `inert`.
828
+
829
+ ```vue title="custom.vue"
830
+ <script setup lang="ts">
831
+ import { XIcon } from "@lucide/vue"
832
+ import {
833
+ Toast,
834
+ ToastAction,
835
+ ToastClose,
836
+ ToastDescription,
837
+ ToastRegion,
838
+ ToastTitle,
839
+ createToaster,
840
+ } from "@ui-sdk/vue/toast"
841
+ import { onUnmounted } from "vue"
842
+ import { useLog } from "./log"
843
+
844
+ const log = useLog()
845
+ const toast = createToaster()
846
+ onUnmounted(() => {
847
+ toast.dismiss()
848
+ })
849
+
850
+ function newMessage() {
851
+ toast({
852
+ title: "Hollis Grant",
853
+ description: "Can you review the draft?",
854
+ data: { initials: "HG" },
855
+ action: { label: "Reply", onAction: () => log("Replying to Hollis Grant") },
856
+ })
857
+ }
858
+ </script>
859
+
860
+ <template>
861
+ <button @click="newMessage">New Message</button>
862
+ <ToastRegion :toaster="toast" aria-label="Messages">
863
+ <template #default="{ toast: item }">
864
+ <Toast>
865
+ <template #render="{ props, state, children }">
866
+ <li
867
+ v-bind="props"
868
+ :inert="
869
+ state.leaving || (!state.expanded && state.index > 0) || undefined
870
+ "
871
+ >
872
+ <component :is="children" />
873
+ </li>
874
+ </template>
875
+ <template #default>
876
+ <span data-slot="media">{{
877
+ (item.data as { initials: string }).initials
878
+ }}</span>
879
+ <div data-slot="stack">
880
+ <ToastTitle />
881
+ <ToastDescription />
882
+ </div>
883
+ <ToastAction data-variant="solid" />
884
+ <ToastClose aria-label="Close">
885
+ <XIcon aria-hidden="true" />
886
+ </ToastClose>
887
+ </template>
888
+ </Toast>
889
+ </template>
890
+ </ToastRegion>
891
+ </template>
892
+ ```
893
+
894
+ Press New Message to show a toast with Hollis Grant's initials. Choose Reply or close it.
895
+
896
+ ## Styling
897
+
898
+ Toasts are unstyled, and the region and its toasts carry what you need to animate a stack:
899
+
900
+ - **The stack.** The region sets `--toast-front-height`, the newest toast's height, and `--toast-stack-height`, all of them added up. Each toast gets `--toast-index`, 0 for the newest, `--toast-offset`, the height of the toasts in front of it, and `--toast-height`, its own height. Position the toasts absolutely in the region and set `height: var(--toast-height)` so changes in height animate.
901
+ - **Collapsed and expanded.** `data-front` marks the newest toast. While the stack is collapsed, clip the toasts behind it to `--toast-front-height` and peek them out by their index. While it's expanded, the region and its toasts get `data-expanded`; move each toast by its `--toast-offset`.
902
+ - **Swiping.** While a toast is swiped it gets `data-swiping`, and `--toast-swipe-x` and `--toast-swipe-y` hold how far it moved. Translate it by them and turn off transitions. When a swipe dismisses it, `data-swipe-direction` says which way, so it can leave in that direction. A mouse drag that starts on selectable text selects it, so set `user-select: none` on toasts to swipe them from anywhere.
903
+ - **Entering and leaving.** A toast has `data-starting-style` for its first frame and `data-ending-style` while it leaves, and stays mounted until its transitions finish.
904
+
905
+ A stack at the bottom of the page, in plain CSS:
906
+
907
+ ```css
908
+ [data-slot="toast-region"] {
909
+ width: 356px;
910
+ height: var(--toast-front-height);
911
+ }
912
+
913
+ [data-slot="toast-region"][data-expanded] {
914
+ height: calc(var(--toast-stack-height) + (var(--toast-count) - 1) * 12px);
915
+ }
916
+
917
+ [data-slot="toast"] {
918
+ --y: calc(var(--toast-index) * -12px);
919
+ position: absolute;
920
+ inset-inline: 0;
921
+ bottom: 0;
922
+ z-index: calc(100 - var(--toast-index));
923
+ overflow: hidden;
924
+ height: var(--toast-height);
925
+ translate: var(--toast-swipe-x, 0px)
926
+ calc(var(--y) + var(--toast-swipe-y, 0px));
927
+ scale: calc(1 - var(--toast-index) * 0.05);
928
+ transition-property: translate, scale, opacity, height;
929
+ transition-duration: 400ms;
930
+ user-select: none;
931
+ }
932
+
933
+ [data-slot="toast"]:not([data-front], [data-expanded]) {
934
+ height: var(--toast-front-height);
935
+ }
936
+
937
+ [data-slot="toast"][data-expanded] {
938
+ --y: calc(-1 * (var(--toast-offset) + var(--toast-index) * 12px));
939
+ scale: 1;
940
+ }
941
+
942
+ [data-slot="toast"][data-starting-style] {
943
+ transition: none;
944
+ }
945
+
946
+ [data-slot="toast"][data-starting-style][data-front] {
947
+ --y: 100%;
948
+ }
949
+
950
+ [data-slot="toast"]:is(
951
+ [data-starting-style]:not([data-front]),
952
+ [data-ending-style]
953
+ ) {
954
+ opacity: 0;
955
+ }
956
+
957
+ [data-slot="toast"][data-swiping] {
958
+ transition: none;
959
+ }
960
+
961
+ @media (prefers-reduced-motion: reduce) {
962
+ [data-slot="toast"] {
963
+ transition-property: opacity;
964
+ }
965
+ }
966
+ ```
967
+
968
+ Each part has a `data-slot`, such as `toast`, and its state attributes are listed under [Data Attributes](#data-attributes).
969
+
970
+ ### ToastRegion
971
+ - `--toast-front-height`: The newest toast's height. Clip the toasts behind it to it in a collapsed stack.
972
+ - `--toast-stack-height`: The toasts' heights added up, for the height of an expanded stack.
973
+ - `--toast-count`: How many toasts show.
974
+ - `--keyboard-inset`: How many pixels of the page the on-screen keyboard covers, 0 without one.
975
+ - `--visual-viewport-width`: The width of the part of the page you can see.
976
+ - `--visual-viewport-height`: The height of the part of the page you can see, above the keyboard.
977
+ - `--visual-viewport-top`: How far the part of the page you can see is scrolled from the top of the layout, as when the keyboard pushes it up.
978
+
979
+ ### Toast
980
+ - `--toast-index`: The toast's place in the stack, 0 for the newest. A closing toast keeps its place.
981
+ - `--toast-offset`: The height of the toasts in front of this one, in pixels. Add gaps with `--toast-index` to place an expanded stack.
982
+ - `--toast-height`: The toast's own height with its content laid out freely, whatever height it's given. Set it as the height to animate the stack.
983
+ - `--toast-swipe-x`: How far a swipe moved the toast sideways, in pixels. Translate the toast by it.
984
+ - `--toast-swipe-y`: How far a swipe moved the toast up or down, in pixels.
985
+
986
+ ## Data Attributes
987
+
988
+ `ToastTitle` and `ToastDescription` have no state attributes. `ToastClose` gets `data-pending`, like `ToastAction`, while a Promise from its `action` runs.
989
+
990
+ ### ToastRegion
991
+ `[data-slot="toast-region"]`
992
+
993
+ - `data-side` (`top`, `bottom`): The edge of the viewport the region sits on.
994
+ - `data-align` (`start`, `center`, `end`): Where along that edge.
995
+ - `data-expanded`: Present while the stack is expanded: hovered, focused, or always with `expanded`.
996
+ - `data-keyboard`: Present on the region while the on-screen keyboard covers part of the page.
997
+
998
+ ### Toast
999
+ `[data-slot="toast"]`
1000
+
1001
+ - `data-type` (`default`, `success`, `error`, `info`, `warning`, `loading`): What the toast is about.
1002
+ - `data-front`: Present on the newest toast, in front of a collapsed stack. A closing toast keeps it while it animates out.
1003
+ - `data-expanded`: Present while the stack is expanded: hovered, focused, or always with `expanded`.
1004
+ - `data-starting-style`: Present for a toast's first frame. Style the state you animate from.
1005
+ - `data-ending-style`: Present while a toast animates out. Style the state you animate to.
1006
+
1007
+ ### ToastAction
1008
+ `[data-slot="toast-action"]`
1009
+
1010
+ - `data-pending`: Present on an action or close button while its handler's Promise runs.
1011
+
1012
+ ## API Reference
1013
+
1014
+ ### Toast
1015
+
1016
+ - `id?` (`string`): Reuses a toast: a toast with this id that's still showing is updated instead of added again.
1017
+ - `title?` (`Content`): The main message.
1018
+ - `description?` (`Content`): More detail, under the title.
1019
+ - `type?` (`ToastType`): What it's about, for styling through `data-type`, and for how it's announced.
1020
+ - `duration?` (`number`): How long it shows, in ms, while nothing pauses it. `Infinity` keeps it until dismissed.
1021
+ - `priority?` (`"assertive" | "polite"`): How screen readers announce it: `"polite"` waits for a pause, `"assertive"` interrupts.
1022
+ - `action?` (`ToastAction<Content>`): A button that does something, like Undo.
1023
+ - `cancel?` (`ToastCancel<Content>`): A button that dismisses it, like Cancel.
1024
+ - `dismissible?` (`boolean`): Whether the user can dismiss it: swiping, Escape and Close parts. Timers and `dismiss()` still close it.
1025
+ - `data?` (`unknown`): Anything else, for your own rendering, like an avatar.
1026
+ - `onDismiss?` (`((details: ToastDismissDetails) => void)`): Runs when it closes, with why. Calling `details.cancel()` keeps it.
1027
+
1028
+ `toast(message, options)` and `toast(options)` return the toast's id. `toast.success`, `.info`, `.warning`, `.error` and `.loading` set the type. `toast.promise(promise, { loading, success, error })` returns the id too, and `toast.update(id, options)` returns whether the toast was still there. `toast.dismiss(id)` closes one, and `toast.dismiss()` every one.
1029
+
1030
+ ### Actions
1031
+
1032
+ - `label` (`Content`): The button's text.
1033
+ - `onAction?` (`((event: Event | undefined, details: ToastActionDetails) => unknown)`): Runs when it's pressed. A returned Promise marks the action pending, then dismisses the toast once it resolves. A rejection keeps the toast. `details.source` says how it was pressed, for changes made after an `await`.
1034
+ - `href?` (`string`): Makes the action a link.
1035
+ - `dismiss?` (`boolean`): Whether pressing it dismisses the toast.
1036
+
1037
+ - `label` (`Content`): The button's text.
1038
+ - `onCancel?` (`((event: Event | undefined, details: ToastActionDetails) => void)`): Runs when it's pressed, before the toast closes. `details.source` says how it was pressed.
1039
+
1040
+ ### ToastRegion
1041
+
1042
+ - `toaster?` (`Toaster<any>`): The queue it shows. A second toaster, from `createToaster()`, gives a second region its own toasts.
1043
+ - `side?` (`"bottom" | "top"`): The edge of the viewport it sits on. Swiping toward it dismisses a toast.
1044
+ - `align?` (`"center" | "end" | "start"`): Where along that edge. `"start"` and `"end"` follow the writing direction, and swiping toward them dismisses too.
1045
+ - `maxVisible?` (`number`): How many toasts show at once. Older ones wait, with their timers stopped, until there's room.
1046
+ - `expanded?` (`boolean`): Whether the stack is always expanded. Otherwise it expands while the pointer or focus is in it.
1047
+ - `shortcut?` (`string | null`): The key that moves focus into the region and back, like `"F6"` or `"alt+t"`. `null` turns it off.
1048
+ - `pendingAnnouncement?` (`string`): What screen readers hear once a toast's action or close button has been pending for a second, so a slow action doesn't pass in silence. Set it in the page's language. An empty string says nothing.
1049
+ - `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.
1050
+
1051
+ ### ToastAction
1052
+
1053
+ - `@action` (`((event: Event | undefined, details: ToastActionDetails) => unknown)`): Runs when it's pressed, instead of the toast's own `action.onAction`. A returned Promise marks it pending. `details.source` says how it was pressed, for changes made after an `await`.
1054
+ - `dismiss?` (`boolean`): Whether pressing it dismisses the toast.
1055
+
1056
+ ### ToastClose
1057
+
1058
+ - `action?` (`((event: Event | undefined, details: ToastActionDetails) => unknown)`): Runs before the toast closes. A returned Promise keeps it open and the button pending until it settles. `details.source` says how it was pressed, for changes made after an `await`.
1059
+
1060
+ ### Confirm
1061
+
1062
+ - `title` (`string`): The question, like "Delete this project?".
1063
+ - `description?` (`string`): What agreeing does.
1064
+ - `confirmLabel?` (`string`): The agreeing button's text.
1065
+ - `cancelLabel?` (`string`): The other button's text.
1066
+
1067
+ ### State
1068
+
1069
+ `ToastRegion`:
1070
+
1071
+ - `side` (`"top" | "bottom"`): The edge it sits on.
1072
+ - `align` (`"start" | "center" | "end"`): Where along that edge.
1073
+ - `expanded` (`boolean`): Whether the stack is expanded.
1074
+ - `toasts` (`readonly ToastItem<unknown>[]`): The toasts to render, newest first, including ones animating out.
1075
+
1076
+ `Toast`:
1077
+
1078
+ - `type` (`ToastType`): What it's about.
1079
+ - `index` (`number`): Its place in the stack, 0 for the newest.
1080
+ - `front` (`boolean`): Whether it's the newest, on top of a collapsed stack. A closing toast keeps it.
1081
+ - `expanded` (`boolean`): Whether the stack is expanded.
1082
+ - `leaving` (`boolean`): Whether it's animating out.
1083
+
1084
+ `ToastAction` and `ToastClose`:
1085
+
1086
+ - `pending` (`boolean`): Whether a Promise its handler returned is still running.
1087
+ - `error` (`unknown`): Why its handler failed, until it's pressed again.
1088
+
1089
+ ### Reasons
1090
+
1091
+ - `timeout` (`none`): A duration ran out, like a toast's, or a rotating carousel's interval.
1092
+ - `close-press` (`MouseEvent | KeyboardEvent | SubmitEvent`): A Close part was pressed, or a form with `method="dialog"` was submitted.
1093
+ - `swipe` (`TouchEvent | PointerEvent`): A swipe gesture: a finger, mouse or pen dragged it.
1094
+ - `escape-key` (`KeyboardEvent`): Escape, or a submenu's close key (ArrowLeft in left-to-right layouts).
1095
+ - `action` (`MouseEvent | KeyboardEvent`): A Close part's `action` finished.
1096
+ - `imperative` (`none`): A controller or `api` call, or a property set on a web component.
1097
+
1098
+ ## Accessibility
1099
+
1100
+ Toasts are announced through shared [live regions](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Guides/Live_regions), once each, without making the visible region live: politely by default and assertively for errors. While it has toasts, the region is a landmark named Notifications; set `aria-label` to name it in the page's language. Keep messages short, and use `duration: Infinity` for one that has to stay available.
1101
+
1102
+ ### Keyboard
1103
+
1104
+ F6, or the region's `shortcut`, moves focus to the newest toast, and pressing it again returns focus to where it came from. Tab moves through the toasts and their buttons, and Tab past the last one goes back too. Escape dismisses the focused toast; focus then moves to the next toast, or back where it came from after the last one. The region stays reachable while a modal dialog is open, and its timers pause while focus is inside.
1105
+
1106
+ ### Tested Behavior
1107
+
1108
+ Every line below is an automated test.
1109
+
1110
+ **Showing**
1111
+
1112
+ - A toast shows its title, description and action in the Notifications region.
1113
+ - Newer toasts come first.
1114
+ - The newest toast is marked as the front one.
1115
+ - Each toast says what it's about through data-type.
1116
+ - The region sits on its side and alignment.
1117
+ - It shows above everything, in the top layer.
1118
+ - A promise toast loads, then shows the result.
1119
+ - A toast with an id that's showing is updated in place.
1120
+
1121
+ **Closing**
1122
+
1123
+ - A toast closes after its duration.
1124
+ - Infinity keeps it until it's dismissed.
1125
+ - The Dismiss button closes it.
1126
+ - The action runs and closes it.
1127
+ - Escape on a focused toast closes it.
1128
+ - A closing toast stays while it animates out.
1129
+ - A toast that can't be dismissed ignores Escape.
1130
+
1131
+ **Timers**
1132
+
1133
+ - Hovering the region pauses its timers, and leaving resumes them.
1134
+ - Focus in the region pauses its timers.
1135
+
1136
+ **Keyboard**
1137
+
1138
+ - F6 moves focus to the newest toast, and again back where it was.
1139
+ - The shortcut is configurable.
1140
+ - The region names its shortcut.
1141
+ - When the focused toast closes, focus goes to the next one, then back where it was.
1142
+
1143
+ **Stacking**
1144
+
1145
+ - Only maxVisible toasts show; the rest wait for room.
1146
+ - The stack expands while hovered or focused.
1147
+ - Expanded keeps the stack expanded.
1148
+ - Toasts measure their heights and offsets for the stack.
1149
+ - A toast measures its content's height, whatever height it's given.
1150
+ - A toast given its measured height animates to a new one when its content changes.
1151
+ - A toast measures again when a child, its class or its padding changes.
1152
+ - A toast closing from the front stays in front while it animates out.
1153
+
1154
+ **Swiping**
1155
+
1156
+ - Swiping toward the region's side dismisses.
1157
+ - Swiping toward the aligned edge dismisses too.
1158
+ - A short swipe snaps back.
1159
+ - Swiping away from the side never dismisses.
1160
+ - A toast that can't be dismissed doesn't swipe.
1161
+
1162
+ **Over a modal dialog**
1163
+
1164
+ - A toast shown from a modal dialog is visible, usable and above it.
1165
+
1166
+ **Updates after closing**
1167
+
1168
+ - A promise toast dismissed while loading stays closed.
1169
+ - An update after a toast closed never brings it back.
1170
+
1171
+ **More pausing and keys**
1172
+
1173
+ - The window losing focus pauses timers, and getting it back resumes them.
1174
+ - F6 does nothing while there are no toasts, so the browser keeps it.
1175
+ - A toast on the top edge swipes up, and a swipe down snaps back.
1176
+
1177
+ Runs in React, Vue and web components.
1178
+
1179
+ Also tested:
1180
+
1181
+ **Enhancements**
1182
+
1183
+ - Update() says whether the toast was still there.
1184
+ - A toast beyond maxVisible never expires unseen.
1185
+ - There's no empty Notifications landmark.
1186
+ - Focus never falls to the page when a toast focused by the mouse closes.
1187
+ - A pending action shows it and holds the toast open until it settles.
1188
+
1189
+ **Pausing**
1190
+
1191
+ - A hidden page pauses timers.
1192
+ - Pause reasons hold separately: getting the window back doesn't resume while focus is in the region.
1193
+
1194
+ **Announcements**
1195
+
1196
+ - The live regions exist before the first toast.
1197
+ - A toast is announced politely, with its title and description.
1198
+ - An error is announced assertively.
1199
+ - Toasts that arrive together are announced together.
1200
+ - The visible region isn't a live region, so nothing is read twice.
1201
+
1202
+ **The shortcut**
1203
+
1204
+ - F6 works from a text field and types nothing.
1205
+ - A shortcut of null turns it off.
1206
+ - Tab past the last toast goes back where F6 came from.
1207
+
1208
+ **Over modal dialogs**
1209
+
1210
+ - F6 reaches the toasts from inside a modal dialog, and goes back into it.
1211
+ - Escape on a toast closes the toast, not the dialog beneath.
1212
+ - A dialog opened after a toast doesn't cover it, and pressing it doesn't close the dialog.
1213
+
1214
+ **Swiping**
1215
+
1216
+ - Dragging across a toast's text with a mouse selects it instead of dismissing.
1217
+
1218
+ Runs in React, Vue and web components.
1219
+
1220
+ Screen readers hear the same thing in each tested framework, recorded by a virtual screen reader:
1221
+
1222
+ - Announcements while reaching a toast with F6 and leaving it.
1223
+
1224
+ Runs in React, Vue and web components.