C

Notification 通知提醒

反馈组件

右上角弹出的通知卡片,比 Toast 内容更丰富、驻留更久。

何时使用

需要通知提醒功能时使用本组件。

代码示例

基础用法

tsx
import { Notification } from "@/components/ui/notification"

export function Basic() {
return <Notification />
}

变体

tsx
{/* 展示 variant 变体 */}
<div className="flex flex-wrap items-center gap-3">
<Notification variant="default">Default</Notification>
<Notification variant="info">Info</Notification>
<Notification variant="success">Success</Notification>
<Notification variant="warning">Warning</Notification>
<Notification variant="destructive">Destructive</Notification>
</div>

样式变体

变体

Variant说明默认
default默认样式
info信息提示
success成功状态
warning警告状态
destructive危险/删除样式

API / Props

Notification

PropTypeDefault说明
classNamestring自定义样式类名
titleReact.ReactNodeTitle
descriptionReact.ReactNodeDescription content
openbooleantrueWhether the notification is visible
onClose() => voidCalled when close button is clicked
durationnumber4500Auto-close duration in ms (0 to disable)
iconReact.ReactNodeIcon to show
...restReact.ComponentProps<"div">透传 <div> 原生属性

注意事项

  • Client Component: 使用 "use client",依赖 React hooks/状态,需在客户端渲染。
  • CVA 变体: 通过 class-variance-authority 管理样式变体,类型安全。变体对象可导出复用。
  • 原生属性: 继承所有 <div> 原生 HTML 属性。

📘 完整交互式示例与控件属性请查看 Storybook 文档