x
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<div class="tw:p-6 tw:max-w-7xl tw:mx-auto tw:space-y-8"> <!-- Introductory callout --> <div class="tw-callout"> <p class="tw:mb-1 tw:text-sm tw:font-mono"> <strong>TOAST:</strong> Lightweight confirmation messages that appear after user actions<br> <strong>POSITIONING:</strong> Bottom-center, slides up from bottom edge<br> <strong>CLASSES:</strong> .tw-toast .tw-toast-container .tw-toast-visible .tw-toast-dismissing .tw-toast-success .tw-toast-error .tw-toast-warning .tw-toast-info .tw-toast-icon .tw-toast-message .tw-toast-action .tw-toast-close </p> <p class="tw:mb-0 tw:text-sm"> Toasts provide quick, non-blocking confirmations (e.g., "Copied!", "Saved!", "Undo available"). Auto-dismiss after 3 seconds (6s with action), pause-on-hover supported. Dark background with semantic color via icon only. </p> </div> <!-- Section 1: Basic Toast --> <div class="tw:border-t tw:pt-6"> <h2 class="tw-h4 tw:mb-4">Basic Toast</h2> <div class="tw-callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Minimal Structure:</strong> Icon + message in dark container. White text ensures readability. </p> </div> <div class="tw:relative tw:h-32 tw:bg-neutral-100 tw:rounded-lg tw:flex tw:items-end tw:justify-center tw:pb-4"> <div class="tw-toast tw-toast-visible"> <i class="fa-solid fa-check tw-toast-icon"></i> <span class="tw-toast-message">Changes saved successfully</span> </div> </div> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div class="tw-toast tw-toast-visible"><br> <i class="fa-solid fa-check tw-toast-icon"></i><br> <span class="tw-toast-message">Changes saved successfully</span><br> </div></code> </div> </div> <!-- Section 2: Semantic Variants --> <div class="tw:border-t tw:pt-6"> <h2 class="tw-h4 tw:mb-4">Semantic Variants</h2> <div class="tw-callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Icon Color Only:</strong> Dark background remains consistent. Add .tw-toast-success, .tw-toast-error, .tw-toast-warning, or .tw-toast-info to color the icon. </p> </div> <div class="tw:relative tw:bg-neutral-100 tw:rounded-lg tw:p-6 tw:space-y-3"> <div class="tw:flex tw:justify-center"> <div class="tw-toast tw-toast-success tw-toast-visible"> <i class="fa-solid fa-circle-check tw-toast-icon"></i> <span class="tw-toast-message">Application submitted successfully</span> </div> </div> <div class="tw:flex tw:justify-center"> <div class="tw-toast tw-toast-error tw-toast-visible"> <i class="fa-solid fa-circle-xmark tw-toast-icon"></i> <span class="tw-toast-message">Failed to save changes</span> </div> </div> <div class="tw:flex tw:justify-center"> <div class="tw-toast tw-toast-warning tw-toast-visible"> <i class="fa-solid fa-triangle-exclamation tw-toast-icon"></i> <span class="tw-toast-message">Connection unstable — changes may not save</span> </div> </div> <div class="tw:flex tw:justify-center"> <div class="tw-toast tw-toast-info tw-toast-visible"> <i class="fa-solid fa-circle-info tw-toast-icon"></i> <span class="tw-toast-message">New version available</span> </div> </div> </div> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div class="tw-toast tw-toast-success tw-toast-visible">...</div><br> <div class="tw-toast tw-toast-error tw-toast-visible">...</div><br> <div class="tw-toast tw-toast-warning tw-toast-visible">...</div><br> <div class="tw-toast tw-toast-info tw-toast-visible">...</div></code> </div> </div> <!-- Section 3: With Close Button --> <div class="tw:border-t tw:pt-6"> <h2 class="tw-h4 tw:mb-4">With Close Button</h2> <div class="tw-callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Manual Dismiss:</strong> Add .tw-toast-close button for user-controlled dismissal. Still auto-dismisses unless disabled. </p> </div> <div class="tw:relative tw:h-32 tw:bg-neutral-100 tw:rounded-lg tw:flex tw:items-end tw:justify-center tw:pb-4"> <div class="tw-toast tw-toast-visible"> <i class="fa-solid fa-check tw-toast-icon"></i> <span class="tw-toast-message">Email copied to clipboard</span> <button type="button" class="tw-toast-close" aria-label="Dismiss"> <i class="fa-solid fa-xmark"></i> </button> </div> </div> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div class="tw-toast tw-toast-visible"><br> <i class="fa-solid fa-check tw-toast-icon"></i><br> <span class="tw-toast-message">Email copied to clipboard</span><br> <button type="button" class="tw-toast-close" aria-label="Dismiss"><br> <i class="fa-solid fa-xmark"></i><br> </button><br> </div></code> </div> </div> <!-- Section 4: With Action Button --> <div class="tw:border-t tw:pt-6"> <h2 class="tw-h4 tw:mb-4">With Action Button</h2> <div class="tw-callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Actionable:</strong> Add .toast-action link/button for quick actions (e.g., "Undo", "View"). Auto-dismiss extends to 6 seconds when action is present. </p> </div> <div class="tw:relative tw:h-32 tw:bg-neutral-100 tw:rounded-lg tw:flex tw:items-end tw:justify-center tw:pb-4"> <div class="tw-toast tw-toast-visible"> <i class="fa-solid fa-trash tw-toast-icon"></i> <span class="tw-toast-message">3 items deleted</span> <button type="button" class="tw-toast-action">Undo</button> </div> </div> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div class="tw-toast tw-toast-visible"><br> <i class="fa-solid fa-trash tw-toast-icon"></i><br> <span class="tw-toast-message">3 items deleted</span><br> <button type="button" class="tw-toast-action">Undo</button><br> </div></code> </div> </div> <!-- Section 5: Without Close Button --> <div class="tw:border-t tw:pt-6"> <h2 class="tw-h4 tw:mb-4">Without Close Button</h2> <div class="tw-callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Auto-dismiss Only:</strong> Omit close button for brief confirmations that should disappear automatically. </p> </div> <div class="tw:relative tw:h-32 tw:bg-neutral-100 tw:rounded-lg tw:flex tw:items-end tw:justify-center tw:pb-4"> <div class="tw-toast tw-toast-success tw-toast-visible"> <i class="fa-solid fa-circle-check tw-toast-icon"></i> <span class="tw-toast-message">Link copied!</span> </div> </div> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div class="tw-toast tw-toast-success tw-toast-visible"><br> <i class="fa-solid fa-circle-check tw-toast-icon"></i><br> <span class="tw-toast-message">Link copied!</span><br> </div></code> </div> </div> <!-- Section 6: Stacked Toasts --> <div class="tw:border-t tw:pt-6"> <h2 class="tw-h4 tw:mb-4">Stacked Toasts</h2> <div class="tw-callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Multiple Toasts:</strong> Container uses flex-col-reverse so newer toasts appear above older ones. Each auto-dismisses independently. </p> </div> <div class="tw:relative tw:h-64 tw:bg-neutral-100 tw:rounded-lg tw:flex tw:items-end tw:justify-center tw:pb-4"> <div class="tw:flex tw:flex-col-reverse tw:gap-3 tw:items-center"> <div class="tw-toast tw-toast-visible"> <i class="fa-solid fa-check tw-toast-icon"></i> <span class="tw-toast-message">Profile updated</span> </div> <div class="tw-toast tw-toast-success tw-toast-visible"> <i class="fa-solid fa-circle-check tw-toast-icon"></i> <span class="tw-toast-message">Password changed successfully</span> </div> <div class="tw-toast tw-toast-info tw-toast-visible"> <i class="fa-solid fa-circle-info tw-toast-icon"></i> <span class="tw-toast-message">Security settings updated</span> <button type="button" class="tw-toast-close" aria-label="Dismiss"> <i class="fa-solid fa-xmark"></i> </button> </div> </div> </div> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div class="tw-toast-container"><br> <!-- Newer toasts appear above older ones --><br> <div class="tw-toast tw-toast-visible">...</div><br> <div class="tw-toast tw-toast-visible">...</div><br> <div class="tw-toast tw-toast-visible">...</div><br> </div></code> </div> </div> <!-- Section 7: Interactive Demo --> <div class="tw:border-t tw:pt-6"> <h2 class="tw-h4 tw:mb-4">Interactive Demo</h2> <div class="tw-callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Live Controller:</strong> Click buttons below to spawn toasts with Stimulus controller. Features auto-dismiss (3s default, 6s with action), pause-on-hover, manual dismiss via close button, and Escape key support. </p> </div> <!-- Toast container for interactive demo --> <div data-controller="toast" class="tw:relative tw:h-96 tw:bg-neutral-100 tw:rounded-lg"> <div class="tw-toast-container" class="tw:absolute"> <!-- Toasts will be appended here dynamically --> </div> <!-- Control buttons --> <div class="tw:absolute tw:top-6 tw:left-6 tw:right-6 tw:flex tw:flex-wrap tw:gap-3 tw:justify-center"> <button type="button" class="tw-btn tw-btn-sm tw-btn-primary" onclick="showToast('basic')"> Basic Toast </button> <button type="button" class="tw-btn tw-btn-sm tw-btn-success" onclick="showToast('success')"> Success Toast </button> <button type="button" class="tw-btn tw-btn-sm tw-btn-danger" onclick="showToast('error')"> Error Toast </button> <button type="button" class="tw-btn tw-btn-sm tw-btn-warning" onclick="showToast('warning')"> Warning Toast </button> <button type="button" class="tw-btn tw-btn-sm tw-btn-info" onclick="showToast('info')"> Info Toast </button> <button type="button" class="tw-btn tw-btn-sm tw-btn-outline-secondary" onclick="showToast('action')"> With Action </button> <button type="button" class="tw-btn tw-btn-sm tw-btn-outline-secondary" onclick="showToast('persistent')"> Persistent (No Auto-dismiss) </button> </div> <div class="tw:absolute tw:bottom-6 tw:left-6 tw:right-6 tw:text-center tw:text-sm text-muted"> <p class="tw:mb-1"> <strong>Interactions:</strong> Hover to pause auto-dismiss • Click X to close • Press Escape to dismiss topmost </p> <p class="tw:mb-0"> <strong>Duration:</strong> 3s default • 6s with action button • Disabled when data-auto-dismiss="0" </p> </div> </div> <script> function showToast(type) { const container = document.querySelector('[data-controller="toast"] .tw-toast-container'); const toast = document.createElement('div'); toast.className = 'tw-toast'; toast.setAttribute('data-toast-target', 'toast'); toast.setAttribute('role', 'status'); toast.setAttribute('aria-live', 'polite'); let icon = ''; let message = ''; let variant = ''; let hasAction = false; let autoDismiss = ''; switch(type) { case 'basic': icon = '<i class="fa-solid fa-check tw-toast-icon"></i>'; message = 'Changes saved successfully'; break; case 'success': icon = '<i class="fa-solid fa-circle-check tw-toast-icon"></i>'; message = 'Application submitted successfully'; variant = 'tw-toast-success'; break; case 'error': icon = '<i class="fa-solid fa-circle-xmark tw-toast-icon"></i>'; message = 'Failed to save changes'; variant = 'tw-toast-error'; break; case 'warning': icon = '<i class="fa-solid fa-triangle-exclamation tw-toast-icon"></i>'; message = 'Connection unstable — changes may not save'; variant = 'tw-toast-warning'; break; case 'info': icon = '<i class="fa-solid fa-circle-info tw-toast-icon"></i>'; message = 'New version available'; variant = 'tw-toast-info'; break; case 'action': icon = '<i class="fa-solid fa-trash tw-toast-icon"></i>'; message = '3 items deleted'; hasAction = true; break; case 'persistent': icon = '<i class="fa-solid fa-circle-info tw-toast-icon"></i>'; message = 'This toast will not auto-dismiss'; variant = 'tw-toast-info'; autoDismiss = ' data-auto-dismiss="0"'; break; } if (variant) { toast.className += ' ' + variant; } let html = icon + '<span class="tw-toast-message">' + message + '</span>'; if (hasAction) { html += '<button type="button" class="tw-toast-action" onclick="console.log(\'Action clicked\')">Undo</button>'; } html += '<button type="button" class="tw-toast-close" aria-label="Dismiss" data-action="click->toast#dismiss"><i class="fa-solid fa-xmark"></i></button>'; toast.innerHTML = html; if (autoDismiss) { toast.setAttribute('data-auto-dismiss', '0'); } container.appendChild(toast); } </script> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div data-controller="toast"><br> <div class="tw-toast-container"><br> <div class="tw-toast" data-toast-target="toast" role="status" aria-live="polite"><br> <i class="fa-solid fa-check tw-toast-icon"></i><br> <span class="tw-toast-message">Changes saved</span><br> <button type="button" class="tw-toast-close" data-action="click->toast#dismiss"><br> <i class="fa-solid fa-xmark"></i><br> </button><br> </div><br> </div><br> </div></code> </div> </div> <!-- Section 8: Accessibility Notes --> <div class="tw:border-t tw:pt-6"> <h2 class="tw-h4 tw:mb-4">Accessibility</h2> <div class="tw-callout"> <p class="tw:mb-2 tw:text-sm"> <strong>ARIA Attributes:</strong> </p> <ul class="tw:text-sm tw:mb-2 tw:space-y-1"> <li><code>role="status"</code> on toast element</li> <li><code>aria-live="polite"</code> announces to screen readers without interrupting</li> <li><code>aria-label="Dismiss"</code> on close button for icon-only context</li> </ul> <p class="tw:mb-2 tw:text-sm"> <strong>Keyboard Support:</strong> </p> <ul class="tw:text-sm tw:mb-2 tw:space-y-1"> <li><strong>Escape</strong> — Dismisses the most recent toast</li> <li>Close button is keyboard focusable via Tab</li> <li>Action button (if present) is keyboard focusable</li> </ul> <p class="tw:mb-0 tw:text-sm"> <strong>Motion:</strong> Animation respects <code>prefers-reduced-motion</code> — transitions disabled when user prefers reduced motion. </p> </div> </div></div>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
<div class="tw:p-6 tw:max-w-7xl tw:mx-auto tw:space-y-8"> <!-- Introductory callout --> <div class="tw-callout"> <p class="tw:mb-1 tw:text-sm tw:font-mono"> <strong>TOAST:</strong> Lightweight confirmation messages that appear after user actions<br> <strong>POSITIONING:</strong> Bottom-center, slides up from bottom edge<br> <strong>CLASSES:</strong> .tw-toast .tw-toast-container .tw-toast-visible .tw-toast-dismissing .tw-toast-success .tw-toast-error .tw-toast-warning .tw-toast-info .tw-toast-icon .tw-toast-message .tw-toast-action .tw-toast-close </p> <p class="tw:mb-0 tw:text-sm"> Toasts provide quick, non-blocking confirmations (e.g., "Copied!", "Saved!", "Undo available"). Auto-dismiss after 3 seconds (6s with action), pause-on-hover supported. Dark background with semantic color via icon only. </p> </div> <!-- Section 1: Basic Toast --> <div class="tw:border-t tw:pt-6"> <h2 class="tw-h4 tw:mb-4">Basic Toast</h2> <div class="tw-callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Minimal Structure:</strong> Icon + message in dark container. White text ensures readability. </p> </div> <div class="tw:relative tw:h-32 tw:bg-neutral-100 tw:rounded-lg tw:flex tw:items-end tw:justify-center tw:pb-4"> <div class="tw-toast tw-toast-visible"> <i class="fa-solid fa-check tw-toast-icon"></i> <span class="tw-toast-message">Changes saved successfully</span> </div> </div> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div class="tw-toast tw-toast-visible"><br> <i class="fa-solid fa-check tw-toast-icon"></i><br> <span class="tw-toast-message">Changes saved successfully</span><br> </div></code> </div> </div> <!-- Section 2: Semantic Variants --> <div class="tw:border-t tw:pt-6"> <h2 class="tw-h4 tw:mb-4">Semantic Variants</h2> <div class="tw-callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Icon Color Only:</strong> Dark background remains consistent. Add .tw-toast-success, .tw-toast-error, .tw-toast-warning, or .tw-toast-info to color the icon. </p> </div> <div class="tw:relative tw:bg-neutral-100 tw:rounded-lg tw:p-6 tw:space-y-3"> <div class="tw:flex tw:justify-center"> <div class="tw-toast tw-toast-success tw-toast-visible"> <i class="fa-solid fa-circle-check tw-toast-icon"></i> <span class="tw-toast-message">Application submitted successfully</span> </div> </div> <div class="tw:flex tw:justify-center"> <div class="tw-toast tw-toast-error tw-toast-visible"> <i class="fa-solid fa-circle-xmark tw-toast-icon"></i> <span class="tw-toast-message">Failed to save changes</span> </div> </div> <div class="tw:flex tw:justify-center"> <div class="tw-toast tw-toast-warning tw-toast-visible"> <i class="fa-solid fa-triangle-exclamation tw-toast-icon"></i> <span class="tw-toast-message">Connection unstable — changes may not save</span> </div> </div> <div class="tw:flex tw:justify-center"> <div class="tw-toast tw-toast-info tw-toast-visible"> <i class="fa-solid fa-circle-info tw-toast-icon"></i> <span class="tw-toast-message">New version available</span> </div> </div> </div> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div class="tw-toast tw-toast-success tw-toast-visible">...</div><br> <div class="tw-toast tw-toast-error tw-toast-visible">...</div><br> <div class="tw-toast tw-toast-warning tw-toast-visible">...</div><br> <div class="tw-toast tw-toast-info tw-toast-visible">...</div></code> </div> </div> <!-- Section 3: With Close Button --> <div class="tw:border-t tw:pt-6"> <h2 class="tw-h4 tw:mb-4">With Close Button</h2> <div class="tw-callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Manual Dismiss:</strong> Add .tw-toast-close button for user-controlled dismissal. Still auto-dismisses unless disabled. </p> </div> <div class="tw:relative tw:h-32 tw:bg-neutral-100 tw:rounded-lg tw:flex tw:items-end tw:justify-center tw:pb-4"> <div class="tw-toast tw-toast-visible"> <i class="fa-solid fa-check tw-toast-icon"></i> <span class="tw-toast-message">Email copied to clipboard</span> <button type="button" class="tw-toast-close" aria-label="Dismiss"> <i class="fa-solid fa-xmark"></i> </button> </div> </div> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div class="tw-toast tw-toast-visible"><br> <i class="fa-solid fa-check tw-toast-icon"></i><br> <span class="tw-toast-message">Email copied to clipboard</span><br> <button type="button" class="tw-toast-close" aria-label="Dismiss"><br> <i class="fa-solid fa-xmark"></i><br> </button><br> </div></code> </div> </div> <!-- Section 4: With Action Button --> <div class="tw:border-t tw:pt-6"> <h2 class="tw-h4 tw:mb-4">With Action Button</h2> <div class="tw-callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Actionable:</strong> Add .toast-action link/button for quick actions (e.g., "Undo", "View"). Auto-dismiss extends to 6 seconds when action is present. </p> </div> <div class="tw:relative tw:h-32 tw:bg-neutral-100 tw:rounded-lg tw:flex tw:items-end tw:justify-center tw:pb-4"> <div class="tw-toast tw-toast-visible"> <i class="fa-solid fa-trash tw-toast-icon"></i> <span class="tw-toast-message">3 items deleted</span> <button type="button" class="tw-toast-action">Undo</button> </div> </div> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div class="tw-toast tw-toast-visible"><br> <i class="fa-solid fa-trash tw-toast-icon"></i><br> <span class="tw-toast-message">3 items deleted</span><br> <button type="button" class="tw-toast-action">Undo</button><br> </div></code> </div> </div> <!-- Section 5: Without Close Button --> <div class="tw:border-t tw:pt-6"> <h2 class="tw-h4 tw:mb-4">Without Close Button</h2> <div class="tw-callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Auto-dismiss Only:</strong> Omit close button for brief confirmations that should disappear automatically. </p> </div> <div class="tw:relative tw:h-32 tw:bg-neutral-100 tw:rounded-lg tw:flex tw:items-end tw:justify-center tw:pb-4"> <div class="tw-toast tw-toast-success tw-toast-visible"> <i class="fa-solid fa-circle-check tw-toast-icon"></i> <span class="tw-toast-message">Link copied!</span> </div> </div> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div class="tw-toast tw-toast-success tw-toast-visible"><br> <i class="fa-solid fa-circle-check tw-toast-icon"></i><br> <span class="tw-toast-message">Link copied!</span><br> </div></code> </div> </div> <!-- Section 6: Stacked Toasts --> <div class="tw:border-t tw:pt-6"> <h2 class="tw-h4 tw:mb-4">Stacked Toasts</h2> <div class="tw-callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Multiple Toasts:</strong> Container uses flex-col-reverse so newer toasts appear above older ones. Each auto-dismisses independently. </p> </div> <div class="tw:relative tw:h-64 tw:bg-neutral-100 tw:rounded-lg tw:flex tw:items-end tw:justify-center tw:pb-4"> <div class="tw:flex tw:flex-col-reverse tw:gap-3 tw:items-center"> <div class="tw-toast tw-toast-visible"> <i class="fa-solid fa-check tw-toast-icon"></i> <span class="tw-toast-message">Profile updated</span> </div> <div class="tw-toast tw-toast-success tw-toast-visible"> <i class="fa-solid fa-circle-check tw-toast-icon"></i> <span class="tw-toast-message">Password changed successfully</span> </div> <div class="tw-toast tw-toast-info tw-toast-visible"> <i class="fa-solid fa-circle-info tw-toast-icon"></i> <span class="tw-toast-message">Security settings updated</span> <button type="button" class="tw-toast-close" aria-label="Dismiss"> <i class="fa-solid fa-xmark"></i> </button> </div> </div> </div> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div class="tw-toast-container"><br> <!-- Newer toasts appear above older ones --><br> <div class="tw-toast tw-toast-visible">...</div><br> <div class="tw-toast tw-toast-visible">...</div><br> <div class="tw-toast tw-toast-visible">...</div><br> </div></code> </div> </div> <!-- Section 7: Interactive Demo --> <div class="tw:border-t tw:pt-6"> <h2 class="tw-h4 tw:mb-4">Interactive Demo</h2> <div class="tw-callout tw:mb-4"> <p class="tw:mb-0 tw:text-sm"> <strong>Live Controller:</strong> Click buttons below to spawn toasts with Stimulus controller. Features auto-dismiss (3s default, 6s with action), pause-on-hover, manual dismiss via close button, and Escape key support. </p> </div> <!-- Toast container for interactive demo --> <div data-controller="toast" class="tw:relative tw:h-96 tw:bg-neutral-100 tw:rounded-lg"> <div class="tw-toast-container" class="tw:absolute"> <!-- Toasts will be appended here dynamically --> </div> <!-- Control buttons --> <div class="tw:absolute tw:top-6 tw:left-6 tw:right-6 tw:flex tw:flex-wrap tw:gap-3 tw:justify-center"> <button type="button" class="tw-btn tw-btn-sm tw-btn-primary" onclick="showToast('basic')"> Basic Toast </button> <button type="button" class="tw-btn tw-btn-sm tw-btn-success" onclick="showToast('success')"> Success Toast </button> <button type="button" class="tw-btn tw-btn-sm tw-btn-danger" onclick="showToast('error')"> Error Toast </button> <button type="button" class="tw-btn tw-btn-sm tw-btn-warning" onclick="showToast('warning')"> Warning Toast </button> <button type="button" class="tw-btn tw-btn-sm tw-btn-info" onclick="showToast('info')"> Info Toast </button> <button type="button" class="tw-btn tw-btn-sm tw-btn-outline-secondary" onclick="showToast('action')"> With Action </button> <button type="button" class="tw-btn tw-btn-sm tw-btn-outline-secondary" onclick="showToast('persistent')"> Persistent (No Auto-dismiss) </button> </div> <div class="tw:absolute tw:bottom-6 tw:left-6 tw:right-6 tw:text-center tw:text-sm text-muted"> <p class="tw:mb-1"> <strong>Interactions:</strong> Hover to pause auto-dismiss • Click X to close • Press Escape to dismiss topmost </p> <p class="tw:mb-0"> <strong>Duration:</strong> 3s default • 6s with action button • Disabled when data-auto-dismiss="0" </p> </div> </div> <script> function showToast(type) { const container = document.querySelector('[data-controller="toast"] .tw-toast-container'); const toast = document.createElement('div'); toast.className = 'tw-toast'; toast.setAttribute('data-toast-target', 'toast'); toast.setAttribute('role', 'status'); toast.setAttribute('aria-live', 'polite'); let icon = ''; let message = ''; let variant = ''; let hasAction = false; let autoDismiss = ''; switch(type) { case 'basic': icon = '<i class="fa-solid fa-check tw-toast-icon"></i>'; message = 'Changes saved successfully'; break; case 'success': icon = '<i class="fa-solid fa-circle-check tw-toast-icon"></i>'; message = 'Application submitted successfully'; variant = 'tw-toast-success'; break; case 'error': icon = '<i class="fa-solid fa-circle-xmark tw-toast-icon"></i>'; message = 'Failed to save changes'; variant = 'tw-toast-error'; break; case 'warning': icon = '<i class="fa-solid fa-triangle-exclamation tw-toast-icon"></i>'; message = 'Connection unstable — changes may not save'; variant = 'tw-toast-warning'; break; case 'info': icon = '<i class="fa-solid fa-circle-info tw-toast-icon"></i>'; message = 'New version available'; variant = 'tw-toast-info'; break; case 'action': icon = '<i class="fa-solid fa-trash tw-toast-icon"></i>'; message = '3 items deleted'; hasAction = true; break; case 'persistent': icon = '<i class="fa-solid fa-circle-info tw-toast-icon"></i>'; message = 'This toast will not auto-dismiss'; variant = 'tw-toast-info'; autoDismiss = ' data-auto-dismiss="0"'; break; } if (variant) { toast.className += ' ' + variant; } let html = icon + '<span class="tw-toast-message">' + message + '</span>'; if (hasAction) { html += '<button type="button" class="tw-toast-action" onclick="console.log(\'Action clicked\')">Undo</button>'; } html += '<button type="button" class="tw-toast-close" aria-label="Dismiss" data-action="click->toast#dismiss"><i class="fa-solid fa-xmark"></i></button>'; toast.innerHTML = html; if (autoDismiss) { toast.setAttribute('data-auto-dismiss', '0'); } container.appendChild(toast); } </script> <div class="tw:mt-4 tw:text-sm tw:text-gray-600"> <code><div data-controller="toast"><br> <div class="tw-toast-container"><br> <div class="tw-toast" data-toast-target="toast" role="status" aria-live="polite"><br> <i class="fa-solid fa-check tw-toast-icon"></i><br> <span class="tw-toast-message">Changes saved</span><br> <button type="button" class="tw-toast-close" data-action="click->toast#dismiss"><br> <i class="fa-solid fa-xmark"></i><br> </button><br> </div><br> </div><br> </div></code> </div> </div> <!-- Section 8: Accessibility Notes --> <div class="tw:border-t tw:pt-6"> <h2 class="tw-h4 tw:mb-4">Accessibility</h2> <div class="tw-callout"> <p class="tw:mb-2 tw:text-sm"> <strong>ARIA Attributes:</strong> </p> <ul class="tw:text-sm tw:mb-2 tw:space-y-1"> <li><code>role="status"</code> on toast element</li> <li><code>aria-live="polite"</code> announces to screen readers without interrupting</li> <li><code>aria-label="Dismiss"</code> on close button for icon-only context</li> </ul> <p class="tw:mb-2 tw:text-sm"> <strong>Keyboard Support:</strong> </p> <ul class="tw:text-sm tw:mb-2 tw:space-y-1"> <li><strong>Escape</strong> — Dismisses the most recent toast</li> <li>Close button is keyboard focusable via Tab</li> <li>Action button (if present) is keyboard focusable</li> </ul> <p class="tw:mb-0 tw:text-sm"> <strong>Motion:</strong> Animation respects <code>prefers-reduced-motion</code> — transitions disabled when user prefers reduced motion. </p> </div> </div></div>No notes provided.
No params configured.