Alert
Display a brief, important message in a way that attracts the user's attention without interrupting the user's task.
Import
tsx
import { Alert } from "@kobalte/pigment";
tsx
import { Alert } from "@kobalte/pigment";
Basic usage
A new software update is available.
tsx
<Alert>A new software update is available.</Alert>
tsx
<Alert>A new software update is available.</Alert>
Customization
Variants
The Alert component comes in two variants: solid
and soft
(default).
A new software update is available.
A new software update is available.
tsx
<Alert variant="solid" status="info">A new software update is available.</Alert><Alert variant="soft" status="info">A new software update is available.</Alert>
tsx
<Alert variant="solid" status="info">A new software update is available.</Alert><Alert variant="soft" status="info">A new software update is available.</Alert>
Status
The Alert component supports six different status which affect the color scheme and default status icon used: success
, info
(default), warning
, danger
and discovery
.
The data has been successfully saved on our server.
A new software update is available.
Your registration token is about to expire.
There was an error processing your request.
Learn about the latest features.
tsx
<Alert variant="soft" status="success">The data has been successfully saved on our server.</Alert><Alert variant="soft" status="info">A new software update is available.</Alert><Alert variant="soft" status="warning">Your registration token is about to expire.</Alert><Alert variant="soft" status="danger">There was an error processing your request.</Alert><Alert variant="soft" status="discovery">Learn about the latest features.</Alert>
tsx
<Alert variant="soft" status="success">The data has been successfully saved on our server.</Alert><Alert variant="soft" status="info">A new software update is available.</Alert><Alert variant="soft" status="warning">Your registration token is about to expire.</Alert><Alert variant="soft" status="danger">There was an error processing your request.</Alert><Alert variant="soft" status="discovery">Learn about the latest features.</Alert>
Sections
Use the leadingSection
and trailingSection
props to append content to either side of the alert.
A new software update is available.
tsx
<Alertvariant="soft"color="info"icon={<RocketIcon />}trailingSection={<CloseButton variant="soft" color="info" size="sm" />}>A new software update is available.</Alert>
tsx
<Alertvariant="soft"color="info"icon={<RocketIcon />}trailingSection={<CloseButton variant="soft" color="info" size="sm" />}>A new software update is available.</Alert>
API Reference
Component identifier
The name Alert
can be used when providing default props and slot classes in the theme.
Props
Prop | Description |
---|---|
variant | "solid" | "soft" default: "soft" The visual style of the alert. |
status | "success" | "info" | "warning" | "danger" | "discovery" default: "info" The status of the alert, which affect the color scheme and default status icon used. |
leadingSection | JSX.Element | ((status) => JSX.Element) The element to show before the alert content. |
trailingSection | JSX.Element | ((status) => JSX.Element) The element to show after the alert content. |
slotClasses | Partial<Record<AlertSlots, string>> Addiitonal CSS classes to be passed to the component slots. |
Slots
Name | CSS selector | Rendered element | Description |
---|---|---|---|
root | .pg-alert-root | div | Root element |
leadingSection | .pg-alert-leading-section | span | Leading section |
trailingSection | .pg-alert-trailing-section | span | Trailing section |