When to use
- A sale or free-shipping window with a real end time.
- A launch or drop announcement that should disappear on its own when it is over.
When not to use
- Offers without a deadline: a plain announcement bar is calmer. Fake urgency erodes trust.
- Blocking messages: use Dialog, after rule 118's checks.
Installation
pnpm dlx shadcn add https://eased.dev/r/promo-banner.jsonnpx shadcn add https://eased.dev/r/promo-banner.jsonyarn dlx shadcn add https://eased.dev/r/promo-banner.jsonbunx --bun shadcn add https://eased.dev/r/promo-banner.jsonThe command adds Promo Banner, everything it builds on and Eased’s tokens to your project.
Install the dependencies
pnpm add motionnpm install motionyarn add motionbun add motionAdd the Eased pieces it builds on
Copy each item’s files the same way, or install them with the CLI:
Copy the source into your project
components/eased/promo-banner/promo-banner.tsxTSX "use client";import { useInView } from "motion/react";import { useEffect, useRef, useState, type ReactNode } from "react";import { AutoHeight } from "../_primitives/auto-height/auto-height";import { CopyIcon, useCopy } from "../_primitives/copy/copy";import { NumberRoll } from "../_primitives/number-roll/number-roll";import { TextSwap } from "../_primitives/text-swap/text-swap";import { useSafeReducedMotion } from "../lib/motion";import { pressIcon } from "../lib/press";/* ---------- Countdown -------------------------------------------------------------------- */export type CountdownParts = { days: number; hours: number; minutes: number; seconds: number; total: number };const split = (ms: number): CountdownParts => { const t = Math.max(0, Math.ceil(ms / 1000)); return { days: Math.floor(t / 86_400), hours: Math.floor(t / 3600) % 24, minutes: Math.floor(t / 60) % 60, seconds: t % 60, total: t };};/** * Seconds left until `endsAt`. `now` pins the first render (server and client agree), and the * clock then runs on real elapsed time from there. It ticks on the second boundary while the * element is on screen and catches up when it comes back, so an off-screen banner costs nothing. */export function useCountdown(endsAt: number, { now, target }: { now?: number; target?: React.RefObject<Element | null> } = {}) { const [left, setLeft] = useState<number | null>(now === undefined ? null : endsAt - now); const none = useRef<Element | null>(null); const inView = useInView(target ?? none, { margin: "64px" }); const active = target ? inView : true; // Offset between the pinned now and the machine clock, fixed on the first client tick. const offset = useRef<number | null>(null); const pinned = useRef(now); useEffect(() => { if (!active) return; if (offset.current === null) offset.current = pinned.current === undefined ? 0 : pinned.current - Date.now(); const skew = offset.current; let timer = 0; const tick = () => { const ms = endsAt - (Date.now() + skew); setLeft(ms); if (ms > 0) timer = window.setTimeout(tick, ((ms % 1000) + 1000) % 1000 || 1000); }; tick(); return () => window.clearTimeout(timer); }, [endsAt, active]); return left === null ? null : split(left);}/* ---------- Banner ----------------------------------------------------------------------- */export type PromoBannerProps = { /** When the offer ends, epoch ms. */ endsAt: number; /** Pin "now" for the first render (SSR, demos). Default: the machine clock after hydration. */ now?: number; headline: ReactNode; detail?: ReactNode; /** A discount code, copyable from the banner. */ code?: string; /** A trailing action, e.g. a "Shop the sale" Button or link. */ action?: ReactNode; /** `bar`: a one-line announcement bar. `card`: a hero card with digit tiles. Default "bar". */ variant?: "bar" | "card"; /** The bar's fill. `neutral` (ink on the canvas colour) is calmer when the page already has a brand CTA. Default "brand". */ tone?: "brand" | "neutral"; /** Collapse the banner when the clock reaches zero. Default true. */ collapseOnExpire?: boolean; /** Fires once at zero. */ onExpire?: () => void; /** Fires when the collapse has settled, to unmount or swap in the next offer. */ onCollapsed?: () => void; locale?: Intl.LocalesArgument; className?: string;};const UNITS = [ { key: "days", short: "d", long: "Days" }, { key: "hours", short: "h", long: "Hours" }, { key: "minutes", short: "m", long: "Min" }, { key: "seconds", short: "s", long: "Sec" },] as const;const spokenLeft = (p: CountdownParts) => { const bits = [p.days && `${p.days} day${p.days === 1 ? "" : "s"}`, p.hours && `${p.hours} hour${p.hours === 1 ? "" : "s"}`, `${p.minutes} minute${p.minutes === 1 ? "" : "s"}`].filter(Boolean); return p.total < 60 ? "less than a minute" : bits.join(" ");};/** * A time-boxed offer: digits roll down each second, and at zero the banner folds away on a * height spring so the page below glides up instead of jumping. The code copies with a morph * to a check. Screen readers get the time left to the minute, not a tick every second. */export function PromoBanner({ endsAt, now, headline, detail, code, action, variant = "bar", tone = "brand", collapseOnExpire = true, onExpire, onCollapsed, locale, className = "",}: PromoBannerProps) { const root = useRef<HTMLDivElement>(null); const reduced = useSafeReducedMotion(); const parts = useCountdown(endsAt, { now, target: root }); const expired = parts !== null && parts.total === 0; const fired = useRef(false); const latest = useRef(onExpire); useEffect(() => { latest.current = onExpire; }); useEffect(() => { if (expired && !fired.current) { fired.current = true; latest.current?.(); } if (!expired) fired.current = false; }, [expired]); const units = UNITS.filter((u) => u.key !== "days" || (parts?.days ?? 0) > 0); const two = { minimumIntegerDigits: 2, useGrouping: false } as const; const digit = (v: number | undefined, i: number) => v === undefined ? "––" : <NumberRoll value={v} locale={locale} format={i === 0 && units[0].key === "days" ? { useGrouping: false } : two} direction="down" animated={!reduced} aria-hidden />; const timer = ( <span role="timer" aria-live="off" className="sr-only"> {parts ? (expired ? "Offer ended" : `Ends in ${spokenLeft(parts)}`) : ""} </span> ); return ( <AutoHeight open={!(collapseOnExpire && expired)} onOpenChangeComplete={(open) => !open && onCollapsed?.()} className={className}> <div ref={root}> {variant === "bar" ? ( <div className={`flex min-h-10 flex-wrap items-center justify-center gap-x-3 gap-y-1 px-(--pad,16px) py-2 text-ui-sm ${tone === "neutral" ? "bg-text text-bg" : "bg-brand text-text-on-brand"}`}> {timer} <p className="min-w-0 text-center text-pretty"> <span className="font-medium">{headline}</span> {detail && <span className="opacity-80"> · {detail}</span>} </p> <span aria-hidden className="inline-flex items-center gap-1.5 font-medium tabular-nums"> <span className="opacity-80">Ends in</span> <span className="inline-flex"> {units.map((u, i) => ( <span key={u.key} className="inline-flex"> {i > 0 && (u.key === "hours" && units[0].key === "days" ? " " : ":")} {digit(parts?.[u.key], i)} {u.key === "days" && "d"} </span> ))} </span> </span> {code && <CodeChip code={code} tone="bar" />} {action} </div> ) : ( <div className="flex flex-col gap-4 rounded-panel border border-line-subtle bg-surface p-(--card-pad,20px) [--card-pad:20px] [--pad:var(--card-pad)] [--radius-outer:var(--eased-radius-panel)]"> {timer} <div className="flex flex-col gap-1"> <p className="text-ui-md font-medium text-balance text-text">{headline}</p> {detail && <p className="text-ui-sm text-pretty text-text-secondary">{detail}</p>} </div> <div aria-hidden className="grid gap-2" style={{ gridTemplateColumns: `repeat(${units.length}, minmax(0, 1fr))` }}> {units.map((u, i) => ( <div key={u.key} className="flex flex-col items-center gap-0.5 rounded-control-sm bg-surface-sunken py-2.5 inset-shadow-well"> <span className="text-2xl font-medium text-text tabular-nums">{digit(parts?.[u.key], i)}</span> <span className="text-ui-2xs tracking-caps text-text-muted uppercase">{u.long}</span> </div> ))} </div> {(code || action) && ( <div className="flex flex-wrap items-center justify-between gap-3"> {code && <CodeChip code={code} tone="card" />} {action} </div> )} </div> )} </div> </AutoHeight> );}/** The code as a chip: press copies it; the label swaps to "Copied" and the icon draws a check. */function CodeChip({ code, tone }: { code: string; tone: "bar" | "card" }) { const { copied, copy } = useCopy(code); return ( <button type="button" onClick={() => void copy()} aria-label={`Copy code ${code}`} // On the card it shares a row with the action, so it takes the action's 32px height (rule 52). className={`inline-flex shrink-0 cursor-pointer items-center gap-1.5 border border-dashed font-mono text-ui-xs font-medium slashed-zero ${pressIcon} ${ tone === "bar" ? "h-control-xs rounded-control-xs border-current/40 px-2 hover-fine:bg-current/10" : "h-control-sm rounded-control-sm border-line-strong px-3 text-text hover-fine:bg-surface-hover" }`} > <TextSwap>{copied ? "Copied" : code}</TextSwap> <CopyIcon copied={copied} className="size-3.5! [&_svg]:size-3.5" /> <span aria-live="polite" className="sr-only"> {copied ? `Code ${code} copied` : ""} </span> </button> );}Keep the folder layout
The files import each other by relative path (
../lib/motion), so keep each one at the path shown, undercomponents/eased/.
Usage
import { PromoBanner } from "@/components/eased/promo-banner/promo-banner";<PromoBanner endsAt={Date.parse("2026-10-19T23:59:00Z")} headline="End-of-season sale" detail="Up to 25% off outerwear" code="FIELD25"/>Examples
Card
A hero card with digit tiles and an action, for the top of a sale page.
<PromoBanner variant="card" endsAt={endsAt} headline="End-of-season sale" code="FIELD25" action={<Button size="sm">Shop the sale</Button>} />API reference
PromoBanner
| Prop | Type | Default | Description |
|---|---|---|---|
endsAt | number | Epoch ms. | |
now | number | the clock | Pins the first render so server and client agree; the clock then runs on real time. |
headline / detail | ReactNode | ||
code | string | Copyable discount code. | |
action | ReactNode | Trailing button or link. | |
variant | "bar" | "card" | "bar" | |
tone | "brand" | "neutral" | "brand" | The bar's fill; neutral is ink on the canvas colour, calmer beside a brand CTA. |
collapseOnExpire | boolean | true | Fold away at zero. |
onExpire / onCollapsed | () => void | At zero; when the fold has settled. |
useCountdown(endsAt, { now, target }) is exported for your own layouts: it returns { days, hours, minutes, seconds, total } and only ticks while target is on screen.
Accessibility
- A
timerwitharia-live="off"carries the time left to the minute, so screen readers aren't read a tick every second. - The code button announces "Code FIELD25 copied" politely.
Motion
Every second each changed digit rolls down on the snappy spring, so 10 → 09 turns the tens column too. At zero the banner folds on Auto Height's smooth spring and the content below glides up; content fades out first. The copy icon draws a check and the code swaps to "Copied". Off screen, the clock stops ticking and catches up when it returns. Reduced motion: digits change in place and the fold snaps.
Notes for AI
Pick it for any offer with an end time. Pass now when rendering on the server, or the first paint shows dashes until hydration.
The clock does not start until the banner is on screen, by design: a banner below the fold keeps its full time until it is scrolled into view. A pinned now maps to the moment the banner first appears, so the countdown starts from endsAt - now then, not on mount. Without now it reads the real clock when it appears.
Don't run your own interval or hide the banner yourself at zero: it does both, and calls onCollapsed when it is safe to unmount.
Related components
- Animated Number Counter: the digits.
- E-commerce Product Card: what the sale links to.
- Shopping Cart Drawer