Banner
import { Banner } from "@cherry-design-system/react";
import { Megaphone } from "lucide-react";
export function ReleaseBanner() {
return (
<Banner variant="accent" icon={<Megaphone />} dismissible>
cherry 2.0 is here.
</Banner>
);
}A Banner is a full-width announcement bar for site-wide news, such as a release or scheduled maintenance. It fades in on mount. For a message tied to one part of the page, use Callout; for transient feedback after an action, use a toast.
Examples
Variants
inverse is the default.
import { Banner } from "@cherry-design-system/react";
export function Variants() {
return (
<>
<Banner variant="inverse">Inverse banner.</Banner>
<Banner variant="accent">Accent banner.</Banner>
<Banner variant="subtle">Subtle banner.</Banner>
</>
);
}With an action
action renders after the message. Pass a link or a button.
import { Banner, Link } from "@cherry-design-system/react";
import { Wrench } from "lucide-react";
export function MaintenanceBanner() {
return (
<Banner
variant="subtle"
icon={<Wrench />}
action={<Link href="/status">View status</Link>}
>
Scheduled maintenance on Sunday from 02:00 to 04:00 UTC.
</Banner>
);
}Dismissible
With dismissible the banner shows a close button. Dismissing fades it out and collapses its height to zero, then removes it and calls onDismiss. Use onDismiss to remember the choice.
"use client";
import { useState } from "react";
import { Banner } from "@cherry-design-system/react";
import { Megaphone } from "lucide-react";
export function DismissibleBanner() {
const [hidden, setHidden] = useState(false);
if (hidden) return null;
return (
<Banner
icon={<Megaphone />}
dismissible
onDismiss={() => setHidden(true)}
dismissLabel="Close announcement"
>
New pricing starts next month.
</Banner>
);
}In a flex column or block flow the gap after the banner collapses with it. A grid track cannot shrink below zero, so inside a grid the row gap closes at the end of the animation.
Properties
Color scheme. Defaults to "inverse".
Leading icon, for example <Megaphone />.
Trailing link or button after the message.
Shows a close button. The banner collapses, then onDismiss runs.
Called after the dismiss animation has finished.
Accessible name of the close button. Defaults to "Dismiss".
Name of the region landmark. Defaults to "Announcement".
Banner renders a <div role="region">, forwards its ref to it and passes every other <div> attribute through. It is a client component.
Styling
| Hook | Values |
|---|---|
.cherry-banner | Root element |
data-variant | inverse, accent, subtle |
data-dismissed | Present while the banner collapses |
| Parts | .cherry-banner__inner, __content, __icon, __message, __action, __dismiss |
inverse reads --cherry-bg-inverse and --cherry-fg-inverse, accent reads --cherry-accent-default and --cherry-fg-on-accent, and subtle reads --cherry-bg-subtle and --cherry-border-default.
Accessibility
- The banner is a region landmark. When several banners show at once, give each a distinct
aria-label. - The dismiss button is labelled by
dismissLabel. Translate it there. - The icon is decorative and hidden from assistive tech.