Ir al contenido
Español
Cuenta atrás con flip viene con Pro. La vista previa aparece al desbloquearlo.

Cómo funciona

A flip clock in which only the digit that changes flips. Time is recomputed from Date.now() and the end time on every wake-up, with the timer aligned to the next second, so delayed timers and background tabs stay accurate. While hidden it keeps one timer to the end; on return it corrects at once without replaying animations. Display follows the device clock, so the server must decide real expiry. Each card is lit from above: the upper half is a touch lighter, the lower half a touch darker, with a dark seam and a soft drop shadow (solid), or a white card on a hairline ring (soft). The demo is a seat hold: the clock sits on a grey panel above a tick meter whose ticks go out as the hold runs down, with an ink Pay button.

Úsalo para

  • Pending payments or confirmations with a clear deadline that should feel urgent.
  • Limited-time offers, flash sales and event start or end countdowns on campaign pages.
  • A reserved hold, such as tickets or seats, where remaining time deserves more weight than a line of text.

Busca otra opción cuando

  • A countdown on every list row: flipping is heavy, use plain text such as “14:59 left”.
  • Short countdowns such as resending a code: put the seconds in the button label.
  • Millisecond display or counting up (a stopwatch): this only counts down in whole seconds.
  • Deciding expiry: the display follows the device clock, so the server decides.

Uso

import { CountdownFlip } from './CountdownFlip.jsx'

// With an absolute deadline (a timestamp from your API): use target
export function PayDeadline({ order, onExpire }) {
  return <CountdownFlip target={order.payDeadline} aria-label="Time left to pay" onComplete={onExpire} />
}

// Only know how many seconds are left: use seconds, counted from mount
// <CountdownFlip seconds={15 * 60} size="sm" variant="soft" labels={false} />

// More than a day: showDays; unit text can be replaced
// <CountdownFlip target={saleEndsAt} showDays labels={{ days: 'd', hours: 'h', minutes: 'm', seconds: 's' }} />

// To restart: pass a new target, or give the component a new key

Propiedades

PropiedadTipoPor defectoQué hace
targetDate | number—Deadline as a Date or millisecond timestamp. Use either this or seconds; target wins. Pass a stable value, not Date.now() + x computed in render.
secondsnumber—Seconds to count down from mount; restarts when the value changes. Use it when there is no absolute deadline.
showDaysbooleanfalseShows days as their own group. When off, time beyond 24 hours accumulates in hours.
labels{ days?, hours?, minutes?, seconds?, ended?, remaining? } | false{ days: 'Days', hours: 'Hours', minutes: 'Min', seconds: 'Sec' }Text under each group, plus spoken text: ended is announced at zero and remaining(text) wraps the spoken time. Spoken units default to full English words; unit entries may also be (n) => string. false hides the unit text.
size'sm' | 'md' | 'lg''md'Card size: 24×34 / 32×46 / 40×58 px.
variant'solid' | 'soft''solid'Look: solid is light text on a dark, softly lit card (inverts in dark mode); soft is dark text on a white card with a hairline ring.
onComplete() => void—Called once at zero, and once on mount if already expired. Called again after every restart (new target or seconds).
pausedbooleanfalseFreezes the digits and onComplete; on resume it continues from the remaining time. Not for real deadlines such as payment.
ariaText(parts) => string"14 minutes 59 seconds remaining" / "Countdown finished"Custom screen reader text for the current time and milestone announcements; parts is { days, hours, minutes, seconds, total }. Return the finished text when total is 0.
...restHTMLAttributes<HTMLDivElement>—Other attributes go to the root, such as className, style and aria-label (say what is being counted). The root gets data-complete after the end.

Accesibilidad

  • The root is role="timer" with aria-live="off", so the per-second change is not announced.
  • Visible digits are aria-hidden; a visually hidden text always holds the current time, such as “14 minutes 59 seconds remaining”.
  • A polite live region speaks only at milestones (each full hour, 30 / 10 / 5 / 1 minutes, 30 / 10 seconds, the end) and clears a few seconds later.
  • Use aria-label to say what is being counted; replace spoken text through labels or ariaText.
  • With reduced motion the cards do not flip and digits change at once.

Movimiento

One flip takes 560ms: 72% easing in from 0° to -180°, then a 10° bounce and settle. Only the digit that changes flips; no animation with reduced motion.

Añádelo a tu proyecto

Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.

CountdownFlip.jsxcountdown-flip.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Datos
Diferencias de código viene con Pro. La vista previa aparece al desbloquearlo.