Oddmash UI
所有组件

通知提供器

管理独立通知、过期和关闭。

用法

在产品界面中挂载一次 ToastProvider,实际结果出现后调用 useToast 的 showToast。可见通知已满时,新通知排队等待空位。

无障碍

成功使用礼貌通知,错误使用警报,出现时不移动焦点。悬停或聚焦期间暂停过期,关闭后将焦点恢复到剩余通知或原控件。

属性类型默认值
maxVisiblenumber4
dismissLabelstringDismiss notification
showToast(options)ToastNotification → stringRequired title
dismissToast(id)string → voidNone
duration (notification)number | null3000; important states persist
const Controls = () => {
  const { showToast } = useToast();
  return (
    <div>
      <Button onClick={() => showToast({ title: 'Project saved', description: 'Your changes are ready.', tone: 'success' })}>
        Show saved notification
      </Button>
      <Button variant="secondary" onClick={() => showToast({ title: 'Save failed', description: 'Your changes could not be synchronized. Check your network connection and retry when you are ready.', tone: 'error' })}>
        Show error notification
      </Button>
    </div>
  );
};

<ToastProvider maxVisible={2}>
  <Controls />
</ToastProvider>

交互式文档