Countdown
DD:HH:MM:SS rolling timer with independent digit reels so only changing columns animate, with feature-detected Temporal and Intl.DurationFormat support.
Customize
Installation
npx shadcn@latest add @kinetic/countdownUsage
Pass an absolute deadline to target (Date, epoch timestamp in milliseconds, or ISO string) or a relative duration in seconds. Every digit slot renders its own RollingWheelDigit reel so only the columns that actually change roll on each second tick while idle digits stay completely still.
Control the days column with showDays ("auto" by default, showing days only when greater than zero, or force true / false), customize the divider via separator (default ":"), and display unit captions with labels.
import { Countdown } from "@/components/kinetic/ui/countdown";
interface LaunchCountdownProps {
readonly deadline: string;
}
export function LaunchCountdown({ deadline }: LaunchCountdownProps) {
return (
<Countdown
target={deadline}
showDays="auto"
labels
className="text-3xl font-semibold"
/>
);
}Custom labels, callbacks, and imperative control
Pass a partial CountdownLabels object to labels to localize unit captions, toggle paused declaratively, or listen to onTick (receiving CountdownParts) and onComplete. Attach a CountdownHandle ref to call pause(), resume(), or reset(nextSeconds?) (omitting nextSeconds restores the original target or seconds prop).
import { useRef } from "react";
import {
Countdown,
type CountdownHandle,
type CountdownParts,
} from "@/components/kinetic/ui/countdown";
interface SessionTimerProps {
readonly initialSeconds: number;
readonly onExpire: () => void;
}
export function SessionTimer({ initialSeconds, onExpire }: SessionTimerProps) {
const timerRef = useRef<CountdownHandle>(null);
const handleTick = (_parts: CountdownParts) => {};
return (
<div className="space-y-3">
<Countdown
ref={timerRef}
seconds={initialSeconds}
showDays={false}
labels={{ hours: "Hr", minutes: "Min", seconds: "Sec" }}
onTick={handleTick}
onComplete={onExpire}
className="text-2xl font-semibold"
/>
<div className="flex gap-2">
<button type="button" onClick={() => timerRef.current?.pause()}>
Pause
</button>
<button type="button" onClick={() => timerRef.current?.resume()}>
Resume
</button>
<button type="button" onClick={() => timerRef.current?.reset(300)}>
Reset 5m
</button>
</div>
</div>
);
}Temporal, Intl.DurationFormat, and accessibility
When running in environments with native Temporal, Countdown reads the current clock via Temporal.Now.instant() and parses ISO target strings via Temporal.Instant.from(), falling back seamlessly to Date.now() and Date.parse().
For assistive technology, Countdown feature-detects Intl.DurationFormat (using locale, default "en-US") to build a natural spoken duration string inside .sr-only, with a plain-text fallback when unavailable. Per-second updates stay silent (aria-live="off") so screen readers are never flooded; enable announceComplete to announce a single polite role="status" update when the timer reaches zero.
Motion preferences
blurPx (default 2, clamped at 8px max) and speed scale with the global Kinetic tempo. Under reduced motion, every RollingWheelDigit disables spring rolling and snaps straight to the next digit each second while keeping the interval, onTick, and onComplete behavior unchanged.
API Reference
Countdown
Per-digit rolling countdown clock supporting absolute target dates or relative durations with localized accessible text.
| Prop | Type | Default | Description |
|---|---|---|---|
target | Date | number | string | - | Target date, epoch timestamp, or ISO string. |
seconds | number | - | Relative countdown length in seconds when target is omitted. |
showDays | boolean | "auto" | "auto" | Auto displays DD only when remaining days > 0. |
separator | string | ":" | Delimiter rendered between time columns. |
labels | boolean | Partial<CountdownLabels> | false | Shows default or custom captions under each unit column. |
paused | boolean | false | Freezes ticking at the current remaining time. |
onTick | (parts: CountdownParts) => void | - | Called every second with days, hours, minutes, and seconds. |
onComplete | () => void | - | Called when the countdown reaches zero. |