Countdown

PreviousNext

A live countdown timer that displays the remaining time to a target date as animated flip-card digits, broken into days, hours, minutes, and seconds.

0
0
0
0
0
0
0
0
days
0
0
0
0
0
0
0
0
hours
0
0
0
0
0
0
0
0
minutes
0
0
0
0
0
0
0
0
seconds
0
0
0
0
0
0
0
0
days
0
0
0
0
0
0
0
0
hours
0
0
0
0
0
0
0
0
minutes
0
0
0
0
0
0
0
0
seconds
'use client';

import { Countdown } from '@/ui/Countdown';

const labels = {
  days: 'days',
  hours: 'hours',
  minutes: 'minutes',
  seconds: 'seconds',
};

const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);

const nextWeek = new Date();
nextWeek.setDate(nextWeek.getDate() + 7);

export function CountdownDemo() {
  return (
    <div className="flex flex-col gap-8">
      <Countdown countdown={{ to: tomorrow.toISOString(), labels }} theme="saffron" />
      <div className="bg-ultramarine p-6 rounded-16">
        <Countdown
          countdown={{ to: nextWeek.toISOString(), labels }}
          theme="white"
          className="text-white"
        />
      </div>
    </div>
  );
}

Installation

npx shadcn@latest add https://develop.trident-ui.pro.clubmed/r/countdown.json

Usage

'use client';
 
import { Countdown } from '@/ui/Countdown';
 
export function Component() {
  const target = new Date();
  target.setDate(target.getDate() + 1);
 
  return (
    <Countdown
      countdown={{
        to: target.toISOString(),
        labels: {
          days: 'days',
          hours: 'hours',
          minutes: 'minutes',
          seconds: 'seconds',
        },
      }}
      theme="saffron"
    />
  );
}

API Reference

Countdown

PropTypeDefaultDescription
countdown{ to: string; labels: CountdownLabels }requiredTarget date (ISO string) and display labels for each unit
themeTheme"white"Color theme applied to the flip-card digits
classNamestringundefinedAdditional CSS classes for the outer wrapper

CountdownLabels

PropTypeDescription
daysstringLabel shown below the days digits
hoursstringLabel shown below the hours digits
minutesstringLabel shown below the minutes digits
secondsstringLabel shown below the seconds digits

Notes

  • Flip animation: Each digit transitions with a 3D flip effect when its value changes, using the animate-tick / animate-tock keyframes defined in the trident-ui CSS.
  • Leading zero dimming: Units whose value is 0 and whose higher-order units are also 0 are rendered with the black theme to indicate they are inactive.
  • Direction: The component always renders dir="ltr" regardless of the document direction, so digit order stays consistent.
  • Client component: Uses setInterval via useEffect and must be rendered in a client context ('use client').
  • Accessibility: The wrapper has role="timer" so assistive technologies announce it as a timer landmark.
  • Stopping: The interval is cleared automatically when the target date is reached; no further re-renders occur after expiry.