Alert
Displays a callout for user attention.
Installation
Install the following dependencies:
Set up the token layer and the StyleX compiler, if you have not already. See
Installation. The alert also needs interop.css, which
places the icon and sizes it.
Copy and paste the following code into your project.
Update the import paths to match your project setup.
Usage
Composition
The icon is any svg passed as a direct child. The alert is a three-column
grid, and interop.css places the icon in the first column and the action in
the last. Both columns collapse to nothing when empty.
Basic
A basic alert with an icon, title and description.
Destructive
Use variant="destructive" to create a destructive alert.
Action
Use AlertAction to add a button or other action element to the alert.
Custom colors
Pass xstyle to change the border, background and text colors. Set
--carbon-alert-description in the same block to recolor the description,
which otherwise reads the variant's muted color.
API reference
Pass render to replace a part's element or compose it with another component.
Alert
Renders a div with role="alert". Every part also takes xstyle and
className.
| Prop | Type | Default |
|---|---|---|
variant | "default" | "destructive" | "default" |
alertStyles
The style map behind the component, exported so you can apply the same styles to any element.
| Key | Description |
|---|---|
base | The grid, padding, border and type |
variants | One entry per variant, keyed by its name |
Data attributes
| Attribute | On | Effect |
|---|---|---|
data-slot="alert" | the root | Where interop.css keys the icon's grid slot |
data-variant | the root | Reflects the variant prop |
data-slot="alert-title" | the title | Links inside are underlined by interop.css |
data-slot="alert-description" | the description | Links inside are underlined by interop.css |
data-slot="alert-action" | the action | Targets the action from a parent |
CSS variables
| Variable | On | Effect |
|---|---|---|
--carbon-alert-description | the root | The description's color. Set by the variant, read by the part |