Alert
Reports the result of an action or the state of the application. A screen reader announces it when it appears.
Import
Copy code
import { Alert } from '@k8ordo/ui';Usage
Information
Copy code
<Alert message="This is an info alert." tone="info" />Tones
Success
Information
Warning
Error
Copy code
<Alert message="Operation completed successfully." tone="success" />
<Alert message="Here is some useful information." tone="info" />
<Alert message="Please proceed with caution." tone="warning" />
<Alert message="Something went wrong." tone="error" />Multiple messages
Error
- Password must be at least 8 characters.
- Password must include a number.
- Password must include a special character.
Copy code
<Alert
message={[
"Password must be at least 8 characters.",
"Password must include a number.",
"Password must include a special character.",
]}
tone="error"
/>Action link
Information
Warning
Copy code
// Navigation link — the consumer owns the element and its style.
// Use Anchor for a link that matches the library look, or any
// <a> / Next.js Link with your own className.
<Alert
message="A new version is available."
tone="info"
action={{
label: 'Learn more',
renderItem: ({ children }) => (
<Anchor href="https://example.com" openInNewTab>
{children}
</Anchor>
),
}}
/>
// Action button (open a modal, etc.) — style it however you like.
<Alert
message="Your profile setup is incomplete."
tone="warning"
action={{
label: 'Open settings',
renderItem: ({ children }) => (
<button
className={styles.link}
type="button"
onClick={() => {}}
>
{children}
</button>
),
}}
/>Dismissible
Warning
Warning
Copy code
const [isVisible, setIsVisible] = useState(true);
// onClose renders an in-frame close (×) button at the row's end.
<Alert
message="..."
onClose={() => setIsVisible(false)}
tone="warning"
/>
// onClose can be combined with action.
<Alert
action={{
label: 'Learn more',
renderItem: ({ children }) => (
<button className={styles.link} type="button" onClick={openHelp}>
{children}
</button>
),
}}
message="..."
onClose={() => setIsVisible(false)}
tone="warning"
/>Props
message- Type:
string|string[] - Default: -
tone- Type:
Status - Default: -
action?- Type:
AlertAction - Default: -
closeLabel?- Type:
string - Default: -
onClose?- Type:
() => void - Default: -
| Prop | Type | Default |
|---|---|---|
message | string|string[] | - |
tone | Status | - |
action? | AlertAction | - |
closeLabel? | string | - |
onClose? | () => void | - |
Inherited attributes (except the ones set internally): HTMLAttributes<HTMLDivElement>
The wording this component draws (labels, placeholders, and so on) comes from the message dictionary unless a prop sets it. To replace it, see: i18n