Preview Updated 2026-05-10

Alert

Inline static message bar — 4 tones × 3 variants, with optional title, icon, and close button.

Basic usage

Minimal form — a line of text with a status icon and an optional title.

<CfAlert tone="info" title="A message">Here is some additional context.</CfAlert>
<CfAlert tone="info" title="A message">Here is some additional context.</CfAlert>

Four tones

tone sets the semantic color — info / success / warning / error, mapped to the --status-* tokens. Each tone ships with a matching status icon.

<CfAlert tone="info" title="A message">Blue</CfAlert>
<CfAlert tone="success" title="Saved successfully">Green</CfAlert>
<CfAlert tone="warning" title="Disk space is low">Yellow</CfAlert>
<CfAlert tone="error" title="Cannot connect to the service">Red</CfAlert>
<CfAlert tone="info" title="A message">Blue</CfAlert>
<CfAlert tone="success" title="Saved successfully">Green</CfAlert>
<CfAlert tone="warning" title="Disk space is low">Yellow</CfAlert>
<CfAlert tone="error" title="Cannot connect to the service">Red</CfAlert>

Three variants

variant controls background and border: soft (tinted background, default, most common) / outline (transparent + border, the most restrained) / solid (filled background, the strongest).

<CfAlert tone="success" variant="soft">soft — tinted background</CfAlert>
<CfAlert tone="success" variant="outline">outline — transparent + matching border</CfAlert>
<CfAlert tone="success" variant="solid">solid — filled background</CfAlert>
<CfAlert tone="success" variant="soft">soft</CfAlert>
<CfAlert tone="success" variant="outline">outline</CfAlert>
<CfAlert tone="success" variant="solid">solid</CfAlert>

Close button

closable adds an × button on the right — clicking it removes the alert from the DOM and fires the close / onClose event.

<CfAlert tone="warning" title="Closable" closable>
An × button appears on the right.
</CfAlert>
<CfAlert tone="info" closable>A closable alert without a title.</CfAlert>
<CfAlert tone="warning" title="Closable" closable>
An × button appears on the right.
</CfAlert>
<CfAlert tone="info" closable>A closable alert without a title.</CfAlert>

Hide icon

icon={false} drops the leading status icon — handy in dense text or inline form hints where space is tight.

<CfAlert tone="info" :icon="false" title="No-icon variant">More compact</CfAlert>
<CfAlert tone="success" :icon="false">Just a single line</CfAlert>
<CfAlert tone="info" icon={false} title="No-icon variant">More compact</CfAlert>
<CfAlert tone="success" icon={false}>Just a single line</CfAlert>

API

PropTypeDefaultDescription
tone'info' | 'success' | 'warning' | 'error''info'Semantic color
variant'soft' | 'outline' | 'solid''soft'Visual variant
titlestringBold emphasis title
iconbooleantrueWhether to show the leading status icon
closablebooleanfalseWhether to show the trailing × button

Events:

  • Vue: @close — fires when the user clicks the close button
  • React: onClose — same as above

反馈与讨论

Alert · Discussion

0
0 / 600
一键发送
正在加载评论...