Default and destructive
The two upstream variants. An icon put first is circled in the alert's marker; the destructive alert is told apart by red hatching in its margin, not by red alone.
A message on a slip of paper, drawn in felt tip. Default and destructive as upstream, plus info, success, warning and a sticky-note variant. Each tone has its own pattern in the margin as well as its own color, and a 16 px icon put first is circled in the tone's marker.
npx shadcn@latest add @wobko/alert第一次使用?先把 registry 加进 components.json。 如何安装
The two upstream variants. An icon put first is circled in the alert's marker; the destructive alert is told apart by red hatching in its margin, not by red alone.
`info`, `success` and `warning` are additions. Each has its own pattern in the margin: a double blue pencil rule, a strip of green marker, a panel of highlighter. Without an icon there is no circle, and without a title the description is one plain line.
`variant="note"` is a sticky note with a taped corner: a Paper, so the sheet turns a little and the text does not. Use it for asides that should not look like system messages.
A real use: the alert leads the card's content, carries an action button of its own (a separate host, with its own ring and hover) and goes away once it is dealt with. It is a live region, so screen readers hear it when it appears.
The shadcn demo. An alert needs no description (icon and a title on one line) and no title (icon and a sentence), and a success message can say everything in three parts. The icon is circled in the alert's own pen.
The smallest destructive alert: an icon, the word Error and one plain sentence. Below it, the same message with the way out built in. Alerts are live regions, so the second one is announced when it appears.
A `role="alert"` grid: an optional icon in the first column, title and description in the second. The box, margin pattern and icon circle are the host's drawing; there is no border, background or radius of its own.
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| variant | "default" | "destructive" | "info" | "success" | "warning" | "note" | "default" | destructive = red felt box, red-pencil hatching in the margin, pale red wash. info = blue felt, double blue-pencil rule. success = green felt, strip of green marker. warning = ink box on a highlighter panel. note = a sticky note with a taped corner (a Paper). |
| seed | string | number | - | Pins the hand: the same seed always draws the same box. Default: derived from useId(). |
CLI 会复制进你项目的文件。
正在加载源码