CLI
手动安装
CLI 将组件源(及其内部依赖项)复制到您的项目中并安装任何所需的 npm 包。
npx boardui@latest add notification使用共享 UI 包或自定义导入别名? 配置您的安装路径 在运行 CLI 之前。复制粘贴示例使用默认导入。
状态
套装 status 信息、成功或错误。每个状态都提供语义活动区域角色、默认图标和强调色。
<Notification status="information" title="New version available" description="Refresh to start using the latest dashboard updates."/>
<Notification status="success" title="Changes saved" description="Your workspace settings have been updated."/>
<Notification status="error" title="Upload failed" description="Check the file size and try again."/>图标和头像
传递任何 Remix 图标 图标,或将图标替换为 avatar。头像通知可以显示在线、忙碌或离线状态。
import { RiSparklingFill } from "@remixicon/react";
{/* Custom icon */}<Notification icon={RiSparklingFill} title="Custom icon" description="Use any Remix icon."/>
{/* Avatar with presence */}<Notification avatar={{ src: "/avatars/livia-saris.webp", alt: "Livia Saris", presence: "busy", }} title="Livia Saris" timestamp="just now" description="Mentioned you in the launch checklist."/>操作按钮
的 actions array 呈现小型 BoardUI 按钮并支持主要、次要和危险变体。
<Notification status="information" title="Backup ready" description="Your latest workspace backup is ready to download." actions={[ { label: "Not now", variant: "secondary", onClick: dismiss }, { label: "Download", variant: "primary", onClick: download }, ]}/>职位
使用 position 支撑 NotificationViewport 将堆栈锚定到浏览器视口的任何角落或水平中心。
import { Notification, NotificationViewport,} from "@/components/base/notification/notification";
<NotificationViewport position="top-center"> <Notification status="information" title="New version available" description="Refresh to start using the latest dashboard updates." /></NotificationViewport>
{/* Available positions: top-left, top-center, top-right, bottom-left, bottom-center, bottom-right */}定时解雇
套装 autoDismissDuration 以毫秒为单位显示同步的 3px 倒计时栏,并在倒计时达到零时关闭通知。使用 NotificationViewport 将重复的通知传送到浏览器视口边缘的平滑动画堆栈。
const [notifications, setNotifications] = useState([]);
function showNotification(variant) { setNotifications((current) => [ ...current, { id: crypto.randomUUID(), variant }, ]);}
<Button onClick={() => showNotification("success")}>Replay notification</Button><Button onClick={() => showNotification("information")}>Information</Button><Button onClick={() => showNotification("error")}>Error</Button><Button onClick={() => showNotification("avatar")}>With avatar</Button><Button onClick={() => showNotification("actions")}>With buttons</Button>
<NotificationViewport> {notifications.map((notification) => ( <Notification {...variants[notification.variant]} key={notification.id} autoDismissDuration={2500} introDelay={0} onDismiss={() => setNotifications((current) => current.filter((item) => item.id !== notification.id) ) } /> ))}</NotificationViewport>