Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Countdown Timer

ProNew

A 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

pnpm dlx shadcn@latest add @viewport/countdown-timer

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

PropTypeDefault
targetDate | number | string

The moment the timer runs out: a `Date`, a timestamp in milliseconds or a date string.

—
durationnumber

Instead of `target`: seconds to count down from the moment the timer is first shown to this visitor.

—
storageKeystring

Remember the first visit for a relative timer across reloads. Use a unique key per offer.

—
repeatEverynumber

Start a new relative countdown every N seconds, measured from the first visit.

—
recurrenceCountdownRecurrence

Roll 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.

—
titleReact.ReactNode

Bold line next to the digits in the bar, or above them in the card.

—
textReact.ReactNode

Regular 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.

—
unitsCountdownUnit[]

Units to show, largest first. Without `days` the hours keep counting past 24.

ALL
labelsPartial<Record<CountdownUnit, string>>

Words under the numbers, e.g. to translate them.

—
separatorboolean

Puts a colon between the units.

false
actionCountdownAction

Call to action.

—
expired"zeros" | "message" | "hide"

When time is up: keep the `zeros`, swap the digits for a `message`, or `hide` the timer.

—
expiredTextReact.ReactNode

The message shown when time is up.

"This offer has ended"
expiredActionCountdownAction

Replaces the action when time is up. Without it the action goes away with the offer.

—
onExpire() => void

Called 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"
dismissibleboolean

Shows the close button. On by default for the bar.

—
onDismiss() => void

Called after the timer has been closed.

—
labelstring

Accessible name of the timer.

"Countdown"
classNamestring—

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.