useCountdown

Snackbar
stable

Internal countdown timer used by OrigamSnackbar to drive the auto-dismiss progress indicator. Counts down from a given millisecond value using setInterval, ticking at the CSS transition duration of the host element so the progress bar remains visually synchronised. Exposes clear / reset / start controls and a reactive time ref.

API

Signature

Full TypeScript signature sourced from the composable file.

typescript

useCountdown is an internal primitive used by OrigamSnackbar. For pushing notifications from application code, use useSnackbarGroup instead. The interval is cleared via onScopeDispose so it never leaks after the component unmounts.

API

Parameters

Input parameters accepted by this composable.

milliseconds
required
number
Total countdown duration in milliseconds. This is the initial value of time and the value it resets to on reset().

API

Return values

Properties and methods exposed by the composable return object.

time
Remaining milliseconds. Starts at the initial milliseconds value, decrements on each tick, and bottoms out at 0. Bind to a progress bar width to visualise the countdown.
clear
Stops the interval without resetting time. Use to pause the countdown (e.g. while the user is hovering the snackbar).
reset
Clears the interval and resets time to the initial milliseconds value on the next tick. Use when the snackbar content changes and the countdown should restart.
start
Start (or resume) the countdown. Reads the CSS transitionDuration of el to synchronise tick frequency with the progress bar animation. Falls back to 200 ms when no element is provided or no transition is set. Clears any existing interval before starting.

Usage

Examples

Ready-to-paste usage snippets.

Auto-dismiss snackbar with countdown progress bar

vue