Banner
Top-of-screen announcement bar with four gradient tones and an action that morphs the bar into a confirmation pill.
Banner
Top-of-screen announcement bar with four gradient tones and an action that morphs the bar into a confirmation pill.
Try it: hover the action to see the arrow nudge, then click it — the full-width bar springs into a centered confirmation pill, lingers, and collapses itself away. In dark mode the default surface flips to a white bar.
Installation
Install the component with the Craft-UI Blocks CLI — it drops banner.tsx into your project and wires up its runtime dependencies:
npx mvpblocks add bannerpnpm dlx mvpblocks add banneryarn dlx mvpblocks add bannerbunx mvpblocks add bannerFile Structure
The CLI saves the component to your project's components/ui folder:
Import it from @/components/ui/banner.
Usage
Banner is a client component. Pass an announcement as children, optionally with an action:
import { Banner } from "@/components/ui/banner";
export function Example() {
return (
<Banner actionHref="/changelog" actionLabel="Learn more">
Important message
</Banner>
);
}actionHref renders the action as a link and appends a small arrow that nudges right on hover. Omit it to render a plain button driven by onAction instead.
Variants
Four gradient tones, each with a matching icon and white text plus a looping light sheen:
<Banner>Important message</Banner>
<Banner variant="info">New integration is live</Banner>
<Banner variant="success">Deployment finished successfully</Banner>
<Banner variant="error">Something went wrong</Banner>The default tone is an inverted near-black bar that flips to white in dark mode; info sweeps sky to indigo, success emerald to teal, and error rose to red.
Morphing
Flip the action into a confirmation pill with morphMessage — after the action is clicked, the full-width bar shrinks and rounds into a centered pill, then dismisses itself:
"use client";
import { Banner } from "@/components/craft-blocks/blocks/banner";
export function MorphExample() {
return (
<Banner
actionLabel="Enable"
onAction={() => undefined}
morphMessage="Feature enabled"
>
Enable the new dashboard
</Banner>
);
}The pill stays on screen for morphDuration (default 2400 ms) before the banner dismisses itself. Pass morphDuration={0} to keep the pill until the user or a parent closes it via the controlled open prop.
Props
Prop
Type
Animations
- Bar → pill morph: a single bouncy-but-controlled spring (
stiffness: 320) drives the layout animation as the bar melts into a centered pill, while the content crossfades through a short blur. - Dismiss collapse: the banner's height collapses to zero with a
0.45sease-out, so content below slides up smoothly. - Light sheen: a subtle white band glides across the gradient surface on a slow, constant 6s loop.
- Reduced motion: every animation honors
prefers-reduced-motion— the morph, collapse, and tap-scale all run instantly.
Registry Bundle
Install the exact registry entry when you want banner.tsx and its declared runtime dependencies together. Dependencies: motion, lucide-react.
Contact
If you find any bug or issue, feel free to raise an issue.
Last updated on