Alert
A message that stays in the page, with a mark for its kind and, if it needs them, an action and a close.
Consent form missing
Installation
pnpm dlx @human-kit/design add alertnpx @human-kit/design add alertyarn dlx @human-kit/design add alertbunx @human-kit/design add alertThe command copies the files to src/lib/components/ui/alert. It also
installs the packages that the files import.
Usage
<script lang="ts">
import * as Alert from '$lib/components/ui/alert';
</script>
<Alert.Root tone="warning" title="Consent form missing">
It is needed before the procedure.
</Alert.Root> Examples
In answer to the user
A message that appears after an action goes inside an element with role="status" that is already in the page, so a screen reader hears it arrive. Use role="alert" instead only for what cannot wait.
Guidelines
- Use an alert for what the page says about itself and stays true while the page is open: a missing form, an account on hold. For what just happened, use a toast.
- Use
outline, a white card with a coloured mark, for most messages. Usesoft, the tone’s fill and line, for the one that must be seen before the rest of the page. - Pick the tone from what the message means:
dangerfor an error that blocks,warningfor one that will,successfor a task done,infoandneutralfor the rest. - Give a
titlethat says the matter in a few words, and the words under it that say what to do. Keepactionsto one or two small buttons. - Pass
onDismissonly when the message can go away without being dealt with.
Accessibility
- The alert has no live role of its own: a message in the page from the start is read with the page, not announced once more on each change.
- For a message shown in answer to the user, give it a live region:
role="status", orrole="alert"when it is urgent. - The mark is hidden from screen readers; the title and the words say the tone. Do not rely on the colour alone.
- The close button is a
<button>named bydismissLabel, "Dismiss" by default. After it closes the alert, move the focus somewhere that makes sense.
API reference
| Prop | Type | Default |
|---|---|---|
variant | 'outline' | 'soft' A white card, or the tone’s fill and line. | 'outline' |
tone | 'neutral' | 'info' | 'success' | 'warning' | 'danger' What kind of message it is. It sets the mark, and the fill of | 'neutral' |
title | string The first line, in full ink. | — |
children | Snippet The words under the title. | — |
actions | Snippet Buttons under the words. Use small ones: | — |
icon | Snippet Your own mark in place of the tone’s. | — |
onDismiss | () => void Called by the close button. Without it, there is no close button. | — |
dismissLabel | string The name of the close button, read aloud. | 'Dismiss' |
Plus every attribute of a <div>, but title, which is the heading of the alert here.