Notice Banner
A full-width strip at the top of a page. Use it when something needs action, such as an integration that needs authorization. The message is on the left and the actions follow it.
Installation
pnpm dlx shadcn@latest add https://sprout.tulipfarm.ai/r/notice-banner.jsonCopies Notice Banner into your app, installs the packages, and adds the styles. Then import it from @/components/ui/notice-banner. Needs Tailwind CSS 4 and a components.json from shadcn init.
Install the following dependencies:
pnpm add clsx tailwind-mergeAdd Sprout base once per app: the
cn()helper and the design tokens.lib/sprout/classes.ts- Design tokens, for your global CSS
Copy and paste the following code into your project.
import type { ComponentProps, ReactNode } from 'react'; import { cn } from '@/lib/sprout/classes'; export const noticeBannerCompactNames = ['sm', 'md', 'lg'] as const; export type NoticeBannerCompactBelow = (typeof noticeBannerCompactNames)[number]; export interface NoticeBannerProps extends Omit<ComponentProps<'section'>, 'children'> { children: ReactNode; actions?: ReactNode; compact?: boolean | NoticeBannerCompactBelow | undefined; } export function NoticeBanner({ children, actions, compact, className, ...props }: NoticeBannerProps) { return ( <section data-slot="notice-banner" data-compact={compact === true ? '' : compact || undefined} className={cn('sprout-notice-banner', className)} {...props} > <div data-slot="notice-banner-content" className="sprout-notice-banner-content"> {children} </div> {actions != null && actions !== false && ( <div data-slot="notice-banner-actions" className="sprout-notice-banner-actions"> {actions} </div> )} </section> ); }Add the styles to your global CSS, after
@import "tailwindcss".@layer components { .sprout-notice-banner { box-sizing: border-box; border-bottom: 1px solid var(--sprout-line); background: var(--sprout-surface); width: 100%; min-width: 0; color: var(--sprout-muted); font-family: var(--sprout-font); font-size: var(--sprout-text-sm); flex-direction: column; flex-shrink: 0; gap: 8px; padding: 8px 16px; line-height: 1.25rem; display: flex; } .sprout-notice-banner-content { overflow-wrap: anywhere; min-width: 0; } .sprout-notice-banner-content :where(p) { margin: 0; } .sprout-notice-banner-actions { flex-wrap: wrap; flex-shrink: 0; align-items: center; gap: 8px; width: 100%; min-width: 0; display: flex; } @media (width >= 640px) { .sprout-notice-banner { flex-direction: row; align-items: center; gap: 16px; padding-inline: 24px; } .sprout-notice-banner-actions { width: auto; } } .sprout-notice-banner[data-compact=""] { flex-direction: row; align-items: center; gap: 12px; } .sprout-notice-banner[data-compact=""] > .sprout-notice-banner-content, .sprout-notice-banner[data-compact=""] > .sprout-notice-banner-content > * { white-space: nowrap; text-overflow: ellipsis; overflow-wrap: normal; overflow: hidden; } .sprout-notice-banner[data-compact=""] > .sprout-notice-banner-content { flex: auto; } .sprout-notice-banner[data-compact=""] > .sprout-notice-banner-actions { flex-wrap: nowrap; width: auto; } @media (width < 640px) { .sprout-notice-banner[data-compact="sm"] { flex-direction: row; align-items: center; gap: 12px; } .sprout-notice-banner[data-compact="sm"] > .sprout-notice-banner-content, .sprout-notice-banner[data-compact="sm"] > .sprout-notice-banner-content > * { white-space: nowrap; text-overflow: ellipsis; overflow-wrap: normal; overflow: hidden; } .sprout-notice-banner[data-compact="sm"] > .sprout-notice-banner-content { flex: auto; } .sprout-notice-banner[data-compact="sm"] > .sprout-notice-banner-actions { flex-wrap: nowrap; width: auto; } } @media (width < 768px) { .sprout-notice-banner[data-compact="md"] { flex-direction: row; align-items: center; gap: 12px; } .sprout-notice-banner[data-compact="md"] > .sprout-notice-banner-content, .sprout-notice-banner[data-compact="md"] > .sprout-notice-banner-content > * { white-space: nowrap; text-overflow: ellipsis; overflow-wrap: normal; overflow: hidden; } .sprout-notice-banner[data-compact="md"] > .sprout-notice-banner-content { flex: auto; } .sprout-notice-banner[data-compact="md"] > .sprout-notice-banner-actions { flex-wrap: nowrap; width: auto; } } @media (width < 1024px) { .sprout-notice-banner[data-compact="lg"] { flex-direction: row; align-items: center; gap: 12px; } .sprout-notice-banner[data-compact="lg"] > .sprout-notice-banner-content, .sprout-notice-banner[data-compact="lg"] > .sprout-notice-banner-content > * { white-space: nowrap; text-overflow: ellipsis; overflow-wrap: normal; overflow: hidden; } .sprout-notice-banner[data-compact="lg"] > .sprout-notice-banner-content { flex: auto; } .sprout-notice-banner[data-compact="lg"] > .sprout-notice-banner-actions { flex-wrap: nowrap; width: auto; } } @media (forced-colors: active) { .sprout-notice-banner { border-bottom-color: canvastext; } } @media (prefers-reduced-motion: no-preference) { .sprout-notice-banner { animation: sprout-notice-banner-in var(--sprout-motion-normal) var(--sprout-motion-ease); } } @keyframes sprout-notice-banner-in { from { opacity: 0; transform: translateY(-2px); } } }Import it from
@/components/ui/notice-banner. Update the paths if your@/alias points elsewhere.
pnpm add @tulipfarm/sprout@import "tailwindcss";
@import "@tulipfarm/sprout/styles.css";The package keeps the source and ships fixes with each release. Import from @tulipfarm/sprout/notice-banner.
Usage
import { Button } from "@tulipfarm/sprout/button";
import { NoticeBanner } from "@tulipfarm/sprout/notice-banner";
<NoticeBanner
aria-label="Integration authorization"
actions={<Button variant="outline">Update permissions</Button>}
>
<p role="status">
<span className="font-medium text-sprout-warning">
Google Calendar ([email protected]) needs authorization.
</span>{" "}
Approve the updated permissions to continue.
</p>
</NoticeBanner>NoticeBanner renders a section with a 1px line under it, the surface color, and 14px muted text. childrenis the message. actions holds buttons, selects, or other controls. They wrap when there is no room. Leave out actionsto show only the message. Other props, like className, go to the section.
By default, below 640px the message and actions stack, with 8px between them, 16px side padding, and full-width actions. From 640px they sit on one row, centered, with 16px between them and 24px side padding. Long words in the message wrap.
Use the default outline Button, 28px with 14px text, for the main action, next to a 32px Select when there is a choice. Usesize="sm", 28px with 12px text, for a single light action, like Dismiss. To render no banner, do not mount it.
Compact
<NoticeBanner
compact
aria-label="Integration authorization"
actions={
<Button variant="link" size="sm" aria-haspopup="dialog" onClick={openDetails}>
Fix
</Button>
}
>
<p role="status">Google Calendar needs reauthorization</p>
</NoticeBanner>
<NoticeBanner compact="lg" aria-label="Integration authorization" actions={action}>
<p role="status">{message}</p>
</NoticeBanner>compact keeps the message and actions on one row at every width. The message stays on one line and ends with an ellipsis when it does not fit; the actions never wrap or shrink. Keep it to one short action, and put the details and other controls somewhere it opens, such as a sheet. Use a short message, such as "3 apps need reauthorization".
Pass "sm", "md", or "lg" to be compact only below 640px, 768px, or 1024px. Wider screens get the default layout with the same message and actions. To show different content on small screens, render a second banner with your own media query. The cut-off text stays in the page, so screen readers read all of it.
Choosing and waiting
<NoticeBanner
aria-label="Integration authorization"
actions={<>
<div className="w-full sm:w-64">
<Select value={selected.id} onValueChange={choose} disabled={busy}>
<SelectTrigger width="full" aria-label="Integration to reauthorize">
<SelectValue>{selected.name}</SelectValue>
</SelectTrigger>
<SelectContent>
{items.map(item => (
<SelectItem key={item.id} value={item.id}>{item.name}</SelectItem>
))}
</SelectContent>
</Select>
</div>
<Button variant="outline" disabled={busy} focusableWhenDisabled aria-busy={busy}>
{busy ? "Please wait..." : failed ? "Check integration status" : "Update permissions"}
</Button>
</>}
>
{failed
? <p role="alert">Authorization could not be opened. Check integration status before trying again.</p>
: <p role="status">…</p>}
</NoticeBanner>When several items need action, put a Select before the button. Give its wrapper a full width on small screens and 16rem from 640px. While work runs, disable the select and button and set aria-busy. Add focusableWhenDisabled so keyboard focus stays on the button.
Accessibility
The banner is a section. Give it an aria-labelso it is a named region that screen reader users can jump to. Put role="status" on a normal message and role="alert" on an error, so changes are announced. All actions are normal controls in tab order.
If an action removes the banner, move focus to a sensible control, as the examples do. The banner fades in over 180ms and does not animate when reduced motion is requested. In forced colors mode the line uses the system text color.
Theme tokens
The background uses --sprout-surface, the line uses --sprout-line, and text uses --sprout-muted. A warning lead can use --sprout-warning. Motion uses --sprout-motion-normal and --sprout-motion-ease.