Countdown Timer
ProNewA countdown to a date or from the visitor’s arrival, optionally remembering the first visit or restarting on a fixed interval: a plain bar, digit tiles or a flip-clock card, with actions and expiry states.
Installation
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
Props
| Prop | Type | Default |
|---|---|---|
| target | Date | number | stringThe moment the timer runs out: a `Date`, a timestamp in milliseconds or a date string. | — |
| duration | numberInstead of `target`: seconds to count down from the moment the timer is first shown to this visitor. | — |
| storageKey | stringRemember the first visit for a relative timer across reloads. Use a unique key per offer. | — |
| repeatEvery | numberStart a new relative countdown every N seconds, measured from the first visit. | — |
| recurrence | CountdownRecurrenceRoll a passed `target` forward to its next occurrence instead of expiring, e.g. a sale that ends every Friday at 5pm. Arithmetic is wall-clock in the viewer's timezone, so local times survive DST changes. | — |
| title | React.ReactNodeBold line next to the digits in the bar, or above them in the card. | — |
| text | React.ReactNodeRegular line under the title. | — |
| layout | "bar" | "card"`bar` is one full-width line; `card` stacks message, digits and action in the middle. | "bar" |
| digits | "plain" | "tiles" | "flip"`plain` is colored numbers, `tiles` puts every digit in its own tile, `flip` turns the tiles like a flip clock. | layout === "card" ? "flip" : "plain" |
| theme | "light" | "dark" | "blue" | "red" | "pink"Color theme. `light` and `blue` follow your light and dark tokens; the others keep their colors in both. | "light" |
| colors | { background?: string; text?: string; digit?: string; digitText?: string; accent?: string; accentText?: string }Overrides for single colors of the theme. Any CSS color. `digit` is the number color, or the tile color with `digitText` on it. | — |
| units | CountdownUnit[]Units to show, largest first. Without `days` the hours keep counting past 24. | ALL |
| labels | Partial<Record<CountdownUnit, string>>Words under the numbers, e.g. to translate them. | — |
| separator | booleanPuts a colon between the units. | false |
| action | CountdownActionCall to action. | — |
| expired | "zeros" | "message" | "hide"When time is up: keep the `zeros`, swap the digits for a `message`, or `hide` the timer. | — |
| expiredText | React.ReactNodeThe message shown when time is up. | "This offer has ended" |
| expiredAction | CountdownActionReplaces the action when time is up. Without it the action goes away with the offer. | — |
| onExpire | () => voidCalled once when the timer reaches zero. | — |
| position | "static" | "sticky" | "top" | "bottom"For the bar: `static` sits in the page flow, `sticky` stays at the top while scrolling, `top` and `bottom` are fixed to the viewport. | "static" |
| dismissible | booleanShows the close button. On by default for the bar. | — |
| onDismiss | () => voidCalled after the timer has been closed. | — |
| label | stringAccessible name of the timer. | "Countdown" |
| className | string | — |
Accessibility
- The digits are a timer that reads as one phrase, “6 days, 7 hours, 8 minutes, 54 seconds left”, and is not announced every second.
- When time is up the message that replaces the digits is announced once through a status.
- The action is a link or a button and the bar has a named Close button, all with visible focus.
- Under reduced motion digits change in place, without rolling or flipping.