# Promo Banner

> Promo banner with a countdown timer for React and shadcn: digits roll down each second, the code copies, and it folds away at zero.

A time-boxed offer as a bar or a card: the countdown's digits roll down each second, the code copies with a check, and at zero the banner folds away so the page glides up.

Also known as an announcement banner or a hero banner.

- Tier: Free (MIT)
- Interaction: Loading
- Page: https://eased.dev/components/promo-banner
- Installs: motion
- Registry: https://eased.dev/r/promo-banner.json

## Install

```bash
npx shadcn add https://eased.dev/r/promo-banner.json
```

A time-boxed offer as an announcement bar or a hero card, with a countdown whose digits roll down and a copyable code.

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

## Usage

```tsx example.tsx
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.

```tsx
<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 `timer` with `aria-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

- [Number Roll](/components/number-roll): the digits.
- [Product Card](/components/product-card): what the sale links to.

## Example

`components/eased/promo-banner/promo-banner-demo.tsx`

```tsx
"use client";

import { AnimatePresence, motion } from "motion/react";
import { useState } from "react";
import { ProductArt } from "../_primitives/commerce-core/commerce-core";
import { FIXTURE_NOW } from "../_primitives/fixtures/shared";
import { productById, promo } from "../_primitives/fixtures/ecommerce";
import { Button } from "../button/button";
import { DemoFrame } from "../lib/demo-frame";
import { enter, exitFast, reducedFade, useSafeReducedMotion } from "../lib/motion";
import { PromoBanner } from "./promo-banner";

const SHELF = ["p1", "p6", "p4"].map(productById);

/** Fern & Field's storefront: a flash bar that folds away at zero, over the season's sale card. */
export function PromoBannerDemo() {
  const reduced = useSafeReducedMotion();
  // A new key restarts the flash offer from its full length.
  const [run, setRun] = useState(0);
  const [gone, setGone] = useState(false);
  const start = () => {
    setGone(false);
    setRun((r) => r + 1);
  };

  return (
    <DemoFrame>
      {/* A relative clock (now 0, ends at 14s) that starts when it mounts; a new key replays it. */}
      <PromoBanner
        key={run}
        className="shrink-0"
        variant="bar"
        now={0}
        endsAt={promo.flash.durationMs}
        headline={promo.flash.headline}
        detail={promo.flash.detail}
        onCollapsed={() => setGone(true)}
      />
      <div className="flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto p-(--pad)">
        <PromoBanner
          variant="card"
          now={FIXTURE_NOW}
          endsAt={promo.endsAt}
          headline={promo.headline}
          detail={promo.detail}
          code={promo.code}
          action={
            <Button variant="secondary" size="sm">
              Shop the sale
            </Button>
          }
        />
        <div className="grid grid-cols-3 gap-2">
          {SHELF.map((p) => (
            <ProductArt key={p.id} kind={p.art} color={p.variants[0].hex} label={p.name} className="h-24 rounded-control" />
          ))}
        </div>
        <AnimatePresence>
          {gone && (
            <motion.div
              className="-mt-1 flex justify-center"
              initial={{ opacity: 0, y: reduced ? 0 : 4 }}
              animate={{ opacity: 1, y: 0, transition: reduced ? reducedFade : enter }}
              exit={{ opacity: 0, transition: exitFast }}
            >
              <Button variant="ghost" size="sm" onClick={start}>
                Replay the flash offer
              </Button>
            </motion.div>
          )}
        </AnimatePresence>
      </div>
    </DemoFrame>
  );
}
```
