Alert
Quiet inline notice with a tone (info, success, warning, danger), optional title, description, action and dismiss.
Code
import { Alert } from "@fadymondy/nasaq/web";export function SyncFailed() { return ( <Alert tone="danger" title="Sync failed"> Could not reach the data source. Check the credentials. </Alert> );}Alerts & Notifications · stable
Live examples and controls: Alert in the lab.
Install
npx shadcn@latest add https://docs.nasaqui.com/r/alert.jsonA quiet, inline notice about the content next to it: a draft invoice that was not sent, a failed sync, a plan limit that is close. It sits in the page flow, stays until the situation changes or the user dismisses it, and never interrupts. Each tone has its own glyph, so it reads without colour.
Relationship to Attention. Attention is a sorted list of things the user should act
on across the product ("What needs my attention?"), fed by the product. Alert is one message about the local
context, written by the developer at the spot where it applies. If you have several items to triage, use
Attention; if you have one sentence about this page or form, use Alert.
When to use
- A persistent message tied to a page, card or form: warnings, limits, results, background information.
- Something the user may want to act on, with one action button beside it.
When not to use
- A list of things to do: use
Attention. - A transient confirmation of something the user just did ("Saved"): use
toast. - A field-level validation message: use the
Fielderror slot. - A decision the user must make before continuing: use
AlertDialog. - A status next to a value in a table or header: use
StatusorBadge.
Import
import { Alert } from "@fadymondy/nasaq/web";
// inside this monorepo: "@nasaq/web"Quick start
import { Alert } from "@fadymondy/nasaq/web";
export function SyncFailed() {
return (
<Alert tone="danger" title="Sync failed">
Could not reach the data source. Check the credentials.
</Alert>
);
}Anatomy
Alert role="alert" (warning, danger) or "status" (info, success) data-slot="alert"
├─ icon tone glyph data-slot="alert-icon"
├─ body data-slot="alert-body"
│ ├─ title optional data-slot="alert-title"
│ └─ description children data-slot="alert-description"
└─ actions action and dismiss button data-slot="alert-actions"API
Alert
AlertProps extends ComponentProps<"div"> (without title).
| Prop | Type | Default | Description |
|---|---|---|---|
tone? | "info" | "success" | "warning" | "danger" | "info" | Meaning, glyph and colour. |
title? | ReactNode | none | Short heading. Omit for a one-line notice. |
children? | ReactNode | none | The description. |
icon? | LucideIcon | tone glyph | Replaces the glyph. |
action? | ReactNode | none | One action at the inline end, e.g. <Button size="sm">. |
onDismiss? | () => void | none | Shows a dismiss button; the host hides the alert. |
dismissLabel? | string | "Dismiss" / "تجاهل" by locale | aria-label of the dismiss button. |
role? | AriaRole | "alert" for warning and danger, else "status" | Override the live-region role. |
className? | string | none | Merged onto the root. |
AlertTone is the union of the four tone names.
Examples
With action and dismiss
import { Alert, Button } from "@fadymondy/nasaq/web";
import { useState } from "react";
export function PaymentFailed() {
const [open, setOpen] = useState(true);
if (!open) return null;
return (
<Alert
tone="danger"
title="Payment failed"
action={<Button size="sm">Update card</Button>}
onDismiss={() => setOpen(false)}
>
The account is restricted in 3 days unless it is updated.
</Alert>
);
}Arabic, one line
import { Alert } from "@fadymondy/nasaq/web";
export function DraftInvoice() {
return <Alert tone="warning">هذه الفاتورة مسودة ولم تُرسل بعد.</Alert>;
}Accessibility
warninganddangeruserole="alert": assistive tech announces them immediately when they appear.infoandsuccessuserole="status": announced politely. Override withrole.- Tone is carried by a distinct glyph as well as colour. The glyph is
aria-hidden; put the meaning in the text ("Sync failed", not just red). - The dismiss button is a real
<button>with anaria-label; localisedismissLabelwhen not using the Nasaq provider.
| Key | Action |
|---|---|
Tab | Moves to the action and dismiss buttons. |
Enter / Space | Activates the focused button. |
RTL & i18n
- The grid is icon, body, actions in inline order, so it mirrors in RTL. Text uses
text-start; the action gap usesms-3. - Built-in string: the dismiss label, "Dismiss" or "تجاهل" when the Nasaq locale starts with
ar.
Styling & tokens
- Surface:
bg-nq-{tone}-soft,border-nq-{tone}/30,rounded-card; glyphtext-nq-{tone}-text; text staystext-foreground/text-muted-foreground. - Target
[data-slot=alert],[data-tone=warning],alert-title,alert-description,alert-actions. Extend withclassName.
Do / Don't
- Do say what happened and what to do, in the title or description.
- Do keep one action at most; put the primary next step there.
- Don't stack more than two alerts on a page; a list belongs in
Attention. - Don't use
dangerfor things that are merely unusual.
Related
Lab
https://docs.nasaqui.com/?path=/docs/components-alerts-notifications-alert--docs