@f-ewald/components 1.33.1 → 1.35.0

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.
@@ -26,6 +26,15 @@ interface ToastOptions {
26
26
  * auto-dismisses after `duration` ms and can also be dismissed via its ✕
27
27
  * button. Appears/disappears instantly — no slide/fade transitions.
28
28
  *
29
+ * A toast with `duration > 0` replaces its ✕ button with a countdown: a
30
+ * number of seconds remaining inside a ring that fills in clockwise over
31
+ * `duration`. Hovering or keyboard-focusing the toast swaps the countdown
32
+ * back for the ✕ and pauses the countdown (both the visual ring/number and
33
+ * the underlying auto-dismiss timer) — the toast won't disappear while
34
+ * someone's reading it or has tabbed to its close button — resuming from
35
+ * where it left off once the pointer/focus leaves. A `duration: 0` toast has
36
+ * no countdown to show, so its ✕ is always visible, exactly as before.
37
+ *
29
38
  * Each variant's background reads a dedicated `--ui-toast-*-background` hook
30
39
  * (`success`/`error`/`info`/`warning`), which defaults to the flat
31
40
  * `--ui-success`/`--ui-danger`/`--ui-info`/`--ui-warning` tokens unchanged —
@@ -46,6 +55,10 @@ export declare class ToastNotification extends LitElement {
46
55
  private _toasts;
47
56
  private _nextId;
48
57
  private _timers;
58
+ /** Per-toast hover/focus tracking, so leaving one doesn't resume while the other still applies. */
59
+ private _interaction;
60
+ /** Ticks while any toast has a running countdown, purely to refresh the displayed seconds. */
61
+ private _tickTimer;
49
62
  static styles: import("lit").CSSResult[];
50
63
  /**
51
64
  * Queues a toast for display.
@@ -60,6 +73,23 @@ export declare class ToastNotification extends LitElement {
60
73
  */
61
74
  dismiss(id: number): void;
62
75
  disconnectedCallback(): void;
76
+ /** Schedules (or reschedules) the real auto-dismiss timeout for a toast. */
77
+ private _scheduleTimer;
78
+ /** Freezes a toast's countdown at its current remaining time. */
79
+ private _pause;
80
+ /** Resumes a paused toast's countdown for whatever time was remaining. */
81
+ private _resume;
82
+ /** Starts or stops the shared display-only tick, matching whether any countdown is actually running. */
83
+ private _syncTicking;
84
+ /** Reads (creating if absent) a toast's hover/focus tracking record. */
85
+ private _interactionState;
86
+ private _onMouseEnter;
87
+ private _onMouseLeave;
88
+ private _onFocusIn;
89
+ /** Rechecks focus-within on a microtask, since focusout fires before the new focus target settles. */
90
+ private _onFocusOut;
91
+ /** Whole seconds remaining until auto-dismiss, for the countdown number. */
92
+ private _secondsLeft;
63
93
  /**
64
94
  * Returns the decorative status icon for a variant, sized as a standalone
65
95
  * 18px glyph to match the dismiss button.
@@ -1 +1 @@
1
- {"version":3,"file":"toast-notification.d.ts","sourceRoot":"","sources":["../src/toast-notification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,OAAO,EAAE,MAAM,KAAK,CAAC;AAWrD,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,CAAC;AAEpE,UAAU,YAAY;IACpB,uEAAuE;IACvE,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,oFAAoF;IACpF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAWD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBACa,iBAAkB,SAAQ,UAAU;IACtC,OAAO,CAAC,OAAO,CAAe;IAEvC,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,OAAO,CAAoD;IAEnE,OAAgB,MAAM,4BA0HpB;IAEF;;;;;OAKG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,MAAM,CAYxD;IAED;;;OAGG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,QAOjB;IAEQ,oBAAoB,SAI5B;IAED;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAaX,MAAM,0DAsBd;CACF;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,oBAAoB,EAAE,iBAAiB,CAAC;KACzC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AM,QASjB;IAEQ,oBAAoB,SAM5B;IAED,4EAA4E;IAC5E,OAAO,CAAC,cAAc;IAOtB,iEAAiE;IACjE,OAAO,CAAC,MAAM;IAiBd,0EAA0E;IAC1E,OAAO,CAAC,OAAO;IAYf,wGAAwG;IACxG,OAAO,CAAC,YAAY;IAUpB,wEAAwE;IACxE,OAAO,CAAC,iBAAiB;IASzB,OAAO,CAAC,aAAa;IAKrB,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,UAAU;IAKlB,sGAAsG;IACtG,OAAO,CAAC,WAAW;IASnB,4EAA4E;IAC5E,OAAO,CAAC,YAAY;IAKpB;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAaX,MAAM,0DAuCd;CACF;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,oBAAoB,EAAE,iBAAiB,CAAC;KACzC;CACF;AAMD,wFAAwF;AACxF,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,QAEhE;AAED,6BAA6B;AAC7B,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,QAElE;AAED,2BAA2B;AAC3B,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,QAE/D;AAED,6BAA6B;AAC7B,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,QAElE"}
@@ -9,6 +9,9 @@ import { customElement, state } from "lit/decorators.js";
9
9
  import { iconCheckCircle, iconExclamationCircle, iconExclamationTriangle, iconInfo, iconX, } from "./icons.js";
10
10
  import { tokens } from "./tokens.js";
11
11
  const DEFAULT_DURATION_MS = 5000;
12
+ /** Radius of the countdown ring's SVG circle — used to derive its circumference. */
13
+ const RING_RADIUS = 9;
14
+ const RING_CIRCUMFERENCE = 2 * Math.PI * RING_RADIUS;
12
15
  /**
13
16
  * Fixed-position stack of dismissible notifications, anchored top-right
14
17
  * (top-full-width on mobile). Every toast shares one fixed width so entries
@@ -24,6 +27,15 @@ const DEFAULT_DURATION_MS = 5000;
24
27
  * auto-dismisses after `duration` ms and can also be dismissed via its ✕
25
28
  * button. Appears/disappears instantly — no slide/fade transitions.
26
29
  *
30
+ * A toast with `duration > 0` replaces its ✕ button with a countdown: a
31
+ * number of seconds remaining inside a ring that fills in clockwise over
32
+ * `duration`. Hovering or keyboard-focusing the toast swaps the countdown
33
+ * back for the ✕ and pauses the countdown (both the visual ring/number and
34
+ * the underlying auto-dismiss timer) — the toast won't disappear while
35
+ * someone's reading it or has tabbed to its close button — resuming from
36
+ * where it left off once the pointer/focus leaves. A `duration: 0` toast has
37
+ * no countdown to show, so its ✕ is always visible, exactly as before.
38
+ *
27
39
  * Each variant's background reads a dedicated `--ui-toast-*-background` hook
28
40
  * (`success`/`error`/`info`/`warning`), which defaults to the flat
29
41
  * `--ui-success`/`--ui-danger`/`--ui-info`/`--ui-warning` tokens unchanged —
@@ -46,6 +58,10 @@ let ToastNotification = class ToastNotification extends LitElement {
46
58
  this._toasts = [];
47
59
  this._nextId = 0;
48
60
  this._timers = new Map();
61
+ /** Per-toast hover/focus tracking, so leaving one doesn't resume while the other still applies. */
62
+ this._interaction = new Map();
63
+ /** Ticks while any toast has a running countdown, purely to refresh the displayed seconds. */
64
+ this._tickTimer = null;
49
65
  }
50
66
  static { this.styles = [
51
67
  tokens,
@@ -123,23 +139,97 @@ let ToastNotification = class ToastNotification extends LitElement {
123
139
  line-height: var(--ui-line-height-normal, 1.5);
124
140
  word-break: break-word;
125
141
  }
126
- .close {
142
+ /* .countdown and .close are stacked exactly on top of one another (both
143
+ inset:0 inside this fixed-size box) rather than swapped via
144
+ display:none, so toggling between them never shifts layout. */
145
+ .actions {
146
+ position: relative;
127
147
  flex: 0 0 auto;
148
+ width: 2rem;
149
+ height: 2rem;
150
+ margin: -0.25rem -0.25rem -0.25rem 0;
151
+ }
152
+ .countdown {
153
+ position: absolute;
154
+ inset: 0;
128
155
  display: inline-flex;
129
156
  align-items: center;
130
157
  justify-content: center;
158
+ pointer-events: none;
159
+ }
160
+ .ring {
161
+ position: absolute;
162
+ inset: 0;
163
+ width: 100%;
164
+ height: 100%;
165
+ }
166
+ .ring-track {
167
+ fill: none;
168
+ stroke: currentColor;
169
+ stroke-width: 2;
170
+ opacity: 0.3;
171
+ }
172
+ .ring-progress {
173
+ fill: none;
174
+ stroke: currentColor;
175
+ stroke-width: 2;
176
+ stroke-linecap: round;
177
+ transform-origin: 50% 50%;
178
+ transform: rotate(-90deg);
179
+ stroke-dasharray: ${RING_CIRCUMFERENCE};
180
+ stroke-dashoffset: ${RING_CIRCUMFERENCE};
181
+ animation-name: toast-ring-fill;
182
+ animation-duration: var(--toast-duration, 5000ms);
183
+ animation-timing-function: linear;
184
+ animation-fill-mode: forwards;
185
+ }
186
+ .toast.has-countdown:hover .ring-progress,
187
+ .toast.has-countdown:focus-within .ring-progress {
188
+ animation-play-state: paused;
189
+ }
190
+ @keyframes toast-ring-fill {
191
+ to {
192
+ stroke-dashoffset: 0;
193
+ }
194
+ }
195
+ .countdown-number {
196
+ position: relative;
197
+ font-size: var(--ui-font-size-xs, 0.6875rem);
198
+ font-weight: var(--ui-font-weight-semibold, 600);
199
+ font-variant-numeric: tabular-nums;
200
+ line-height: var(--ui-line-height-glyph, 1);
201
+ }
202
+ .close {
203
+ position: absolute;
204
+ inset: 0;
131
205
  width: 2rem;
132
206
  height: 2rem;
207
+ display: inline-flex;
208
+ align-items: center;
209
+ justify-content: center;
133
210
  background: none;
134
211
  border: none;
135
212
  padding: 0;
136
- margin: -0.25rem -0.25rem -0.25rem 0;
137
213
  color: inherit;
138
214
  opacity: 0.8;
139
215
  cursor: pointer;
140
216
  line-height: var(--ui-line-height-glyph, 1);
141
217
  border-radius: var(--ui-radius-sm, 0.25rem);
142
218
  }
219
+ /* Only hide the ✕ behind the countdown when there IS a countdown — a
220
+ duration:0 toast has no .countdown sibling and keeps the ✕ always
221
+ visible, unchanged from before this feature existed. */
222
+ .toast.has-countdown .close {
223
+ opacity: 0;
224
+ }
225
+ .toast.has-countdown:hover .close,
226
+ .toast.has-countdown:focus-within .close {
227
+ opacity: 1;
228
+ }
229
+ .toast.has-countdown:hover .countdown,
230
+ .toast.has-countdown:focus-within .countdown {
231
+ visibility: hidden;
232
+ }
143
233
  .close:hover {
144
234
  opacity: 1;
145
235
  background: var(--ui-hover-overlay, rgb(255 255 255 / 0.32));
@@ -149,6 +239,11 @@ let ToastNotification = class ToastNotification extends LitElement {
149
239
  opacity: 1;
150
240
  box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));
151
241
  }
242
+ @media (prefers-reduced-motion: reduce) {
243
+ .ring-progress {
244
+ animation: none;
245
+ }
246
+ }
152
247
  @media (forced-colors: active) {
153
248
  .toast {
154
249
  border: 1px solid CanvasText;
@@ -180,10 +275,20 @@ let ToastNotification = class ToastNotification extends LitElement {
180
275
  const id = this._nextId++;
181
276
  const variant = options.variant ?? "info";
182
277
  const duration = options.duration ?? DEFAULT_DURATION_MS;
183
- this._toasts = [...this._toasts, { id, message, variant, description: options.description }];
184
- if (duration > 0) {
185
- this._timers.set(id, setTimeout(() => this.dismiss(id), duration));
186
- }
278
+ const toast = {
279
+ id,
280
+ message,
281
+ variant,
282
+ description: options.description,
283
+ duration,
284
+ endTime: duration > 0 ? Date.now() + duration : 0,
285
+ remaining: duration,
286
+ paused: false,
287
+ };
288
+ this._toasts = [...this._toasts, toast];
289
+ if (duration > 0)
290
+ this._scheduleTimer(id, duration);
291
+ this._syncTicking();
187
292
  return id;
188
293
  }
189
294
  /**
@@ -196,13 +301,104 @@ let ToastNotification = class ToastNotification extends LitElement {
196
301
  clearTimeout(timer);
197
302
  this._timers.delete(id);
198
303
  }
304
+ this._interaction.delete(id);
199
305
  this._toasts = this._toasts.filter((t) => t.id !== id);
306
+ this._syncTicking();
200
307
  }
201
308
  disconnectedCallback() {
202
309
  super.disconnectedCallback();
203
310
  for (const timer of this._timers.values())
204
311
  clearTimeout(timer);
205
312
  this._timers.clear();
313
+ if (this._tickTimer)
314
+ clearInterval(this._tickTimer);
315
+ this._tickTimer = null;
316
+ }
317
+ /** Schedules (or reschedules) the real auto-dismiss timeout for a toast. */
318
+ _scheduleTimer(id, ms) {
319
+ this._timers.set(id, setTimeout(() => this.dismiss(id), ms));
320
+ }
321
+ /** Freezes a toast's countdown at its current remaining time. */
322
+ _pause(id) {
323
+ const index = this._toasts.findIndex((t) => t.id === id);
324
+ if (index === -1)
325
+ return;
326
+ const toast = this._toasts[index];
327
+ if (toast.duration === 0 || toast.paused)
328
+ return;
329
+ const timer = this._timers.get(id);
330
+ if (timer) {
331
+ clearTimeout(timer);
332
+ this._timers.delete(id);
333
+ }
334
+ const remaining = Math.max(0, toast.endTime - Date.now());
335
+ const next = [...this._toasts];
336
+ next[index] = { ...toast, paused: true, remaining };
337
+ this._toasts = next;
338
+ this._syncTicking();
339
+ }
340
+ /** Resumes a paused toast's countdown for whatever time was remaining. */
341
+ _resume(id) {
342
+ const index = this._toasts.findIndex((t) => t.id === id);
343
+ if (index === -1)
344
+ return;
345
+ const toast = this._toasts[index];
346
+ if (toast.duration === 0 || !toast.paused)
347
+ return;
348
+ this._scheduleTimer(id, toast.remaining);
349
+ const next = [...this._toasts];
350
+ next[index] = { ...toast, paused: false, endTime: Date.now() + toast.remaining };
351
+ this._toasts = next;
352
+ this._syncTicking();
353
+ }
354
+ /** Starts or stops the shared display-only tick, matching whether any countdown is actually running. */
355
+ _syncTicking() {
356
+ const needsTicking = this._toasts.some((t) => t.duration > 0 && !t.paused);
357
+ if (needsTicking && !this._tickTimer) {
358
+ this._tickTimer = setInterval(() => this.requestUpdate(), 250);
359
+ }
360
+ else if (!needsTicking && this._tickTimer) {
361
+ clearInterval(this._tickTimer);
362
+ this._tickTimer = null;
363
+ }
364
+ }
365
+ /** Reads (creating if absent) a toast's hover/focus tracking record. */
366
+ _interactionState(id) {
367
+ let state = this._interaction.get(id);
368
+ if (!state) {
369
+ state = { hovered: false, focusWithin: false };
370
+ this._interaction.set(id, state);
371
+ }
372
+ return state;
373
+ }
374
+ _onMouseEnter(id) {
375
+ this._interactionState(id).hovered = true;
376
+ this._pause(id);
377
+ }
378
+ _onMouseLeave(id) {
379
+ const state = this._interactionState(id);
380
+ state.hovered = false;
381
+ if (!state.focusWithin)
382
+ this._resume(id);
383
+ }
384
+ _onFocusIn(id) {
385
+ this._interactionState(id).focusWithin = true;
386
+ this._pause(id);
387
+ }
388
+ /** Rechecks focus-within on a microtask, since focusout fires before the new focus target settles. */
389
+ _onFocusOut(id, event) {
390
+ const el = event.currentTarget;
391
+ queueMicrotask(() => {
392
+ const state = this._interactionState(id);
393
+ state.focusWithin = el.matches(":focus-within");
394
+ if (!state.hovered && !state.focusWithin)
395
+ this._resume(id);
396
+ });
397
+ }
398
+ /** Whole seconds remaining until auto-dismiss, for the countdown number. */
399
+ _secondsLeft(t) {
400
+ const ms = t.paused ? t.remaining : Math.max(0, t.endTime - Date.now());
401
+ return Math.max(0, Math.ceil(ms / 1000));
206
402
  }
207
403
  /**
208
404
  * Returns the decorative status icon for a variant, sized as a standalone
@@ -227,18 +423,35 @@ let ToastNotification = class ToastNotification extends LitElement {
227
423
  return html `
228
424
  ${this._toasts.map((t) => html `
229
425
  <div
230
- class="toast ${t.variant}"
426
+ class="toast ${t.variant} ${t.duration > 0 ? "has-countdown" : ""}"
231
427
  role=${t.variant === "error" ? "alert" : "status"}
232
428
  aria-atomic="true"
429
+ @mouseenter=${() => this._onMouseEnter(t.id)}
430
+ @mouseleave=${() => this._onMouseLeave(t.id)}
431
+ @focusin=${() => this._onFocusIn(t.id)}
432
+ @focusout=${(e) => this._onFocusOut(t.id, e)}
233
433
  >
234
434
  <span class="icon" aria-hidden="true">${this._variantIcon(t.variant)}</span>
235
435
  <div class="content">
236
436
  <span class="message">${t.message}</span>
237
437
  ${t.description ? html `<span class="description">${t.description}</span>` : nothing}
238
438
  </div>
239
- <button class="close" aria-label="Dismiss notification" @click=${() => this.dismiss(t.id)}>
240
- <span aria-hidden="true">${iconX(18)}</span>
241
- </button>
439
+ <div class="actions">
440
+ ${t.duration > 0
441
+ ? html `
442
+ <div class="countdown" aria-hidden="true" style="--toast-duration: ${t.duration}ms">
443
+ <svg class="ring" viewBox="0 0 24 24">
444
+ <circle class="ring-track" cx="12" cy="12" r=${RING_RADIUS}></circle>
445
+ <circle class="ring-progress" cx="12" cy="12" r=${RING_RADIUS}></circle>
446
+ </svg>
447
+ <span class="countdown-number">${this._secondsLeft(t)}</span>
448
+ </div>
449
+ `
450
+ : nothing}
451
+ <button class="close" aria-label="Dismiss notification" @click=${() => this.dismiss(t.id)}>
452
+ <span aria-hidden="true">${iconX(18)}</span>
453
+ </button>
454
+ </div>
242
455
  </div>
243
456
  `)}
244
457
  `;
@@ -1 +1 @@
1
- {"version":3,"file":"toast-notification.js","sourceRoot":"","sources":["../src/toast-notification.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,QAAQ,EACR,KAAK,GACN,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAuBrC,MAAM,mBAAmB,GAAG,IAAI,CAAC;AAEjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEI,IAAM,iBAAiB,GAAvB,MAAM,iBAAkB,SAAQ,UAAU;IAA1C;;QACY,YAAO,GAAY,EAAE,CAAC;QAE/B,YAAO,GAAG,CAAC,CAAC;QACZ,YAAO,GAAG,IAAI,GAAG,EAAyC,CAAC;IA8MrE,CAAC;aA5MiB,WAAM,GAAG;QACvB,MAAM;QACN,G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KAAK,EAAE;kDAA+B;AAD5B,iBAAiB;IAD7B,aAAa,CAAC,oBAAoB,CAAC;GACvB,iBAAiB,CAkN7B;;AAQD,SAAS,QAAQ;IACf,OAAO,QAAQ,CAAC,aAAa,CAAC,oBAAoB,CAAC,CAAC;AACtD,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,WAAW,CAAC,OAAe,EAAE,WAAoB;IAC/D,QAAQ,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;AAC/D,CAAC;AAED,6BAA6B;AAC7B,MAAM,UAAU,aAAa,CAAC,OAAe,EAAE,WAAoB;IACjE,QAAQ,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;AACjE,CAAC;AAED,2BAA2B;AAC3B,MAAM,UAAU,UAAU,CAAC,OAAe,EAAE,WAAoB;IAC9D,QAAQ,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED,6BAA6B;AAC7B,MAAM,UAAU,aAAa,CAAC,OAAe,EAAE,WAAoB;IACjE,QAAQ,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { LitElement, css, html, nothing } from \"lit\";\nimport { customElement, state } from \"lit/decorators.js\";\nimport {\n iconCheckCircle,\n iconExclamationCircle,\n iconExclamationTriangle,\n iconInfo,\n iconX,\n} from \"./icons.js\";\nimport { tokens } from \"./tokens.js\";\n\nexport type ToastVariant = \"error\" | \"info\" | \"success\" | \"warning\";\n\ninterface ToastOptions {\n /** Visual style; also selects the accent color. Defaults to \"info\". */\n variant?: ToastVariant;\n /** Auto-dismiss delay in ms. Pass 0 to require a manual close. Defaults to 5000. */\n duration?: number;\n /**\n * Optional secondary line shown beneath the headline in smaller, non-bold\n * type. Omit for a single-line toast.\n */\n description?: string;\n}\n\ninterface Toast {\n id: number;\n message: string;\n variant: ToastVariant;\n description?: string;\n}\n\nconst DEFAULT_DURATION_MS = 5000;\n\n/**\n * Fixed-position stack of dismissible notifications, anchored top-right\n * (top-full-width on mobile). Every toast shares one fixed width so entries\n * never appear narrower or wider than one another. Not wired to any app state\n * yet — callers add toasts imperatively via the `show()` method on a live\n * element reference,\n * e.g. `document.querySelector('toast-notification')?.show('Offline', { variant: 'error' })`,\n * or via the `notifySuccess`/`notifyError`/`notifyInfo` module-level helpers\n * exported from this file. The first argument is the required bold headline; an\n * optional `description` renders a smaller, non-bold second line. Each variant\n * leads with a matching status icon (success → check, error → exclamation\n * circle, info → information circle, warning → exclamation triangle). Each toast\n * auto-dismisses after `duration` ms and can also be dismissed via its ✕\n * button. Appears/disappears instantly — no slide/fade transitions.\n *\n * Each variant's background reads a dedicated `--ui-toast-*-background` hook\n * (`success`/`error`/`info`/`warning`), which defaults to the flat\n * `--ui-success`/`--ui-danger`/`--ui-info`/`--ui-warning` tokens unchanged —\n * so those stay the single source of truth for every other component. A\n * consumer can override just these toast-specific tokens with a\n * `linear-gradient(...)` to opt every toast into a gradient look without\n * touching component markup — `gradientTokenValues` in `tokens.ts` ships\n * exactly this, wired up via `data-theme=\"gradient\"` (see `tokens.css`'s\n * \"Gradient theme\" section), the same mechanism `ui-button` uses.\n * `--ui-toast-highlight` (a glossy top-edge box-shadow, layered onto the\n * existing elevation shadow) and `--ui-toast-text-shadow` (legibility\n * against the gradient's lighter stop) round out the effect, mirroring\n * `ui-button`'s `--ui-button-highlight`/`--ui-button-text-shadow`.\n *\n * @element toast-notification\n */\n@customElement(\"toast-notification\")\nexport class ToastNotification extends LitElement {\n @state() private _toasts: Toast[] = [];\n\n private _nextId = 0;\n private _timers = new Map<number, ReturnType<typeof setTimeout>>();\n\n static override styles = [\n tokens,\n css`\n :host {\n position: fixed;\n top: 1rem;\n right: 1rem;\n z-index: 200;\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n width: 22.5rem;\n pointer-events: none;\n }\n .toast {\n pointer-events: auto;\n display: flex;\n align-items: flex-start;\n gap: 0.5rem;\n border-radius: var(--ui-radius, 0.5rem);\n padding: 0.75rem;\n box-shadow: var(\n --ui-shadow-lg,\n 0 20px 25px -5px rgb(0 0 0 / 0.1),\n 0 8px 10px -6px rgb(0 0 0 / 0.1)\n ), var(--ui-toast-highlight, 0 0 0 0 transparent);\n font-family: var(\n --ui-font,\n ui-sans-serif,\n system-ui,\n sans-serif,\n \"Apple Color Emoji\",\n \"Segoe UI Emoji\",\n \"Segoe UI Symbol\",\n \"Noto Color Emoji\"\n );\n font-size: var(--ui-font-size, 0.875rem);\n line-height: var(--ui-line-height-normal, 1.5);\n color: var(--ui-on-accent, #ffffff);\n background: var(--ui-text, #0f172a);\n text-shadow: var(--ui-toast-text-shadow, none);\n }\n .toast.error {\n background: var(--ui-toast-error-background, var(--ui-danger, #dc2626));\n }\n .toast.success {\n background: var(--ui-toast-success-background, var(--ui-success, #16a34a));\n }\n .toast.info {\n background: var(--ui-toast-info-background, var(--ui-info, #0ea5e9));\n }\n .toast.warning {\n background: var(--ui-toast-warning-background, var(--ui-warning, #d97706));\n }\n .icon {\n flex: 0 0 auto;\n margin-top: 0.125rem;\n line-height: var(--ui-line-height-glyph, 1);\n }\n .content {\n flex: 1 1 auto;\n min-width: 0;\n display: flex;\n flex-direction: column;\n gap: 0.25rem;\n }\n .message {\n font-weight: var(--ui-font-weight-semibold, 600);\n word-break: break-word;\n }\n .description {\n font-size: var(--ui-font-size-sm, 0.75rem);\n font-weight: var(--ui-font-weight-regular, 400);\n line-height: var(--ui-line-height-normal, 1.5);\n word-break: break-word;\n }\n .close {\n flex: 0 0 auto;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 2rem;\n height: 2rem;\n background: none;\n border: none;\n padding: 0;\n margin: -0.25rem -0.25rem -0.25rem 0;\n color: inherit;\n opacity: 0.8;\n cursor: pointer;\n line-height: var(--ui-line-height-glyph, 1);\n border-radius: var(--ui-radius-sm, 0.25rem);\n }\n .close:hover {\n opacity: 1;\n background: var(--ui-hover-overlay, rgb(255 255 255 / 0.32));\n }\n .close:focus-visible {\n outline: none;\n opacity: 1;\n box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));\n }\n @media (forced-colors: active) {\n .toast {\n border: 1px solid CanvasText;\n forced-color-adjust: auto;\n }\n .close:focus-visible {\n outline: 2px solid CanvasText;\n outline-offset: 2px;\n box-shadow: none;\n }\n }\n @media (max-width: 48rem) {\n :host {\n top: 0.75rem;\n right: 0.75rem;\n left: 0.75rem;\n width: auto;\n }\n }\n `,\n ];\n\n /**\n * Queues a toast for display.\n * @param message Text to show.\n * @param options Variant + auto-dismiss duration (see {@link ToastOptions}).\n * @returns The toast's id — pass to `dismiss()` to remove it early.\n */\n show(message: string, options: ToastOptions = {}): number {\n const id = this._nextId++;\n const variant = options.variant ?? \"info\";\n const duration = options.duration ?? DEFAULT_DURATION_MS;\n this._toasts = [...this._toasts, { id, message, variant, description: options.description }];\n if (duration > 0) {\n this._timers.set(\n id,\n setTimeout(() => this.dismiss(id), duration),\n );\n }\n return id;\n }\n\n /**\n * Removes a toast immediately, cancelling its pending auto-dismiss timer if any.\n * @param id The id returned by `show()`.\n */\n dismiss(id: number) {\n const timer = this._timers.get(id);\n if (timer) {\n clearTimeout(timer);\n this._timers.delete(id);\n }\n this._toasts = this._toasts.filter((t) => t.id !== id);\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback();\n for (const timer of this._timers.values()) clearTimeout(timer);\n this._timers.clear();\n }\n\n /**\n * Returns the decorative status icon for a variant, sized as a standalone\n * 18px glyph to match the dismiss button.\n * @param variant The toast variant.\n */\n private _variantIcon(variant: ToastVariant) {\n switch (variant) {\n case \"success\":\n return iconCheckCircle(18);\n case \"error\":\n return iconExclamationCircle(18);\n case \"warning\":\n return iconExclamationTriangle(18);\n default:\n return iconInfo(18);\n }\n }\n\n override render() {\n if (this._toasts.length === 0) return nothing;\n return html`\n ${this._toasts.map(\n (t) => html`\n <div\n class=\"toast ${t.variant}\"\n role=${t.variant === \"error\" ? \"alert\" : \"status\"}\n aria-atomic=\"true\"\n >\n <span class=\"icon\" aria-hidden=\"true\">${this._variantIcon(t.variant)}</span>\n <div class=\"content\">\n <span class=\"message\">${t.message}</span>\n ${t.description ? html`<span class=\"description\">${t.description}</span>` : nothing}\n </div>\n <button class=\"close\" aria-label=\"Dismiss notification\" @click=${() => this.dismiss(t.id)}>\n <span aria-hidden=\"true\">${iconX(18)}</span>\n </button>\n </div>\n `,\n )}\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"toast-notification\": ToastNotification;\n }\n}\n\nfunction getToast(): ToastNotification | null {\n return document.querySelector(\"toast-notification\");\n}\n\n/** Shows an error toast. Use for connection/network failures, not validation errors. */\nexport function notifyError(message: string, description?: string) {\n getToast()?.show(message, { variant: \"error\", description });\n}\n\n/** Shows a success toast. */\nexport function notifySuccess(message: string, description?: string) {\n getToast()?.show(message, { variant: \"success\", description });\n}\n\n/** Shows an info toast. */\nexport function notifyInfo(message: string, description?: string) {\n getToast()?.show(message, { variant: \"info\", description });\n}\n\n/** Shows a warning toast. */\nexport function notifyWarning(message: string, description?: string) {\n getToast()?.show(message, { variant: \"warning\", description });\n}\n"]}
1
+ {"version":3,"file":"toast-notification.js","sourceRoot":"","sources":["../src/toast-notification.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,QAAQ,EACR,KAAK,GACN,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,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AAE,CAAC,CAAC;AAC/D,CAAC;AAED,6BAA6B;AAC7B,MAAM,UAAU,aAAa,CAAC,OAAe,EAAE,WAAoB;IACjE,QAAQ,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;AACjE,CAAC;AAED,2BAA2B;AAC3B,MAAM,UAAU,UAAU,CAAC,OAAe,EAAE,WAAoB;IAC9D,QAAQ,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED,6BAA6B;AAC7B,MAAM,UAAU,aAAa,CAAC,OAAe,EAAE,WAAoB;IACjE,QAAQ,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { LitElement, css, html, nothing } from \"lit\";\nimport { customElement, state } from \"lit/decorators.js\";\nimport {\n iconCheckCircle,\n iconExclamationCircle,\n iconExclamationTriangle,\n iconInfo,\n iconX,\n} from \"./icons.js\";\nimport { tokens } from \"./tokens.js\";\n\nexport type ToastVariant = \"error\" | \"info\" | \"success\" | \"warning\";\n\ninterface ToastOptions {\n /** Visual style; also selects the accent color. Defaults to \"info\". */\n variant?: ToastVariant;\n /** Auto-dismiss delay in ms. Pass 0 to require a manual close. Defaults to 5000. */\n duration?: number;\n /**\n * Optional secondary line shown beneath the headline in smaller, non-bold\n * type. Omit for a single-line toast.\n */\n description?: string;\n}\n\ninterface Toast {\n id: number;\n message: string;\n variant: ToastVariant;\n description?: string;\n /** Configured auto-dismiss delay in ms; 0 means manual dismiss only (no countdown). */\n duration: number;\n /** Timestamp (`Date.now()`-based) this toast will auto-dismiss at, while the countdown is running. */\n endTime: number;\n /** Milliseconds remaining, frozen at the instant hover/focus paused the countdown. */\n remaining: number;\n /** Whether hover or focus has paused the countdown. */\n paused: boolean;\n}\n\nconst DEFAULT_DURATION_MS = 5000;\n/** Radius of the countdown ring's SVG circle — used to derive its circumference. */\nconst RING_RADIUS = 9;\nconst RING_CIRCUMFERENCE = 2 * Math.PI * RING_RADIUS;\n\n/**\n * Fixed-position stack of dismissible notifications, anchored top-right\n * (top-full-width on mobile). Every toast shares one fixed width so entries\n * never appear narrower or wider than one another. Not wired to any app state\n * yet — callers add toasts imperatively via the `show()` method on a live\n * element reference,\n * e.g. `document.querySelector('toast-notification')?.show('Offline', { variant: 'error' })`,\n * or via the `notifySuccess`/`notifyError`/`notifyInfo` module-level helpers\n * exported from this file. The first argument is the required bold headline; an\n * optional `description` renders a smaller, non-bold second line. Each variant\n * leads with a matching status icon (success → check, error → exclamation\n * circle, info → information circle, warning → exclamation triangle). Each toast\n * auto-dismisses after `duration` ms and can also be dismissed via its ✕\n * button. Appears/disappears instantly — no slide/fade transitions.\n *\n * A toast with `duration > 0` replaces its ✕ button with a countdown: a\n * number of seconds remaining inside a ring that fills in clockwise over\n * `duration`. Hovering or keyboard-focusing the toast swaps the countdown\n * back for the ✕ and pauses the countdown (both the visual ring/number and\n * the underlying auto-dismiss timer) — the toast won't disappear while\n * someone's reading it or has tabbed to its close button — resuming from\n * where it left off once the pointer/focus leaves. A `duration: 0` toast has\n * no countdown to show, so its ✕ is always visible, exactly as before.\n *\n * Each variant's background reads a dedicated `--ui-toast-*-background` hook\n * (`success`/`error`/`info`/`warning`), which defaults to the flat\n * `--ui-success`/`--ui-danger`/`--ui-info`/`--ui-warning` tokens unchanged —\n * so those stay the single source of truth for every other component. A\n * consumer can override just these toast-specific tokens with a\n * `linear-gradient(...)` to opt every toast into a gradient look without\n * touching component markup — `gradientTokenValues` in `tokens.ts` ships\n * exactly this, wired up via `data-theme=\"gradient\"` (see `tokens.css`'s\n * \"Gradient theme\" section), the same mechanism `ui-button` uses.\n * `--ui-toast-highlight` (a glossy top-edge box-shadow, layered onto the\n * existing elevation shadow) and `--ui-toast-text-shadow` (legibility\n * against the gradient's lighter stop) round out the effect, mirroring\n * `ui-button`'s `--ui-button-highlight`/`--ui-button-text-shadow`.\n *\n * @element toast-notification\n */\n@customElement(\"toast-notification\")\nexport class ToastNotification extends LitElement {\n @state() private _toasts: Toast[] = [];\n\n private _nextId = 0;\n private _timers = new Map<number, ReturnType<typeof setTimeout>>();\n /** Per-toast hover/focus tracking, so leaving one doesn't resume while the other still applies. */\n private _interaction = new Map<number, { hovered: boolean; focusWithin: boolean }>();\n /** Ticks while any toast has a running countdown, purely to refresh the displayed seconds. */\n private _tickTimer: ReturnType<typeof setInterval> | null = null;\n\n static override styles = [\n tokens,\n css`\n :host {\n position: fixed;\n top: 1rem;\n right: 1rem;\n z-index: 200;\n display: flex;\n flex-direction: column;\n gap: 0.5rem;\n width: 22.5rem;\n pointer-events: none;\n }\n .toast {\n pointer-events: auto;\n display: flex;\n align-items: flex-start;\n gap: 0.5rem;\n border-radius: var(--ui-radius, 0.5rem);\n padding: 0.75rem;\n box-shadow: var(\n --ui-shadow-lg,\n 0 20px 25px -5px rgb(0 0 0 / 0.1),\n 0 8px 10px -6px rgb(0 0 0 / 0.1)\n ), var(--ui-toast-highlight, 0 0 0 0 transparent);\n font-family: var(\n --ui-font,\n ui-sans-serif,\n system-ui,\n sans-serif,\n \"Apple Color Emoji\",\n \"Segoe UI Emoji\",\n \"Segoe UI Symbol\",\n \"Noto Color Emoji\"\n );\n font-size: var(--ui-font-size, 0.875rem);\n line-height: var(--ui-line-height-normal, 1.5);\n color: var(--ui-on-accent, #ffffff);\n background: var(--ui-text, #0f172a);\n text-shadow: var(--ui-toast-text-shadow, none);\n }\n .toast.error {\n background: var(--ui-toast-error-background, var(--ui-danger, #dc2626));\n }\n .toast.success {\n background: var(--ui-toast-success-background, var(--ui-success, #16a34a));\n }\n .toast.info {\n background: var(--ui-toast-info-background, var(--ui-info, #0ea5e9));\n }\n .toast.warning {\n background: var(--ui-toast-warning-background, var(--ui-warning, #d97706));\n }\n .icon {\n flex: 0 0 auto;\n margin-top: 0.125rem;\n line-height: var(--ui-line-height-glyph, 1);\n }\n .content {\n flex: 1 1 auto;\n min-width: 0;\n display: flex;\n flex-direction: column;\n gap: 0.25rem;\n }\n .message {\n font-weight: var(--ui-font-weight-semibold, 600);\n word-break: break-word;\n }\n .description {\n font-size: var(--ui-font-size-sm, 0.75rem);\n font-weight: var(--ui-font-weight-regular, 400);\n line-height: var(--ui-line-height-normal, 1.5);\n word-break: break-word;\n }\n /* .countdown and .close are stacked exactly on top of one another (both\n inset:0 inside this fixed-size box) rather than swapped via\n display:none, so toggling between them never shifts layout. */\n .actions {\n position: relative;\n flex: 0 0 auto;\n width: 2rem;\n height: 2rem;\n margin: -0.25rem -0.25rem -0.25rem 0;\n }\n .countdown {\n position: absolute;\n inset: 0;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n pointer-events: none;\n }\n .ring {\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n }\n .ring-track {\n fill: none;\n stroke: currentColor;\n stroke-width: 2;\n opacity: 0.3;\n }\n .ring-progress {\n fill: none;\n stroke: currentColor;\n stroke-width: 2;\n stroke-linecap: round;\n transform-origin: 50% 50%;\n transform: rotate(-90deg);\n stroke-dasharray: ${RING_CIRCUMFERENCE};\n stroke-dashoffset: ${RING_CIRCUMFERENCE};\n animation-name: toast-ring-fill;\n animation-duration: var(--toast-duration, 5000ms);\n animation-timing-function: linear;\n animation-fill-mode: forwards;\n }\n .toast.has-countdown:hover .ring-progress,\n .toast.has-countdown:focus-within .ring-progress {\n animation-play-state: paused;\n }\n @keyframes toast-ring-fill {\n to {\n stroke-dashoffset: 0;\n }\n }\n .countdown-number {\n position: relative;\n font-size: var(--ui-font-size-xs, 0.6875rem);\n font-weight: var(--ui-font-weight-semibold, 600);\n font-variant-numeric: tabular-nums;\n line-height: var(--ui-line-height-glyph, 1);\n }\n .close {\n position: absolute;\n inset: 0;\n width: 2rem;\n height: 2rem;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n background: none;\n border: none;\n padding: 0;\n color: inherit;\n opacity: 0.8;\n cursor: pointer;\n line-height: var(--ui-line-height-glyph, 1);\n border-radius: var(--ui-radius-sm, 0.25rem);\n }\n /* Only hide the ✕ behind the countdown when there IS a countdown — a\n duration:0 toast has no .countdown sibling and keeps the ✕ always\n visible, unchanged from before this feature existed. */\n .toast.has-countdown .close {\n opacity: 0;\n }\n .toast.has-countdown:hover .close,\n .toast.has-countdown:focus-within .close {\n opacity: 1;\n }\n .toast.has-countdown:hover .countdown,\n .toast.has-countdown:focus-within .countdown {\n visibility: hidden;\n }\n .close:hover {\n opacity: 1;\n background: var(--ui-hover-overlay, rgb(255 255 255 / 0.32));\n }\n .close:focus-visible {\n outline: none;\n opacity: 1;\n box-shadow: var(--ui-focus-ring, 0 0 0 3px rgb(79 70 229 / 0.35));\n }\n @media (prefers-reduced-motion: reduce) {\n .ring-progress {\n animation: none;\n }\n }\n @media (forced-colors: active) {\n .toast {\n border: 1px solid CanvasText;\n forced-color-adjust: auto;\n }\n .close:focus-visible {\n outline: 2px solid CanvasText;\n outline-offset: 2px;\n box-shadow: none;\n }\n }\n @media (max-width: 48rem) {\n :host {\n top: 0.75rem;\n right: 0.75rem;\n left: 0.75rem;\n width: auto;\n }\n }\n `,\n ];\n\n /**\n * Queues a toast for display.\n * @param message Text to show.\n * @param options Variant + auto-dismiss duration (see {@link ToastOptions}).\n * @returns The toast's id — pass to `dismiss()` to remove it early.\n */\n show(message: string, options: ToastOptions = {}): number {\n const id = this._nextId++;\n const variant = options.variant ?? \"info\";\n const duration = options.duration ?? DEFAULT_DURATION_MS;\n const toast: Toast = {\n id,\n message,\n variant,\n description: options.description,\n duration,\n endTime: duration > 0 ? Date.now() + duration : 0,\n remaining: duration,\n paused: false,\n };\n this._toasts = [...this._toasts, toast];\n if (duration > 0) this._scheduleTimer(id, duration);\n this._syncTicking();\n return id;\n }\n\n /**\n * Removes a toast immediately, cancelling its pending auto-dismiss timer if any.\n * @param id The id returned by `show()`.\n */\n dismiss(id: number) {\n const timer = this._timers.get(id);\n if (timer) {\n clearTimeout(timer);\n this._timers.delete(id);\n }\n this._interaction.delete(id);\n this._toasts = this._toasts.filter((t) => t.id !== id);\n this._syncTicking();\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback();\n for (const timer of this._timers.values()) clearTimeout(timer);\n this._timers.clear();\n if (this._tickTimer) clearInterval(this._tickTimer);\n this._tickTimer = null;\n }\n\n /** Schedules (or reschedules) the real auto-dismiss timeout for a toast. */\n private _scheduleTimer(id: number, ms: number): void {\n this._timers.set(\n id,\n setTimeout(() => this.dismiss(id), ms),\n );\n }\n\n /** Freezes a toast's countdown at its current remaining time. */\n private _pause(id: number): void {\n const index = this._toasts.findIndex((t) => t.id === id);\n if (index === -1) return;\n const toast = this._toasts[index];\n if (toast.duration === 0 || toast.paused) return;\n const timer = this._timers.get(id);\n if (timer) {\n clearTimeout(timer);\n this._timers.delete(id);\n }\n const remaining = Math.max(0, toast.endTime - Date.now());\n const next = [...this._toasts];\n next[index] = { ...toast, paused: true, remaining };\n this._toasts = next;\n this._syncTicking();\n }\n\n /** Resumes a paused toast's countdown for whatever time was remaining. */\n private _resume(id: number): void {\n const index = this._toasts.findIndex((t) => t.id === id);\n if (index === -1) return;\n const toast = this._toasts[index];\n if (toast.duration === 0 || !toast.paused) return;\n this._scheduleTimer(id, toast.remaining);\n const next = [...this._toasts];\n next[index] = { ...toast, paused: false, endTime: Date.now() + toast.remaining };\n this._toasts = next;\n this._syncTicking();\n }\n\n /** Starts or stops the shared display-only tick, matching whether any countdown is actually running. */\n private _syncTicking(): void {\n const needsTicking = this._toasts.some((t) => t.duration > 0 && !t.paused);\n if (needsTicking && !this._tickTimer) {\n this._tickTimer = setInterval(() => this.requestUpdate(), 250);\n } else if (!needsTicking && this._tickTimer) {\n clearInterval(this._tickTimer);\n this._tickTimer = null;\n }\n }\n\n /** Reads (creating if absent) a toast's hover/focus tracking record. */\n private _interactionState(id: number): { hovered: boolean; focusWithin: boolean } {\n let state = this._interaction.get(id);\n if (!state) {\n state = { hovered: false, focusWithin: false };\n this._interaction.set(id, state);\n }\n return state;\n }\n\n private _onMouseEnter(id: number): void {\n this._interactionState(id).hovered = true;\n this._pause(id);\n }\n\n private _onMouseLeave(id: number): void {\n const state = this._interactionState(id);\n state.hovered = false;\n if (!state.focusWithin) this._resume(id);\n }\n\n private _onFocusIn(id: number): void {\n this._interactionState(id).focusWithin = true;\n this._pause(id);\n }\n\n /** Rechecks focus-within on a microtask, since focusout fires before the new focus target settles. */\n private _onFocusOut(id: number, event: FocusEvent): void {\n const el = event.currentTarget as HTMLElement;\n queueMicrotask(() => {\n const state = this._interactionState(id);\n state.focusWithin = el.matches(\":focus-within\");\n if (!state.hovered && !state.focusWithin) this._resume(id);\n });\n }\n\n /** Whole seconds remaining until auto-dismiss, for the countdown number. */\n private _secondsLeft(t: Toast): number {\n const ms = t.paused ? t.remaining : Math.max(0, t.endTime - Date.now());\n return Math.max(0, Math.ceil(ms / 1000));\n }\n\n /**\n * Returns the decorative status icon for a variant, sized as a standalone\n * 18px glyph to match the dismiss button.\n * @param variant The toast variant.\n */\n private _variantIcon(variant: ToastVariant) {\n switch (variant) {\n case \"success\":\n return iconCheckCircle(18);\n case \"error\":\n return iconExclamationCircle(18);\n case \"warning\":\n return iconExclamationTriangle(18);\n default:\n return iconInfo(18);\n }\n }\n\n override render() {\n if (this._toasts.length === 0) return nothing;\n return html`\n ${this._toasts.map(\n (t) => html`\n <div\n class=\"toast ${t.variant} ${t.duration > 0 ? \"has-countdown\" : \"\"}\"\n role=${t.variant === \"error\" ? \"alert\" : \"status\"}\n aria-atomic=\"true\"\n @mouseenter=${() => this._onMouseEnter(t.id)}\n @mouseleave=${() => this._onMouseLeave(t.id)}\n @focusin=${() => this._onFocusIn(t.id)}\n @focusout=${(e: FocusEvent) => this._onFocusOut(t.id, e)}\n >\n <span class=\"icon\" aria-hidden=\"true\">${this._variantIcon(t.variant)}</span>\n <div class=\"content\">\n <span class=\"message\">${t.message}</span>\n ${t.description ? html`<span class=\"description\">${t.description}</span>` : nothing}\n </div>\n <div class=\"actions\">\n ${t.duration > 0\n ? html`\n <div class=\"countdown\" aria-hidden=\"true\" style=\"--toast-duration: ${t.duration}ms\">\n <svg class=\"ring\" viewBox=\"0 0 24 24\">\n <circle class=\"ring-track\" cx=\"12\" cy=\"12\" r=${RING_RADIUS}></circle>\n <circle class=\"ring-progress\" cx=\"12\" cy=\"12\" r=${RING_RADIUS}></circle>\n </svg>\n <span class=\"countdown-number\">${this._secondsLeft(t)}</span>\n </div>\n `\n : nothing}\n <button class=\"close\" aria-label=\"Dismiss notification\" @click=${() => this.dismiss(t.id)}>\n <span aria-hidden=\"true\">${iconX(18)}</span>\n </button>\n </div>\n </div>\n `,\n )}\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n \"toast-notification\": ToastNotification;\n }\n}\n\nfunction getToast(): ToastNotification | null {\n return document.querySelector(\"toast-notification\");\n}\n\n/** Shows an error toast. Use for connection/network failures, not validation errors. */\nexport function notifyError(message: string, description?: string) {\n getToast()?.show(message, { variant: \"error\", description });\n}\n\n/** Shows a success toast. */\nexport function notifySuccess(message: string, description?: string) {\n getToast()?.show(message, { variant: \"success\", description });\n}\n\n/** Shows an info toast. */\nexport function notifyInfo(message: string, description?: string) {\n getToast()?.show(message, { variant: \"info\", description });\n}\n\n/** Shows a warning toast. */\nexport function notifyWarning(message: string, description?: string) {\n getToast()?.show(message, { variant: \"warning\", description });\n}\n"]}
package/docs/app-shell.md CHANGED
@@ -1,25 +1,46 @@
1
1
  # `<app-shell>`
2
2
 
3
3
  The dashboard page shell: a slot-based CSS-grid backbone that arranges a
4
- full-height sidebar, a top bar, the main content, an optional right-hand
5
- detail column, and an optional footer. It owns the responsive behavior so
6
- consumers don't re-implement it — above the shared 48rem breakpoint the
7
- sidebar collapses to an icon rail and the detail region is an inline column;
8
- at or below it the sidebar becomes an off-canvas drawer and the detail region
9
- an overlay, both dismissed by a scrim or Escape.
4
+ top bar, the main content, an optional right-hand detail column, an
5
+ optional footer, and a sidebar. The top bar always spans the shell's full
6
+ width, in every sidebar state.
7
+
8
+ The sidebar's visibility, width, and layout mode are three independent
9
+ properties:
10
+ - `sidebar-open` (default closed) — whether it's shown at all.
11
+ - `sidebar-width`: `"full"` (16rem, icons + labels, the default) or
12
+ `"icon"` (3.5rem rail, icons only — drives the slotted `app-sidebar`'s
13
+ own `collapsed` attribute).
14
+ - `sidebar-mode`: `"overlay"` (the default) floats the sidebar above the
15
+ shell's own content with a higher z-index, covering part of the top
16
+ bar's corner and whatever content sits beneath it, without ever
17
+ resizing or reflowing `main`/`footer`. `"push"` instead reserves a real
18
+ grid column beside `main`/`footer` (which resize to make room) — the
19
+ top bar still spans full width above it either way.
20
+
21
+ Below the shared 48rem breakpoint the sidebar always behaves as a
22
+ full-width, modal, scrim/Escape-dismissible drawer regardless of
23
+ `sidebar-mode`/`sidebar-width` — those two properties only affect the
24
+ desktop presentation. Above 48rem, an `overlay`-mode sidebar is a
25
+ non-modal panel (no dimming scrim, no Escape-dismiss, since it reads as
26
+ an ordinary always-interactive panel rather than a blocking dialog); a
27
+ `push`-mode sidebar is even more clearly non-modal, since it never
28
+ covers anything.
29
+
30
+ The right-hand detail column is unaffected by any of the above: it still
31
+ reserves an inline grid column on desktop and becomes a dismissible
32
+ overlay (scrim/Escape) on mobile.
10
33
 
11
34
  Widths are tunable per instance via `--component-sidebar-width` (16rem),
12
35
  `--component-sidebar-rail-width` (3.5rem), and `--component-topbar-height`
13
36
  (3rem); the detail column reuses the 20rem/25rem panel widths. The main
14
37
  content area is white by default — override it with
15
- `--component-main-background`. Give the shell a height (e.g. `height: 100vh`)
16
- so the sidebar and main can size and scroll.
38
+ `--component-main-background`. Give the shell a height (e.g. `height:
39
+ 100vh`) so the sidebar and main can size and scroll.
17
40
 
18
- The built-in top-bar button toggles the sidebar, and so does pressing `[`
19
- anywhere on the page (ignored while typing in a text field or with a
20
- modifier held). Hovering or keyboard-focusing the toggle reveals a tooltip
21
- naming the action and its `[` shortcut — the shortcut is not shown as
22
- permanent chrome.
41
+ Hovering or keyboard-focusing the toggle reveals a tooltip naming the
42
+ action and its `[` shortcut — the shortcut is not shown as permanent
43
+ chrome.
23
44
 
24
45
  ## Install
25
46
 
@@ -51,7 +72,9 @@ import "@f-ewald/components/app-shell.js";
51
72
 
52
73
  | Property | Attribute | Type | Default | Description |
53
74
  | --- | --- | --- | --- | --- |
54
- | `sidebarCollapsed` | `sidebar-collapsed` | `boolean` | `false` | Collapses the sidebar to an icon rail on desktop. |
75
+ | `sidebarOpen` | `sidebar-open` | `boolean` | `false` | Whether the sidebar is open. Closed by default at every breakpoint. |
76
+ | `sidebarMode` | `sidebar-mode` | `"overlay" | "push"` | `"overlay"` | `"overlay"` (default) floats the sidebar above content; `"push"` reserves a grid column instead. |
77
+ | `sidebarWidth` | `sidebar-width` | `"full" | "icon"` | `"full"` | Sidebar width when open: `"full"` (16rem, icons + labels) or `"icon"` (3.5rem rail, icons only). |
55
78
  | `detailOpen` | `detail-open` | `boolean` | `false` | Shows the right-hand detail region (inline column, or overlay on mobile). |
56
79
  | `detailWidth` | `detail-width` | `"compact" | "comfortable"` | `"compact"` | Detail width: `compact` (20rem) or `comfortable` (25rem). |
57
80
 
@@ -7,9 +7,10 @@ label), optional `<p>` group headings, and marks the active item with
7
7
  `aria-current="page"`. The sidebar styles them, tracks hover/active/focus,
8
8
  and — in collapsed "rail" mode — centers the icons and hides the labels.
9
9
 
10
- Rail mode is driven by the `collapsed` attribute (the parent `app-shell`
11
- toggles it). Labels are hidden by the inherited `--app-sidebar-label` custom
12
- property, so each label element should read it, e.g.
10
+ Rail mode is driven by the `collapsed` attribute, which callers set
11
+ directly — `app-shell` no longer auto-manages it (its own sidebar is a
12
+ pure overlay, not a rail). Labels are hidden by the inherited
13
+ `--app-sidebar-label` custom property, so each label element should read it, e.g.
13
14
  `<span style="display: var(--app-sidebar-label, inline)">Reports</span>`;
14
15
  keep an `aria-label` on the item so its accessible name survives collapse.
15
16
  The sidebar fills the width and height of its container — `app-shell` owns