Banner
A strip across the top of a page or a view for one short notice: a release, a beta, a trial ending, an outage.
Usage
import { Banner, BannerClose, BannerLink } from 'nyctoui/banner'
<Banner>
Workspaces can now share one billing plan.
<BannerLink href="/changelog">Read the changelog</BannerLink>
<BannerClose />
</Banner>Put the banner first in the page, above the header, and let it run the full width. It is at least 40px tall with 14px text, and wraps onto a second line on narrow screens rather than cutting the text off. Keep it to one sentence and one link; a page holds one banner at a time.
It takes the same tone and variant as a Badge, with the same tints and inks, so a Badge inside it, like the New above, matches. For a notice that comes and goes after an action, use a Toast.
Good for
- An outage or degraded-service notice across the top of a SaaS dashboard.
- A trial ending soon, with a link to the billing page.
- A beta notice at the top of a new section of an app.
- A read-only notice when someone opens a shared document they can’t edit.
Examples
Tones
neutral is for announcements: a release, a beta, a new feature. The hues are for status, as on a badge: blue for information, green for success, yellow and orange for warnings, red for an outage or a failure.
Outline
variant="outline" leaves the page’s own background and draws a hairline underneath, for a banner that should sit back further than a tinted strip.
With an icon
Put a 16px Tabler icon in a BannerIcon before the text. It takes the banner’s color and is hidden from assistive technology; the text carries the meaning.
Above an app
align="start" lines the text up with the view under it, for a notice above an app rather than a landing page.
Dismissing
A BannerClose hides the banner. It sits at the inline end, and the banner keeps the same room on the other side, so centered text stays centered on the page. Pass open and onOpenChange to keep the choice, for example in storage under the announcement’s id, so it stays dismissed on the next visit and the next announcement shows again.
Accessibility
A banner is plain content, not a live region: it is on the page when the page loads, so it is read in order like the rest. For a notice that appears after something happens, use a Toast, which is announced. To make the banner a landmark, pass render={<aside aria-label="Announcement" />}.
BannerClose is labelled “Dismiss”. A status tone is never the only signal: say what happened in the text.
Best practices
- Pick the tone from the message: blue for news, yellow or orange for a warning, red for a failure, green for a confirmation.
- Keep it to one short sentence, such as “Payments are delayed”, plus one link to the detail.
- Let people dismiss a release or beta notice with
BannerClose, and keep an outage or a blocked account up until it is fixed. - Say the status in the words, not only the color or the icon; the icon is decoration to a screen reader.
- Use a banner for something that just happened, like a saved change. That’s a toast.
- Stack several banners. Combine related notices into one, or show the most urgent and queue the rest.
- Use a banner for a note about one part of the page. Put a callout next to that part instead.
API reference
Banner
A <div> by default. Other props go to the element.
| Prop | Type | Default |
|---|---|---|
toneColor, as on Badge. Use a hue only for status. | 'neutral' | 'red' | 'orange' | 'yellow' | 'green' | 'blue' | 'neutral' |
variantA tinted fill, or a hairline under a transparent fill. | 'soft' | 'outline' | 'soft' |
alignCentered for a page, or lined up with an app view. | 'center' | 'start' | 'center' |
openWhether the banner is shown. For controlled use. | boolean | — |
defaultOpenWhether it is shown at first. For uncontrolled use. | boolean | true |
onOpenChangeCalled with false when a BannerClose is pressed. | (open: boolean) => void | — |
renderRenders another element, such as an <aside>, with the banner’s props. | ReactElement | (props) => ReactElement | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
BannerIcon
A <span> slot for a 16px icon, hidden from assistive technology.
| Prop | Type | Default |
|---|---|---|
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
BannerLink
An underlined <a> in the banner’s color. Other props go to the element.
| Prop | Type | Default |
|---|---|---|
renderRenders a router link instead, e.g. <Link to="…" />. | ReactElement | (props) => ReactElement | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |
BannerClose
A small ghost icon Button that hides the banner. Other props go to the button.
| Prop | Type | Default |
|---|---|---|
aria-labelThe button’s accessible name. | string | 'Dismiss' |
onClickRuns first; call event.preventDefault() to keep the banner open. | (event) => void | — |
sxStyleX styles merged after the built-in ones. | StyleXStyles | — |