-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
438 lines (369 loc) · 14.8 KB
/
Copy pathindex.html
File metadata and controls
438 lines (369 loc) · 14.8 KB
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<link
rel="icon"
href="data:image/svg+xml,%3Csvg width%3D%22512%22 height%3D%22512%22 viewBox%3D%220 0 512 512%22 fill%3D%22none%22 xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cstyle%3E path%7Bcolor%3Ablack%7D%40media (prefers-color-scheme%3Adark)%7Bpath%7Bcolor%3Awhite%7D%7D%3C%2Fstyle%3E%3Crect width%3D%22512%22 height%3D%22512%22 rx%3D%22120%22 fill%3D%22url(%23paint0_linear_2_2)%22 fill-opacity%3D%220.3%22%2F%3E%3Cpath d%3D%22M304.877 355.467C311.87 381.538 296.382 408.336 270.283 415.323C244.183 422.308 217.355 406.836 210.362 380.764M247.806 155.519C252.767 146.603 254.402 135.827 251.551 125.196C245.722 103.47 223.367 90.5763 201.617 96.3979C179.867 102.219 166.96 124.551 172.787 146.277C175.639 156.908 182.448 165.424 191.208 170.668M334.964 215.866C329.144 194.165 313.602 176.018 291.762 165.417C269.92 154.816 243.568 152.63 218.5 159.339C193.433 166.049 171.705 181.104 158.096 201.193C144.487 221.283 140.112 244.76 145.933 266.462C155.565 302.366 153.694 331.011 147.612 352.777C140.68 377.586 137.214 389.99 138.151 392.48C139.222 395.33 139.997 396.113 142.838 397.213C145.322 398.174 155.755 395.38 176.622 389.796L370.122 338.005C390.988 332.419 401.422 329.627 403.092 327.553C405.002 325.181 405.281 324.117 404.784 321.115C404.348 318.489 395.137 309.479 376.715 291.456C360.554 275.643 344.596 251.771 334.964 215.866Z%22 stroke%3D%22currentColor%22 stroke-width%3D%2233%22 stroke-linecap%3D%22round%22 stroke-linejoin%3D%22round%22%2F%3E%3Cdefs%3E%3ClinearGradient id%3D%22paint0_linear_2_2%22 x1%3D%22256%22 y1%3D%220%22 x2%3D%22256%22 y2%3D%22512%22 gradientUnits%3D%22userSpaceOnUse%22%3E%3Cstop stop-color%3D%22%23666666%22%2F%3E%3Cstop offset%3D%221%22%2F%3E%3C%2FlinearGradient%3E%3C%2Fdefs%3E%3C%2Fsvg%3E"
sizes="any"
>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>toast-queue</title>
<style>
body {
margin: unset;
min-height: 100dvh;
place-content: center;
justify-items: center;
}
* {
box-sizing: border-box;
}
main {
display: grid;
grid-column: auto;
gap: 1rem;
}
button {
touch-action: manipulation;
user-select: none;
-webkit-user-select: none;
}
[id="demo-modal-dialog"],
[id="demo-popover"] {
width: min(100% - 2rem, 32rem);
max-block-size: 85vh;
min-block-size: 50vh;
border-radius: 1rem;
}
/* toast-queue customization */
toast-queue {
--toast-color: Canvas;
width: 300px;
&:popover-open {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
}
toast-queue [data-part="group"] {
gap: 0.6rem;
}
toast-queue [data-part="item"]:is([data-dragging]) {
opacity: calc(1 - var(--tq-swipe-distance, 0));
}
toast-queue [data-part="toast"] {
color: hsl(from var(--toast-color) h s 15%);
border: 1px solid var(--toast-color);
background: hsl(from var(--toast-color) h s 90%);
box-shadow: 0 12px 12px -8px hsl(from var(--toast-color) h s l / 0.325);
border-radius: 1rem;
padding: 1rem;
gap: 0.5rem;
}
toast-queue [data-part="content"] {
align-items: flex-start;
flex: 1;
gap: 0.3rem;
}
toast-queue [data-part="actions"] {
align-self: center;
}
toast-queue [data-part="close-button"] {
display: flex;
align-items: center;
justify-content: center;
width: 2rem;
aspect-ratio: 1;
border-radius: 100%;
background-color: unset;
border: unset;
align-self: center;
font-size: 1.4rem;
&:hover {
background-color: var(--toast-color);
}
}
toast-queue [data-part="menu"] {
display: flex;
justify-content: flex-end;
margin: unset;
}
toast-queue:not([data-active]) [data-part="menu"] {
display: none;
}
[data-controls] {
display: grid;
gap: 0.5rem;
}
[data-controls] [data-row] {
display: grid;
grid-template-columns: 5rem 1fr 3rem;
gap: 0.5rem;
align-items: center;
}
[data-controls] output {
text-align: end;
font-variant-numeric: tabular-nums;
}
[data-actions] {
display: flex;
gap: 0.5rem;
flex-wrap: wrap;
}
</style>
</head>
<body>
<main>
<div data-controls>
<label>
Preset
<select id="toastPresetMenu" aria-label="Toast preset">
<option value="list">list</option>
<option value="stacked">stacked</option>
</select>
</label>
<label>
Position
<select id="toastPositionMenu" aria-label="Toast position">
<option value="top-start">top start</option>
<option value="top-center">top center</option>
<option value="top-end">top end</option>
<option value="bottom-start">bottom start</option>
<option value="bottom-center">bottom center</option>
<option value="bottom-end">bottom end</option>
</select>
</label>
<div data-row>
<label for="toastOffsetInline">inline</label>
<input id="toastOffsetInline" type="range" min="0" max="64" step="1" value="16">
<output id="toastOffsetInlineValue">16px</output>
</div>
<div data-row>
<label for="toastOffsetBlock">block</label>
<input id="toastOffsetBlock" type="range" min="0" max="64" step="1" value="16">
<output id="toastOffsetBlockValue">16px</output>
</div>
</div>
<div data-actions>
<button type="button" data-action="add-toast">Add toast</button>
<button type="button" data-action="add-burst">Add 5</button>
<button type="button" data-action="add-long">Long</button>
<button type="button" data-action="add-unbroken">Unbroken</button>
<button type="button" data-action="add-no-dismiss">No dismiss</button>
<button type="button" data-action="add-action">Action</button>
</div>
<div data-actions>
<button type="button" commandfor="demo-modal-dialog" command="show-modal">Modal dialog top layer change</button>
<button type="button" popovertarget="demo-popover">Popover top layer change</button>
</div>
<dialog id="demo-modal-dialog">
<h1>Modal dialog</h1>
<button type="button" data-action="add-toast">Add toast</button>
<button type="button" commandfor="demo-nested-dialog" command="show-modal">Open nested dialog</button>
<button type="button" commandfor="demo-modal-dialog" command="close">Close dialog</button>
<dialog id="demo-nested-dialog">
<h1>Nested dialog</h1>
<button type="button" data-action="add-toast">Add toast</button>
<button type="button" commandfor="demo-nested-dialog" command="close">Close dialog</button>
</dialog>
</dialog>
<div id="demo-popover" popover>
<h1>Popover</h1>
<button type="button" data-action="add-toast">Add toast</button>
<button type="button" popovertarget="demo-popover" popovertargetaction="hide">Hide popover</button>
</div>
</main>
<script type="module">
import { ToastQueue } from './src/index.js';
import listPreset from './src/presets/list.css?url';
import stackedPreset from './src/presets/stacked.css?url';
if (typeof HTMLElement.prototype.ariaNotify !== 'function') {
await import('https://cdn.jsdelivr.net/npm/@github/arianotify-polyfill');
}
if (!(typeof HTMLButtonElement !== 'undefined' && 'command' in HTMLButtonElement.prototype && 'source' in (globalThis.CommandEvent?.prototype || {}))) {
await import('https://cdn.jsdelivr.net/npm/invokers-polyfill@latest/+esm');
}
const presetUrls = {
list: listPreset,
stacked: stackedPreset,
};
const toastPreset = localStorage.getItem('tq-preset') || 'list';
const toastPosition = localStorage.getItem('tq-position') || 'top-end';
const toastOffsetInline = localStorage.getItem('tq-offset-inline') || '16';
const toastOffsetBlock = localStorage.getItem('tq-offset-block') || '16';
const toastPresetMenu = document.querySelector('#toastPresetMenu');
const toastPositionMenu = document.querySelector('#toastPositionMenu');
const toastOffsetInlineInput = document.querySelector('#toastOffsetInline');
const toastOffsetInlineValue = document.querySelector('#toastOffsetInlineValue');
const toastOffsetBlockInput = document.querySelector('#toastOffsetBlock');
const toastOffsetBlockValue = document.querySelector('#toastOffsetBlockValue');
const presetLink = document.createElement('link');
presetLink.rel = 'stylesheet';
presetLink.href = presetUrls[toastPreset];
document.head.appendChild(presetLink);
window.tq = new ToastQueue({
root: document.querySelector('main'),
position: toastPosition,
template: {
root: `<toast-queue>
<menu data-part="menu">
<button type="button" data-command="clear">Clear all</button>
</menu>
<ol data-part="group"></ol>
</toast-queue>`,
},
});
window.tq2 = new ToastQueue({
duration: 0,
position: 'top-start',
});
const toastQueue = tq.element;
toastQueue.addEventListener('toast-add', ({ detail }) => {
console.log('[toast-queue] add', { id: detail.toast.id });
});
toastQueue.addEventListener('toast-close', ({ detail }) => {
console.log('[toast-queue] close', {
id: detail.toast.id,
reason: detail.reason,
});
});
toastQueue.addEventListener('toast-action', ({ detail }) => {
console.log('[toast-queue] action', { id: detail.toast.id });
});
toastQueue.addEventListener('activate', ({ detail }) => {
console.log('[toast-queue] activate', detail.reason);
});
toastQueue.addEventListener('deactivate', ({ detail }) => {
console.log('[toast-queue] deactivate', detail.reason);
});
toastQueue.addEventListener('pause', () => {
console.log('[toast-queue] pause');
});
toastQueue.addEventListener('resume', () => {
console.log('[toast-queue] resume');
});
toastQueue.style.setProperty('--tq-offset-inline', `${toastOffsetInline}px`);
toastQueue.style.setProperty('--tq-offset-block', `${toastOffsetBlock}px`);
const setToastPosition = (value) => {
tq.position = value;
localStorage.setItem('tq-position', value);
};
const setToastPreset = (value) => {
presetLink.href = presetUrls[value];
localStorage.setItem('tq-preset', value);
};
const setToastOffset = (axis, value) => {
toastQueue.style.setProperty(`--tq-offset-${axis}`, `${value}px`);
localStorage.setItem(`tq-offset-${axis}`, value);
};
window.setToastPosition = setToastPosition;
window.setToastPreset = setToastPreset;
window.setToastOffset = setToastOffset;
toastPresetMenu.value = toastPreset;
toastPositionMenu.value = toastPosition;
toastOffsetInlineInput.value = toastOffsetInline;
toastOffsetBlockInput.value = toastOffsetBlock;
toastOffsetInlineValue.value = `${toastOffsetInline}px`;
toastOffsetBlockValue.value = `${toastOffsetBlock}px`;
toastPresetMenu.addEventListener('change', (event) => {
setToastPreset(event.target.value);
});
toastPositionMenu.addEventListener('change', (event) => {
const selectedValue = event.target.value;
setToastPosition(selectedValue);
});
toastOffsetInlineInput.addEventListener('input', (event) => {
const value = event.target.value;
toastOffsetInlineValue.value = `${value}px`;
setToastOffset('inline', value);
});
toastOffsetBlockInput.addEventListener('input', (event) => {
const value = event.target.value;
toastOffsetBlockValue.value = `${value}px`;
setToastOffset('block', value);
});
const addToast = (content, options = {}) => {
tq.add(content, {
...options,
});
};
document.addEventListener('click', (event) => {
const action = event.target.closest('[data-action]')?.dataset.action;
if (!action) return;
if (action === 'add-toast') {
addToast(
{
title: 'Title',
description: Date.now(),
},
{
icon: 'ℹ️',
className: 'my-toast',
action: {
label: 'Action',
onClick: (toast) => {
console.log(toast);
tq.close(toast.id);
},
},
},
);
return;
}
if (action === 'add-burst') {
for (let index = 1; index <= 5; index++) {
addToast({
title: `Toast ${index}`,
description: Date.now(),
});
}
return;
}
if (action === 'add-long') {
addToast({
title: 'A deliberately long toast title that should wrap',
description: 'This description is intentionally long so we can test wrapping, queue sizing, animation and how the toast behaves when there is substantially more content than usual.',
});
return;
}
if (action === 'add-unbroken') {
addToast({
title: 'Unbroken content',
description: 'https://example.com/really-long-path/with-a-very-long-unbroken-string-that-should-not-break-the-queue-layout',
});
return;
}
if (action === 'add-no-dismiss') {
addToast(
{
title: 'Persistent toast',
description: 'This toast cannot be dismissed by swipe or close.',
},
{
dismissible: false,
},
);
return;
}
if (action === 'add-action') {
addToast(
{
title: 'Action toast',
description: 'Test focus, keyboard and action handling.',
},
{
icon: '⚡',
action: {
label: 'Run',
onClick: (toast) => {
console.log('Action clicked', toast);
},
},
},
);
}
});
</script>
</body>
</html>