Floating promotional banner for campaigns and sales. It is a non-modal <dialog> rendered on the server: the close button is a <form method="dialog">, so it works without JavaScript. The marquee and the entry animation are pure CSS. A small client script runs only when you pass storageKey, onClose or onCtaClick: it remembers the dismissal and calls the callbacks.
Browser Support
Displays the promotional banner.
Animates the banner entrance.
Animates the banner exit.
Preview
Installation
The marquee keyframes ship inside the component, nothing to add to globals.css. The marquee pauses on hover and stops for reduced motion.
Usage
import { PromoBanner } from "@/components/ui/promo-banner"
export default function Page() {
return (
<PromoBanner
title="Winter Campaign"
headline="START THE NEW YEAR WITH A BANG!"
price={229}
originalPrice={1444}
ctaText="Get Bundle"
ctaHref="/docs"
marqueeText="3 DAYS LEFT • FIRST 100 ONLY"
storageKey="promo-winter"
/>
)
}Examples
Positions
Choose where the banner appears on screen
<PromoBanner position="top-left" />
<PromoBanner position="top-right" />
<PromoBanner position="bottom-left" />
<PromoBanner position="bottom-right" /> // defaultCustom Gradients
The gradient takes colors from theme tokens, so it follows the active theme. Pass any Tailwind classes to change it
<PromoBanner
gradientFrom="from-foreground"
gradientTo="to-[color-mix(in_oklab,var(--foreground)_40%,var(--primary))]"
/>With localStorage
Remember when the user closes the banner. An inline script hides a dismissed banner before the first paint, so it does not flash.
<PromoBanner
storageKey="promo-winter"
delay={3000} // show after 3 seconds
/>Using Provider
Global banner management with context. The provider and the hook are client code.
import { Button } from "@/components/ui/button"
import { PromoBannerProvider, usePromoBanner } from "@/components/ui/promo-banner"
// In layout or app
<PromoBannerProvider>
<App />
</PromoBannerProvider>
// Anywhere in your app
function Component() {
const { show, hide } = usePromoBanner()
return (
<Button onClick={() => show({
headline: "Flash Sale!",
price: 99,
originalPrice: 199,
})}>
Show Promo
</Button>
)
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| headline | string | required | Main headline text |
| price | number | - | Current price |
| title | string | "Special Offer" | Small title above headline |
| originalPrice | number | - | Original price (crossed out) |
| currency | string | "$" | Currency symbol |
| ctaText | string | "Get Now" | CTA button text |
| ctaHref | string | "#" | CTA button link |
| marqueeText | string | - | Scrolling text at bottom |
| position | "bottom-right" | "bottom-left" | "top-right" | "top-left" | "bottom-right" | Banner position |
| gradientFrom | string | "from-foreground" | Gradient start color class |
| gradientTo | string | "to-[color-mix(in_oklab,var(--foreground)_55%,var(--primary))]" | Gradient end color class |
| storageKey | string | - | localStorage key for persistence |
| delay | number | 0 | Delay before showing (ms) |
| images | string[] | - | Product image URLs |
| defaultOpen | boolean | true | Render the banner open |
| showPattern | boolean | false | Diagonal lines on the background |
| labels | { banner?: string; close?: string } | - | Accessible names of the banner and the close button |
| onClose | () => void | - | Close callback, client components only |
| onCtaClick | () => void | - | CTA click callback, client components only |