Alert
提示条:四种语义配色,可带标题、图标与关闭按钮,危险态自动用 alert 语义播报。
安装
添加组件
pnpm dlx @elyri/cli@latest add alert示例
全部变体
四种语义配色:info / success / warning / danger。
Info
Success
Warning
Danger
import { Alert } from './components/elyri/Alert';
export function Example() {
return (
<div className="demo-ui-stack">
<Alert variant="info" title="Info">
A short supporting message.
</Alert>
<Alert variant="success" title="Success">
A short supporting message.
</Alert>
<Alert variant="warning" title="Warning">
A short supporting message.
</Alert>
<Alert variant="danger" title="Danger">
A short supporting message.
</Alert>
</div>
);
}描边
默认带边框,bordered={false} 可去掉。
Bordered
No border
import { Alert } from './components/elyri/Alert';
export function Example() {
return (
<div className="demo-ui-stack">
<Alert variant="info" title="Bordered">
The default alert keeps its border.
</Alert>
<Alert variant="info" title="No border" bordered={false}>
Set bordered={false} to drop the border.
</Alert>
</div>
);
}强调
accent={false} 关闭强调色,图标与背景转为中性色。
Accent
Neutral
import { Alert } from './components/elyri/Alert';
export function Example() {
return (
<div className="demo-ui-stack">
<Alert variant="success" title="Accent">
Accent coloring is on by default.
</Alert>
<Alert variant="success" title="Neutral" accent={false}>
Set accent={false} for a neutral icon and background.
</Alert>
</div>
);
}可关闭
传入 onClose 后显示关闭按钮,点击即隐藏。
Saved
import { useState } from 'react';
import { Alert } from './components/elyri/Alert';
export function Example() {
const [visible, setVisible] = useState(true);
if (!visible) return null;
return (
<Alert variant="success" title="Saved" onClose={() => setVisible(false)}>
Your changes have been stored.
</Alert>
);
}属性
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
variant | 'info' | 'success' | 'warning' | 'danger' | 'info' | 语义与配色:info / success / warning / danger |
title | ReactNode | — | 标题,省略则只显示内容 |
icon | ReactNode | — | 自定义图标,省略时显示随语义变色的圆点 |
onClose | () => void | — | 传入后显示关闭按钮 |
closeLabel | string | 'Dismiss' | 关闭按钮的无障碍名称,默认 Dismiss |
bordered | boolean | true | 是否显示边框,默认 true |
accent | boolean | true | 是否使用强调色(图标着色与背景染色),默认 true |
children | ReactNode | — | 提示正文 |
...rest | HTMLAttributes | — | 其余属性透传给原生 div |