unstable_Banner API
- Component status:
-
unstable
Import
Section titled “Import”import { unstable_Banner as Banner } from "@stratakit/structures";// ORimport * as Banner from "@stratakit/structures/unstable_Banner";Banner (default)
Section titled “Banner (default)”A banner to highlight information and also optionally provide actions. The information could be very important (like a call to action) or reasonably import (like a status message).
Example:
<Banner label="Label" message="Message" icon={placeholderIcon} onDismiss={() => {}} />string | Element (required) The label of the banner.
Either pass a string or a <VisuallyHidden> component if you don’t want the label to be visible.
message
Section titled “message”ReactNode (required) The message content of the banner.
actions
Section titled “actions”ReactNode (optional) The actions available for the banner.
Example with one action:
actions={<Button key={…} onClick={}>Action</Button>}Example with two Buttons:
actions={ <> <Button key={…} onClick={…}>Action 1</Button>, <Button key={…} onClick={…}>Action 2</Button>, </>}Example with two Anchors as Button:
actions={ <> <Anchor key={…} render={<button />} onClick={…}>Action 1</Anchor>, <Anchor key={…} render={<button />} onClick={…}>Action 2</Anchor>, </>}string | Element | undefined (optional) A static icon decoration for the banner.
Can be a URL of an SVG from the @stratakit/icons package, or a custom JSX icon.
- If no
iconis passed and thetoneis"neutral", no icon is shown. - If no
iconis passed and thetoneis not"neutral", the status icon is shown.
onDismiss
Section titled “onDismiss”(() => void) | undefined (optional) undefined Callback invoked when the dismiss (”❌”) button is clicked.
If undefined, the dismiss button will not be rendered.
render
Section titled “render”(props: P) => React.ReactNode | React.ReactElement | undefined (optional) Allows the component to be rendered as a different HTML element or React component. The value can be a React element or a function that takes in the original component props and gives back a React element with the props merged.
Check out the Composition guide for more details.
"neutral" | "info" | "positive" | "attention" | "critical" | undefined (optional) "neutral" The tone of the banner.
variant
Section titled “variant”"outline" | undefined (optional) "outline" The variant of the banner.
Banner.Root
Section titled “Banner.Root”A banner to highlight information and also optionally provide actions. The information could be very important (like a call to action) or reasonably import (like a status message).
Example:
<Banner.Root tone="info" variant="outline"> <Banner.Icon /> <Banner.Label>Label</Banner.Label> <Banner.Message>Message</Banner.Message> <Banner.DismissButton onClick={onDismiss} /></Banner.Root>"neutral" | "info" | "positive" | "attention" | "critical" | undefined (optional) "neutral" The tone of the banner.
variant
Section titled “variant”"outline" | undefined (optional) "outline" The variant of the banner.
Additional props
Section titled “Additional props”Banner.Icon
Section titled “Banner.Icon”A static icon decoration for the banner.
- If no
hrefis passed and thetoneis"neutral", no icon is shown. - If no
hrefis passed and thetoneis not"neutral", the status icon is shown.
Example with default status icon:
<Banner.Root tone="info"> <Banner.Icon /></Banner.Root>
Example with custom icon:```tsximport svgPlaceholder from "@stratakit/icons/placeholder.svg";
<Banner.Root> <Banner.Icon href={svgPlaceholder} /></Banner.Root>string | undefined (optional) Alternative text describing the icon.
When this prop is passed, the SVG gets rendered as role="img" and labelled
using the provided text.
This prop is not required if the icon is purely decorative. By default, the icon will be hidden from the accessibility tree.
string | undefined (optional) URL of the .svg file (e.g. from @stratakit/icons).
The URL can contain a hash pointing to a specific symbol within the SVG (e.g. #icon, #icon-large).
By default, the #icon symbol is used if no hash is provided.
Note: The .svg must be an external HTTP resource for it to be processed by
the <use> element. As a fallback, JS will be used to fetch the SVG from
non-supported URLs; the fetched SVG content will be sanitized using the
unstable_htmlSanitizer function passed to <Root>.
Key | null | undefined (optional) Ref<HTMLElement | SVGSVGElement> | undefined (optional) Allows getting a ref to the component instance.
Once the component unmounts, React will set ref.current to null
(or call the ref with null if you passed a callback ref).
render
Section titled “render”(props: P) => React.ReactNode | React.ReactElement | undefined (optional) Allows the component to be rendered as a different HTML element or React component. The value can be a React element or a function that takes in the original component props and gives back a React element with the props merged.
Check out the Composition guide for more details.
"regular" | "large" | undefined (optional) Size of the icon. This only affects the icon’s physical dimensions (not the SVG contents).
Defaults to "regular" (16px) and can be optionally set to "large" (24px).
Banner.Label
Section titled “Banner.Label”The label of the banner.
Pass render={<VisuallyHidden />} if you don’t want the label to be visible.
Example:
<Banner.Root> <Banner.Label>Label</Banner.Label></Banner.Root>Example with a visually hidden label:
<Banner.Root> <Banner.Label render={<VisuallyHidden />}>Label</Banner.Label></Banner.Root>Additional props
Section titled “Additional props”Banner.Message
Section titled “Banner.Message”The message content of the banner.
Example:
<Banner.Root> <Banner.Message>Message content goes here.</Banner.Message></Banner.Root>Additional props
Section titled “Additional props”Banner.Actions
Section titled “Banner.Actions”The actions available for the banner.
Example with one action:
<Banner.Root> <Banner.Actions> <Button key={…} onClick={…}>Action</Button> </Banner.Actions></Banner.Root>Example with two Buttons:
<Banner.Root> <Banner.Actions> <Button key={…} onClick={…}>Action 1</Button> <Button key={…} onClick={…}>Action 2</Button> </Banner.Actions></Banner.Root>Example with two Anchors as Button:
<Banner.Root> <Banner.Actions> <Anchor key={…} render={<button />} onClick={…}>Action 1</Anchor>, <Anchor key={…} render={<button />} onClick={…}>Action 2</Anchor>, </Banner.Actions></Banner.Root>Additional props
Section titled “Additional props”Banner.DismissButton
Section titled “Banner.DismissButton”Dismiss (”❌”) button for the banner.
Handle the onClick callback to dismiss the banner.
Example:
<Banner.Root> <Banner.DismissButton onClick={() => {}} /></Banner.Root>string | undefined (optional) "Dismiss" Label for the dismiss button.
The final accessible name of the dismiss button is a combination of this label and the text content of Banner.Label.