Alert
Inline alerts with four semantic colors, an optional title, icon and close button.
Installation
Add component
pnpm dlx @elyri/cli@latest add alertExamples
Variants
Four semantic colors: info / success / warning / danger.
Info
Success
Warning
Danger
import { Alert } from './components/elyri/Alert';
export function Example() {
return (
<div className="demo-ui-stack">
<Alert variant="info" title="Info">
A short supporting message.
</Alert>
<Alert variant="success" title="Success">
A short supporting message.
</Alert>
<Alert variant="warning" title="Warning">
A short supporting message.
</Alert>
<Alert variant="danger" title="Danger">
A short supporting message.
</Alert>
</div>
);
}Bordered
The border shows by default; set bordered={false} to drop it.
Bordered
No border
import { Alert } from './components/elyri/Alert';
export function Example() {
return (
<div className="demo-ui-stack">
<Alert variant="info" title="Bordered">
The default alert keeps its border.
</Alert>
<Alert variant="info" title="No border" bordered={false}>
Set bordered={false} to drop the border.
</Alert>
</div>
);
}Accent
Set accent={false} for a neutral icon and background.
Accent
Neutral
import { Alert } from './components/elyri/Alert';
export function Example() {
return (
<div className="demo-ui-stack">
<Alert variant="success" title="Accent">
Accent coloring is on by default.
</Alert>
<Alert variant="success" title="Neutral" accent={false}>
Set accent={false} for a neutral icon and background.
</Alert>
</div>
);
}Closable
Pass onClose to render a close button that hides the alert.
Saved
import { useState } from 'react';
import { Alert } from './components/elyri/Alert';
export function Example() {
const [visible, setVisible] = useState(true);
if (!visible) return null;
return (
<Alert variant="success" title="Saved" onClose={() => setVisible(false)}>
Your changes have been stored.
</Alert>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'info' | 'success' | 'warning' | 'danger' | 'info' | Semantic color: info / success / warning / danger |
title | ReactNode | — | Title; omit it to show the message only |
icon | ReactNode | — | Custom icon; falls back to a colored dot |
onClose | () => void | — | Pass a handler to render the close button |
closeLabel | string | 'Dismiss' | Accessible name of the close button, defaults to Dismiss |
bordered | boolean | true | Whether the border shows, defaults to true |
accent | boolean | true | Whether the accent coloring (icon and background) is used, defaults to true |
children | ReactNode | — | Alert message |
...rest | HTMLAttributes | — | Remaining props are forwarded to the native div |