Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/added-toast-countdown-pause.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Dashboard toasts: the countdown bar now drains right-to-left over the toast's real lifetime (`--toast-ttl`), pauses with the dismiss timer while the pointer or keyboard focus is on the toast and resumes on leave, uses the severity colour at 40% so it reads in dark and light mode, and stays visible under reduced motion.
2 changes: 2 additions & 0 deletions src/docs/dashboard-sections.md
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,8 @@ The toast reads, in order, *what happened → on what → what happens next*: a

It does **not** auto-dismiss: it stays until the tracker reports the target row in a new stage, caption or chip set (or gone), and up to five such toasts stack for pending decisions. A no-op says so plainly — *No change — hive already recorded this decision at 12:01Z; still blocked by needs-human* — and clears the acting state at once; an error toast says what failed and why (*Hold failed on acme/console#7 — write permission required*) and is sticky but not tied to a row.

Every *timed* toast elsewhere in the dashboard (success / info / warning notices, an error given an explicit deadline, an in-flight toast resolved into its result) carries a 2 px countdown bar along its bottom edge, in the toast's severity colour at 40%, that drains from right to left over the toast's real lifetime. Resting the pointer on the toast, or tabbing into it, holds both the bar and the dismiss timer where they are; leaving lets them run on for exactly what was left. Sticky toasts — errors, and the result toasts above — have no bar because they have no deadline. The bar is decorative to assistive tech (`aria-hidden`) and stays visible under reduced motion, since a countdown is information rather than flourish.

Older hives that answer without `result` still get a toast built from the legacy fields.

#### Confirmations and "Don't ask again"
Expand Down
25 changes: 14 additions & 11 deletions src/pkg/dashboard/static-src/css/alerts-toasts.css
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,21 @@
position: relative; overflow: hidden;
}
/* Countdown bar: a timed toast's remaining life, drained along the bottom
edge over exactly its auto-dismiss window (animation-duration is set
inline by toastCountdownBar from the same ms the dismiss timer uses).
Absolutely positioned so it never shifts the toast's layout; clipped
to the toast radius by the parent's overflow. Sticky/persistent
toasts carry no bar. */
.toast-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; pointer-events: none; transform-origin: left center; background: var(--muted); opacity: 0.55; animation: toast-bar-drain linear forwards; }
.toast.success .toast-bar { background: var(--green); }
.toast.error .toast-bar { background: var(--red); }
.toast.info .toast-bar { background: var(--blue); }
.toast.warning .toast-bar { background: var(--status-warn); }
edge from right to left (origin left, scaleX 1 -> 0) over --toast-ttl,
which toastCountdownBar sets on the toast from the same ms the dismiss
timer uses; hover or focus-within pauses both together (inline
animation-play-state). Absolutely positioned so it never shifts the
toast's layout; clipped to the toast radius by the parent's overflow.
Subtle: the severity token at 40% over transparent, no track. Sticky/
persistent toasts carry no bar. Reduced motion keeps it: a linear
countdown is information, not decoration. */
.toast-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; pointer-events: none; transform-origin: left center; background: color-mix(in srgb, currentColor 35%, transparent); animation: toast-bar-drain var(--toast-ttl, 3000ms) linear forwards; }
.toast.success .toast-bar { background: color-mix(in srgb, var(--green) 40%, transparent); }
.toast.error .toast-bar { background: color-mix(in srgb, var(--red) 40%, transparent); }
.toast.info .toast-bar { background: color-mix(in srgb, var(--blue) 40%, transparent); }
.toast.warning .toast-bar { background: color-mix(in srgb, var(--status-warn) 40%, transparent); }
@keyframes toast-bar-drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) { .toast-bar { display: none; } }
@media (prefers-reduced-motion: reduce) { .toast-bar { animation-timing-function: linear; } }
.toast.success { background: color-mix(in srgb, var(--green) 14%, var(--panel)); border-color: color-mix(in srgb, var(--green) 35%, var(--line)); border-left-color: var(--green); }
.toast.error { background: color-mix(in srgb, var(--red) 14%, var(--panel)); border-color: color-mix(in srgb, var(--red) 35%, var(--line)); border-left-color: var(--red); }
.toast.info { background: color-mix(in srgb, var(--blue) 14%, var(--panel)); border-color: color-mix(in srgb, var(--blue) 35%, var(--line)); border-left-color: var(--blue); }
Expand Down
64 changes: 56 additions & 8 deletions src/pkg/dashboard/static-src/js/tooltips-dialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -724,19 +724,66 @@
el.appendChild(close);
el.addEventListener('click', () => dismissToast(el, null, null, true));
}
// toastCountdownBar arms a toast's auto-dismiss: one setTimeout that
// closes it after `ms`, and a .toast-bar whose drain animation runs for
// the same `ms`, so the bar hits zero as the toast leaves. Every timed
// toast path (success/info/warning, error-with-deadline, in-flight toast
// resolved by dismissToast) goes through here; sticky and persistent
// toasts never call it and so show no bar.
// toastCountdownBar arms a toast's auto-dismiss: one timer that closes
// it after `ms`, and a .toast-bar whose drain animation runs for the
// same `ms` (published on the toast as --toast-ttl), so the bar hits
// zero as the toast leaves. Every timed toast path (success/info/
// warning, error-with-deadline, in-flight toast resolved by
// dismissToast) goes through here; sticky and persistent toasts never
// call it and so show no bar.
//
// Hover or keyboard focus inside the toast holds the countdown: the
// timer is cleared with its remaining milliseconds banked and the bar's
// animation is paused at the same instant, so the two never drift.
// Leaving re-arms the timer for exactly the banked remainder and lets
// the bar run on from where it stopped. Re-arming (dismissToast
// rewriting an in-flight toast) cancels any earlier countdown first.
function toastCountdownBar(el, ms, onExpire) {
toastCountdownCancel(el);
const bar = document.createElement('span');
bar.className = 'toast-bar';
bar.setAttribute('aria-hidden', 'true');
bar.style.animationDuration = ms + 'ms';
el.style.setProperty('--toast-ttl', ms + 'ms');
el.appendChild(bar);
setTimeout(() => { if (el.parentNode) onExpire(); }, ms);
const cd = { bar, remaining: ms, startedAt: 0, timer: 0, hovered: false, focused: false };
el._countdown = cd;
const fire = () => { cd.timer = 0; el._countdown = null; if (el.parentNode) onExpire(); };
cd.resume = () => {
if (cd.timer || cd.hovered || cd.focused || el._countdown !== cd) return;
cd.startedAt = Date.now();
cd.timer = setTimeout(fire, cd.remaining);
bar.style.animationPlayState = 'running';
};
cd.pause = () => {
if (!cd.timer) return;
clearTimeout(cd.timer);
cd.timer = 0;
cd.remaining = Math.max(0, cd.remaining - (Date.now() - cd.startedAt));
bar.style.animationPlayState = 'paused';
};
if (!el._countdownWired) {
el._countdownWired = true;
const c = () => el._countdown;
el.addEventListener('mouseenter', () => { const x = c(); if (x) { x.hovered = true; x.pause(); } });
el.addEventListener('mouseleave', () => { const x = c(); if (x) { x.hovered = false; x.resume(); } });
el.addEventListener('focusin', () => { const x = c(); if (x) { x.focused = true; x.pause(); } });
el.addEventListener('focusout', e => { const x = c(); if (x && !el.contains(e.relatedTarget)) { x.focused = false; x.resume(); } });
}
// A toast re-armed under the pointer stays held until it leaves.
if (el.matches(':hover')) cd.hovered = true;
if (el.contains(document.activeElement)) cd.focused = true;
cd.resume();
if (!cd.timer) bar.style.animationPlayState = 'paused';
}
// toastCountdownCancel drops a toast's pending countdown (timer and
// bar) so a rewrite or manual dismissal cannot fire a stale timer.
function toastCountdownCancel(el) {
const cd = el._countdown;
if (!cd) return;
if (cd.timer) clearTimeout(cd.timer);
cd.timer = 0;
if (cd.bar && cd.bar.parentNode) cd.bar.remove();
el._countdown = null;
}
function showToast(msg, type = 'info', persistent = false, autoDismissMs = 0) {
const opts = (persistent && typeof persistent === 'object') ? persistent : {};
Expand Down Expand Up @@ -795,6 +842,7 @@
// click/× path, so a sticky error can still be dismissed on demand.
function dismissToast(el, newMsg, newType, force) {
if (!el || !el.parentNode) return;
toastCountdownCancel(el);
if (newMsg) {
el.textContent = newMsg;
el.className = `toast ${newType || 'success'}`;
Expand Down
89 changes: 70 additions & 19 deletions src/pkg/dashboard/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3701,18 +3701,21 @@
position: relative; overflow: hidden;
}
/* Countdown bar: a timed toast's remaining life, drained along the bottom
edge over exactly its auto-dismiss window (animation-duration is set
inline by toastCountdownBar from the same ms the dismiss timer uses).
Absolutely positioned so it never shifts the toast's layout; clipped
to the toast radius by the parent's overflow. Sticky/persistent
toasts carry no bar. */
.toast-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; pointer-events: none; transform-origin: left center; background: var(--muted); opacity: 0.55; animation: toast-bar-drain linear forwards; }
.toast.success .toast-bar { background: var(--green); }
.toast.error .toast-bar { background: var(--red); }
.toast.info .toast-bar { background: var(--blue); }
.toast.warning .toast-bar { background: var(--status-warn); }
edge from right to left (origin left, scaleX 1 -> 0) over --toast-ttl,
which toastCountdownBar sets on the toast from the same ms the dismiss
timer uses; hover or focus-within pauses both together (inline
animation-play-state). Absolutely positioned so it never shifts the
toast's layout; clipped to the toast radius by the parent's overflow.
Subtle: the severity token at 40% over transparent, no track. Sticky/
persistent toasts carry no bar. Reduced motion keeps it: a linear
countdown is information, not decoration. */
.toast-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 2px; pointer-events: none; transform-origin: left center; background: color-mix(in srgb, currentColor 35%, transparent); animation: toast-bar-drain var(--toast-ttl, 3000ms) linear forwards; }
.toast.success .toast-bar { background: color-mix(in srgb, var(--green) 40%, transparent); }
.toast.error .toast-bar { background: color-mix(in srgb, var(--red) 40%, transparent); }
.toast.info .toast-bar { background: color-mix(in srgb, var(--blue) 40%, transparent); }
.toast.warning .toast-bar { background: color-mix(in srgb, var(--status-warn) 40%, transparent); }
@keyframes toast-bar-drain { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) { .toast-bar { display: none; } }
@media (prefers-reduced-motion: reduce) { .toast-bar { animation-timing-function: linear; } }
.toast.success { background: color-mix(in srgb, var(--green) 14%, var(--panel)); border-color: color-mix(in srgb, var(--green) 35%, var(--line)); border-left-color: var(--green); }
.toast.error { background: color-mix(in srgb, var(--red) 14%, var(--panel)); border-color: color-mix(in srgb, var(--red) 35%, var(--line)); border-left-color: var(--red); }
.toast.info { background: color-mix(in srgb, var(--blue) 14%, var(--panel)); border-color: color-mix(in srgb, var(--blue) 35%, var(--line)); border-left-color: var(--blue); }
Expand Down Expand Up @@ -42259,19 +42262,66 @@ <h4>GitHub Projects sync</h4>
el.appendChild(close);
el.addEventListener('click', () => dismissToast(el, null, null, true));
}
// toastCountdownBar arms a toast's auto-dismiss: one setTimeout that
// closes it after `ms`, and a .toast-bar whose drain animation runs for
// the same `ms`, so the bar hits zero as the toast leaves. Every timed
// toast path (success/info/warning, error-with-deadline, in-flight toast
// resolved by dismissToast) goes through here; sticky and persistent
// toasts never call it and so show no bar.
// toastCountdownBar arms a toast's auto-dismiss: one timer that closes
// it after `ms`, and a .toast-bar whose drain animation runs for the
// same `ms` (published on the toast as --toast-ttl), so the bar hits
// zero as the toast leaves. Every timed toast path (success/info/
// warning, error-with-deadline, in-flight toast resolved by
// dismissToast) goes through here; sticky and persistent toasts never
// call it and so show no bar.
//
// Hover or keyboard focus inside the toast holds the countdown: the
// timer is cleared with its remaining milliseconds banked and the bar's
// animation is paused at the same instant, so the two never drift.
// Leaving re-arms the timer for exactly the banked remainder and lets
// the bar run on from where it stopped. Re-arming (dismissToast
// rewriting an in-flight toast) cancels any earlier countdown first.
function toastCountdownBar(el, ms, onExpire) {
toastCountdownCancel(el);
const bar = document.createElement('span');
bar.className = 'toast-bar';
bar.setAttribute('aria-hidden', 'true');
bar.style.animationDuration = ms + 'ms';
el.style.setProperty('--toast-ttl', ms + 'ms');
el.appendChild(bar);
setTimeout(() => { if (el.parentNode) onExpire(); }, ms);
const cd = { bar, remaining: ms, startedAt: 0, timer: 0, hovered: false, focused: false };
el._countdown = cd;
const fire = () => { cd.timer = 0; el._countdown = null; if (el.parentNode) onExpire(); };
cd.resume = () => {
if (cd.timer || cd.hovered || cd.focused || el._countdown !== cd) return;
cd.startedAt = Date.now();
cd.timer = setTimeout(fire, cd.remaining);
bar.style.animationPlayState = 'running';
};
cd.pause = () => {
if (!cd.timer) return;
clearTimeout(cd.timer);
cd.timer = 0;
cd.remaining = Math.max(0, cd.remaining - (Date.now() - cd.startedAt));
bar.style.animationPlayState = 'paused';
};
if (!el._countdownWired) {
el._countdownWired = true;
const c = () => el._countdown;
el.addEventListener('mouseenter', () => { const x = c(); if (x) { x.hovered = true; x.pause(); } });
el.addEventListener('mouseleave', () => { const x = c(); if (x) { x.hovered = false; x.resume(); } });
el.addEventListener('focusin', () => { const x = c(); if (x) { x.focused = true; x.pause(); } });
el.addEventListener('focusout', e => { const x = c(); if (x && !el.contains(e.relatedTarget)) { x.focused = false; x.resume(); } });
}
// A toast re-armed under the pointer stays held until it leaves.
if (el.matches(':hover')) cd.hovered = true;
if (el.contains(document.activeElement)) cd.focused = true;
cd.resume();
if (!cd.timer) bar.style.animationPlayState = 'paused';
}
// toastCountdownCancel drops a toast's pending countdown (timer and
// bar) so a rewrite or manual dismissal cannot fire a stale timer.
function toastCountdownCancel(el) {
const cd = el._countdown;
if (!cd) return;
if (cd.timer) clearTimeout(cd.timer);
cd.timer = 0;
if (cd.bar && cd.bar.parentNode) cd.bar.remove();
el._countdown = null;
}
function showToast(msg, type = 'info', persistent = false, autoDismissMs = 0) {
const opts = (persistent && typeof persistent === 'object') ? persistent : {};
Expand Down Expand Up @@ -42330,6 +42380,7 @@ <h4>GitHub Projects sync</h4>
// click/× path, so a sticky error can still be dismissed on demand.
function dismissToast(el, newMsg, newType, force) {
if (!el || !el.parentNode) return;
toastCountdownCancel(el);
if (newMsg) {
el.textContent = newMsg;
el.className = `toast ${newType || 'success'}`;
Expand Down
Loading
Loading