useCountdown
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
Signature TypeScript complète extraite du fichier du composable.
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
Paramètres
Paramètres d'entrée acceptés par ce composable.
- millisecondsrequisnumber
- Total countdown duration in milliseconds. This is the initial value of time and the value it resets to on reset().
API
Valeurs de retour
Propriétés et méthodes exposées par l'objet retourné par le composable.
- 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
Exemples
Extraits de code prêts à coller.
Auto-dismiss snackbar with countdown progress bar