createTimeoutLoop
{count()}
{delay() === false ? "paused" : `${delay()}ms`}
{([250, 500, 1000, 2000] as const).map(ms => (
))}
Change the delay mid-tick — it takes effect on the next execution, not the
current one.
);
},
});
export const PausableTimer = meta.story({
name: "Pausable toast",
parameters: {
docs: {
description: {
story:
"`createPausableTimer` keeps the remaining time across pause/resume. Hover or focus the toast to pause it; leaving resumes with what was left, not the full delay.",
},
},
},
render: () => {
const [dismissed, setDismissed] = createSignal(0);
const [now, setNow] = createSignal(0);
const timer = createPausableTimer(() => setDismissed(d => d + 1), 5000, {
pauseWhenHidden: true,
});
const id = setInterval(() => setNow(n => n + 1), 100);
onCleanup(() => clearInterval(id));
return (