//feedback
Banner
Full-width announcement bar for promos, maintenance notices, trial reminders and cookie consent, in neutral, primary and status tones. Copy-paste ready.
// title: Dismissible promo and maintenance banners above a page
"use client";
import { ArrowRightIcon, SparklesIcon, WrenchIcon } from "lucide-react";
import { useState } from "react";
import {
Banner,
BannerAction,
BannerClose,
BannerContent,
BannerDescription,
BannerTitle,
} from "@/components/ui/banner";
import { Button } from "@/components/ui/button";
export default function Particle() {
const [promo, setPromo] = useState(true);
const [maintenance, setMaintenance] = useState(true);
return (
<div className="w-full max-w-2xl overflow-hidden rounded-xl border">
{promo && (
<Banner variant="primary">
<SparklesIcon aria-hidden="true" />
<BannerContent>
<BannerTitle>Launch week: 30% off annual plans</BannerTitle>
<BannerDescription className="max-sm:hidden">
Ends Friday, Oct 23.
</BannerDescription>
</BannerContent>
<BannerAction>
<Button
className="border-primary-foreground/24 bg-primary-foreground/12 text-primary-foreground hover:bg-primary-foreground/20"
size="sm"
variant="outline"
>
Upgrade <ArrowRightIcon aria-hidden="true" />
</Button>
</BannerAction>
<BannerClose onClick={() => setPromo(false)} />
</Banner>
)}
{maintenance && (
<Banner variant="warning">
<WrenchIcon aria-hidden="true" />
<BannerContent>
<BannerTitle>Scheduled maintenance</BannerTitle>
<BannerDescription>
Sun, Oct 25 · 02:00–03:00 UTC. Deploys will be paused.
</BannerDescription>
</BannerContent>
<BannerClose onClick={() => setMaintenance(false)} />
</Banner>
)}
<div className="flex min-h-40 flex-col items-center justify-center gap-3 p-6 text-center">
<p className="font-medium text-sm">Dashboard</p>
<p className="text-muted-foreground text-sm">
{promo || maintenance
? "Banners sit above the page and close for this visit."
: "All banners dismissed."}
</p>
{!(promo && maintenance) && (
<Button
onClick={() => {
setPromo(true);
setMaintenance(true);
}}
size="sm"
variant="outline"
>
Show banners again
</Button>
)}
</div>
</div>
);
}
Installation
pnpm dlx shadcn@latest add @cnippet/banner
Usage
import {
Banner,
BannerAction,
BannerClose,
BannerContent,
BannerDescription,
BannerTitle,
} from "@/components/ui/banner"const [open, setOpen] = useState(true)
{open && (
<Banner variant="warning">
<WrenchIcon />
<BannerContent>
<BannerTitle>Scheduled maintenance</BannerTitle>
<BannerDescription>Sun, Oct 25 · 02:00–03:00 UTC.</BannerDescription>
</BannerContent>
<BannerClose onClick={() => setOpen(false)} />
</Banner>
)}Anatomy
<Banner>
<svg /> {/* optional leading icon */}
<BannerContent> {/* title and description, side by side when they fit */}
<BannerTitle />
<BannerDescription />
</BannerContent>
<BannerAction /> {/* buttons */}
<BannerClose /> {/* dismiss button */}
</Banner>Good to know
- Banner is for site-wide or page-wide messages that sit above the content. For a message about one form or section, use Alert; for something that comes and goes, use Toast.
- The banner doesn't hide itself.
BannerCloseis a plain button, so you choose what dismissing means: for this visit (state), or for good (save it to a cookie or local storage). - It has no role by default. Add
role="status"if it appears after the page loads and should be announced, orrole="region"with anaria-labelif users should be able to jump to it. - On narrow screens the actions wrap onto their own row.
API Reference
Banner
| Prop | Type | Default | Description |
|---|---|---|---|
variant | "default" | "primary" | "info" | "success" | "warning" | "error" | "default" | Colour tone |
BannerClose
A button with aria-label="Dismiss" and an X icon. Pass children to replace the icon.
Examples
Tones
// title: Banner tones: default, info, success, warning, error
import {
CircleAlertIcon,
CircleCheckIcon,
InfoIcon,
MegaphoneIcon,
TriangleAlertIcon,
} from "lucide-react";
import {
Banner,
BannerContent,
BannerDescription,
BannerTitle,
} from "@/components/ui/banner";
export default function Particle() {
return (
<div className="flex w-full max-w-2xl flex-col overflow-hidden rounded-xl border [&>*:last-child]:border-b-0">
<Banner>
<MegaphoneIcon aria-hidden="true" />
<BannerContent>
<BannerTitle>New in v4.2</BannerTitle>
<BannerDescription>Saved views for every table.</BannerDescription>
</BannerContent>
</Banner>
<Banner variant="info">
<InfoIcon aria-hidden="true" />
<BannerContent>
<BannerTitle>You're viewing a shared workspace</BannerTitle>
<BannerDescription>
Changes are visible to 12 people.
</BannerDescription>
</BannerContent>
</Banner>
<Banner variant="success">
<CircleCheckIcon aria-hidden="true" />
<BannerContent>
<BannerTitle>All systems operational</BannerTitle>
<BannerDescription>Last incident 41 days ago.</BannerDescription>
</BannerContent>
</Banner>
<Banner variant="warning">
<TriangleAlertIcon aria-hidden="true" />
<BannerContent>
<BannerTitle>Your trial ends in 3 days</BannerTitle>
<BannerDescription>
Add a card to keep your projects.
</BannerDescription>
</BannerContent>
</Banner>
<Banner variant="error">
<CircleAlertIcon aria-hidden="true" />
<BannerContent>
<BannerTitle>Payment failed</BannerTitle>
<BannerDescription>We'll retry on Oct 21.</BannerDescription>
</BannerContent>
</Banner>
</div>
);
}
Cookie consent
A bottom bar with two actions that goes away once the user picks one.
// title: Cookie consent bar with two actions
"use client";
import { CookieIcon } from "lucide-react";
import { useState } from "react";
import {
Banner,
BannerAction,
BannerContent,
BannerDescription,
} from "@/components/ui/banner";
import { Button } from "@/components/ui/button";
export default function Particle() {
const [choice, setChoice] = useState<string | null>(null);
return (
<div className="w-full max-w-2xl overflow-hidden rounded-xl border">
<div className="flex min-h-32 items-center justify-center p-6 text-muted-foreground text-sm">
{choice ? `Saved: ${choice}.` : "Page content"}
</div>
{!choice && (
<Banner className="border-t border-b-0">
<CookieIcon aria-hidden="true" />
<BannerContent>
<BannerDescription className="text-foreground">
We use cookies for analytics. You can change this any time in
settings.
</BannerDescription>
</BannerContent>
<BannerAction className="max-sm:w-full max-sm:*:flex-1">
<Button
onClick={() => setChoice("essential cookies only")}
size="sm"
variant="outline"
>
Essential only
</Button>
<Button onClick={() => setChoice("all cookies")} size="sm">
Accept all
</Button>
</BannerAction>
</Banner>
)}
</div>
);
}