Component reference
Banner
A dismissible application-wide message.
Preview
Live previewOptional six-digit hex. Clear to restore the preset. Check contrast with your brand color.
Changes apply to this preview only.
Width adapts to the available space
"use client";
import { useState } from "react";
import { Button, Banner, type PimoluBannerVariant } from "@pimolu/react";
function BannerIcon({ variant, }: {
variant: PimoluBannerVariant;
}) {
const common = {
viewBox: "0 0 24 24",
fill: "none",
stroke: "currentColor",
strokeWidth: 1.8,
strokeLinecap: "round" as const,
strokeLinejoin: "round" as const,
"aria-hidden": true,
focusable: false,
};
if(variant === "success") {
return (
<svg {...common}>
<path d="M4 12.5 9 17.5 20 6.5" />
</svg>
);
}
if(variant === "warning") {
return (
<svg {...common}>
<path
d="M10.3 4.3 2.8 17a2 2 0 0 0 1.7 3h15a2 2 0 0 0 1.7-3L13.7 4.3a2 2 0 0 0-3.4 0Z"
/>
<path d="M12 9v4" />
<path d="M12 17h.01" />
</svg>
);
}
if(variant === "danger") {
return (
<svg {...common}>
<circle cx="12" cy="12" r="9" />
<path d="m9 9 6 6" />
<path d="m15 9-6 6" />
</svg>
);
}
if(variant === "neutral") {
return (
<svg {...common}>
<path d="M5 21V8l7-5 7 5v13" />
<path d="M9 21v-6h6v6" />
</svg>
);
}
return (
<svg {...common}>
<circle cx="12" cy="12" r="9" />
<path d="M12 11v5" />
<path d="M12 7.5h.01" />
</svg>
);
}
function DismissibleBannerDemo() {
const [visible, setVisible] = useState(true);
if(!visible) {
return (
<div className="flex flex-wrap items-center gap-3 min-w-0">
<span className="text-sm text-muted leading-relaxed">The banner has been dismissed.</span>
<Button size="sm" appearance="outline" onClick={() => setVisible(true)}>Show it again</Button>
</div>
);
}
return (
<Banner
variant="success"
icon={<BannerIcon variant="success" />}
title="Your workspace is on the Pro plan"
description="The upgrade is active for every member, with no restart required."
onDismiss={() => setVisible(false)}
/>
);
}
export function DemoExample() {
return (<DismissibleBannerDemo />);
}More examples
Different configurations and compositions using the real Pimolu API. Each preview runs independently and follows the site appearance.
Variants
Each tone tints the whole surface and colours the icon.
Sticky
sticky keeps the banner at the top of its scrolling container; the page shell provides the offset in a real app.
Examples
A banner belongs to the page shell, above the content it qualifies.
Usage
Keep persistent critical notices discoverable after dismissal and store dismissal preferences deliberately.
API reference
Generated from the public TypeScript declarations. Native HTML attributes are inherited where the component extends them; this reference includes Pimolu props and selected common native attributes.
PimoluBannerProps
Type source| Name | Type | Default | Description |
|---|---|---|---|
variant | "neutral" | "success" | "warning" | "danger" | "info" | undefined | "info" | Semantic tone of the page-level message. |
titleRequired | ReactNode | — | Short, emphasised summary. |
description | ReactNode | — | Optional supporting text. |
actions | ReactNode | — | Action buttons or links rendered below the description. |
dismissible | boolean | undefined | true when onDismiss is provided | Shows an accessible close button. Defaults to true when onDismiss is provided. The component is controlled: hide it when the callback fires. |
onDismiss | (() => void) | undefined | — | Public Pimolu prop; see the source declaration for details. |
dismissLabel | string | undefined | "Dismiss banner" | Accessible name of the close button. |
icon | ReactNode | — | Decorative leading icon, hidden from assistive technology. |
sticky | boolean | undefined | false | Sticks the banner to the top of its scrolling container. |
role | AriaRole | undefined | "alert" for danger and "status" for every other variant | Explicit landmark role. Defaults to "alert" for danger and "status" for every other variant. |
onChange | ChangeEventHandler<HTMLDivElement, Element> | undefined | — | Standard React/HTML attribute. |
defaultValue | string | number | readonly string[] | undefined | — | Standard React/HTML attribute. |
className | string | undefined | — | Standard React/HTML attribute. |
style | CSSProperties | undefined | — | Standard React/HTML attribute. |
aria-label | string | undefined | — | Defines a string value that labels the current element. |
onClick | MouseEventHandler<HTMLDivElement> | undefined | — | Standard React/HTML attribute. |
variant"neutral" | "success" | "warning" | "danger" | "info" | undefinedDefault: "info"
Semantic tone of the page-level message.
titleRequiredReactNodeNo default extracted.
Short, emphasised summary.
descriptionReactNodeNo default extracted.
Optional supporting text.
actionsReactNodeNo default extracted.
Action buttons or links rendered below the description.
dismissibleboolean | undefinedDefault: true when onDismiss is provided
Shows an accessible close button. Defaults to true when onDismiss is provided. The component is controlled: hide it when the callback fires.
onDismiss(() => void) | undefinedNo default extracted.
Public Pimolu prop; see the source declaration for details.
dismissLabelstring | undefinedDefault: "Dismiss banner"
Accessible name of the close button.
iconReactNodeNo default extracted.
Decorative leading icon, hidden from assistive technology.
stickyboolean | undefinedDefault: false
Sticks the banner to the top of its scrolling container.
roleAriaRole | undefinedDefault: "alert" for danger and "status" for every other variant
Explicit landmark role. Defaults to "alert" for danger and "status" for every other variant.
onChangeChangeEventHandler<HTMLDivElement, Element> | undefinedNo default extracted.
Standard React/HTML attribute.
defaultValuestring | number | readonly string[] | undefinedNo default extracted.
Standard React/HTML attribute.
classNamestring | undefinedNo default extracted.
Standard React/HTML attribute.
styleCSSProperties | undefinedNo default extracted.
Standard React/HTML attribute.
aria-labelstring | undefinedNo default extracted.
Defines a string value that labels the current element.
onClickMouseEventHandler<HTMLDivElement> | undefinedNo default extracted.
Standard React/HTML attribute.
Accessibility
- Choose announcement urgency carefully and give the dismiss action a clear name.