Alert
A message inside the page that tells people something important, and stays until it is dealt with.
import { Alert } from '@halo-ds/react';
When to use it
Use an alert for information people need while they are on a page: a problem to fix, a change to know about, or a success worth confirming. Pick the type for its meaning, the style for how loud it should be, and the layout for where it sits. For short confirmations that disappear, use a Toast; for questions that must be answered, use a Modal.
Do
- Put the alert next to what it is about.
- Say what happened, then what to do next.
- Give an action when there is a fix, like "Update card".
- Show one alert per message; don't stack many.
Don't
- Use an alert for a quick confirmation; use a Toast.
- Rely on colour alone; the icon and words carry the meaning.
- Show several Filled alerts on one page.
- Let people dismiss an error they still have to fix.
Alert, Toast or Modal?
All three show messages. Pick by how long it should stay, and whether people must answer.
- Alert: Stays in the page until it is fixed or dismissed. Doesn't block anything. For problems, warnings and important updates.
- Toast or Modal: Toast: a short confirmation that disappears by itself, like "Changes saved". Modal: a question that must be answered before carrying on. If people can carry on without acting, don't use a Modal.
Props
Alert props
| Prop | Type | What it does | |||
|---|---|---|---|---|---|
type | `AlertType \ | undefined` | Sets the colour and default icon. Figma: Type. | ||
variant | `"soft" \ | "outline" \ | "filled" \ | undefined` | soft is tinted, outline is white with a coloured icon, filled is solid colour. Figma: Style. |
layout | `"inline" \ | "banner" \ | undefined` | inline stacks the text in a box; banner is one row across the top of a page. Figma: Layout. | |
size | `"sm" \ | "md" \ | undefined` | Figma: Size. | |
title (required) | ReactNode | Figma: Title. | |||
description | ReactNode | Supporting text. Figma: Description. | |||
icon | ReactNode | Replaces the type icon, or false to hide it. Figma: L icon. | |||
actions | ReactNode | Buttons, usually one small secondary Button. Figma: Actions. | |||
onClose | `(() => void) \ | undefined` | Shows a close button and calls this when it is pressed. Figma: Show close. | ||
closeLabel | `string \ | undefined` | |||
classNames | `Partial<Record<AlertPart, string>> \ | undefined` | Extra class names for the parts inside the component, by part name, like { header: 'my-header' }. | ||
styles | `Partial<Record<AlertPart, CSSProperties>> \ | undefined` | Inline styles for the parts inside the component, by part name, like { footer: { gap: 4 } }. |
It also takes the usual HTML attributes for its element.
Examples
Overview
import { Alert, Button } from '@halo-ds/react';
export default function Example() {
return (
<div style={{ display: 'grid', gap: 12, width: '100%', maxWidth: 520 }}>
<Alert type="information" title="Your trial ends in 3 days" description="Pick a plan to keep your projects." actions={<Button size="sm">See plans</Button>} />
<Alert type="success" title="Payment received" />
<Alert type="warning" title="Two invites bounced" description="Check the email addresses and try again." />
<Alert type="error" title="Couldn't save" description="Check your connection and try again." />
</div>
);
}
Styles
Soft, outline and filled. Soft is the default and suits most pages.
import { Alert } from '@halo-ds/react';
export default function Demo() {
return (
<div className="demo-stack" style={{ width: '100%', maxWidth: 520 }}>
<Alert variant="soft" type="information" title="Soft" description="The default, for most messages." />
<Alert variant="outline" type="success" title="Outline" description="A quieter border on the page background." />
<Alert variant="filled" type="error" title="Filled" description="For messages that must not be missed." />
</div>
);
}
Small
For tight spaces like a card or a form.
import { Alert, Button } from '@halo-ds/react';
export default function Demo() {
return (
<div style={{ width: '100%', maxWidth: 420 }}>
<Alert size="sm" type="warning" title="Connection lost" description="Changes save when you are back online." actions={<Button variant="secondary" size="xs">Reload</Button>} />
</div>
);
}
Banner
One row across the top of a page.
import { Alert, Button } from '@halo-ds/react';
export default function Demo() {
return (
<div style={{ width: '100%' }}>
<Alert layout="banner" type="information" title="A new version is ready" description="Reload to get the latest features." actions={<Button variant="secondary" size="sm">Reload</Button>} onClose={() => {}} />
</div>
);
}
More: https://halodesignsystem.dev/components/alert