トーストプロバイダー
独立した通知、有効期限、閉じる操作を管理します。
使い方
製品の画面に ToastProvider を一度配置し、実際の結果の後に useToast の showToast を呼び出します。表示枠が埋まると空きができるまで新しい通知を待機させます。
アクセシビリティ
確認は穏やかに、エラーは警告として通知し、表示時にフォーカスを移動しません。ホバーまたはフォーカス中は期限を一時停止し、閉じると残った通知または元の操作にフォーカスを戻します。
| プロパティ | 型 | 既定値 |
|---|---|---|
| maxVisible | number | 4 |
| dismissLabel | string | Dismiss notification |
| showToast(options) | ToastNotification → string | Required title |
| dismissToast(id) | string → void | None |
| duration (notification) | number | null | 3000; 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>