@dowel-ui/react 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/blocks/admin-users/meta.js +27 -0
- package/dist/blocks/admin-users/meta.js.map +1 -0
- package/dist/blocks/ai-chat/meta.js +30 -0
- package/dist/blocks/ai-chat/meta.js.map +1 -0
- package/dist/blocks/dashboard/meta.js +23 -0
- package/dist/blocks/dashboard/meta.js.map +1 -0
- package/dist/blocks/forgot-password/meta.js +24 -0
- package/dist/blocks/forgot-password/meta.js.map +1 -0
- package/dist/blocks/login/meta.js +26 -0
- package/dist/blocks/login/meta.js.map +1 -0
- package/dist/blocks/pricing/meta.js +24 -0
- package/dist/blocks/pricing/meta.js.map +1 -0
- package/dist/blocks/settings/meta.js +29 -0
- package/dist/blocks/settings/meta.js.map +1 -0
- package/dist/blocks/signup/meta.js +25 -0
- package/dist/blocks/signup/meta.js.map +1 -0
- package/dist/components/accordion/accordion.d.ts +19 -0
- package/dist/components/accordion/accordion.d.ts.map +1 -0
- package/dist/components/accordion/accordion.js +58 -0
- package/dist/components/accordion/accordion.js.map +1 -0
- package/dist/components/accordion/index.d.ts +2 -0
- package/dist/components/accordion/index.js +2 -0
- package/dist/components/accordion/meta.js +17 -0
- package/dist/components/accordion/meta.js.map +1 -0
- package/dist/components/activity-feed/activity-feed.d.ts +39 -0
- package/dist/components/activity-feed/activity-feed.d.ts.map +1 -0
- package/dist/components/activity-feed/activity-feed.js +77 -0
- package/dist/components/activity-feed/activity-feed.js.map +1 -0
- package/dist/components/activity-feed/index.d.ts +2 -0
- package/dist/components/activity-feed/index.js +2 -0
- package/dist/components/activity-feed/meta.js +17 -0
- package/dist/components/activity-feed/meta.js.map +1 -0
- package/dist/components/ai-agent-status/ai-agent-status.d.ts +30 -0
- package/dist/components/ai-agent-status/ai-agent-status.d.ts.map +1 -0
- package/dist/components/ai-agent-status/ai-agent-status.js +43 -0
- package/dist/components/ai-agent-status/ai-agent-status.js.map +1 -0
- package/dist/components/ai-agent-status/index.d.ts +2 -0
- package/dist/components/ai-agent-status/index.js +2 -0
- package/dist/components/ai-agent-status/meta.js +17 -0
- package/dist/components/ai-agent-status/meta.js.map +1 -0
- package/dist/components/ai-conversation/ai-conversation.d.ts +45 -0
- package/dist/components/ai-conversation/ai-conversation.d.ts.map +1 -0
- package/dist/components/ai-conversation/ai-conversation.js +138 -0
- package/dist/components/ai-conversation/ai-conversation.js.map +1 -0
- package/dist/components/ai-conversation/index.d.ts +2 -0
- package/dist/components/ai-conversation/index.js +2 -0
- package/dist/components/ai-conversation/meta.js +17 -0
- package/dist/components/ai-conversation/meta.js.map +1 -0
- package/dist/components/ai-message/ai-message.d.ts +56 -0
- package/dist/components/ai-message/ai-message.d.ts.map +1 -0
- package/dist/components/ai-message/ai-message.js +90 -0
- package/dist/components/ai-message/ai-message.js.map +1 -0
- package/dist/components/ai-message/index.d.ts +2 -0
- package/dist/components/ai-message/index.js +2 -0
- package/dist/components/ai-message/meta.js +17 -0
- package/dist/components/ai-message/meta.js.map +1 -0
- package/dist/components/ai-model-selector/ai-model-selector.d.ts +42 -0
- package/dist/components/ai-model-selector/ai-model-selector.d.ts.map +1 -0
- package/dist/components/ai-model-selector/ai-model-selector.js +48 -0
- package/dist/components/ai-model-selector/ai-model-selector.js.map +1 -0
- package/dist/components/ai-model-selector/index.d.ts +2 -0
- package/dist/components/ai-model-selector/index.js +2 -0
- package/dist/components/ai-model-selector/meta.js +17 -0
- package/dist/components/ai-model-selector/meta.js.map +1 -0
- package/dist/components/ai-prompt-input/ai-prompt-input.d.ts +61 -0
- package/dist/components/ai-prompt-input/ai-prompt-input.d.ts.map +1 -0
- package/dist/components/ai-prompt-input/ai-prompt-input.js +170 -0
- package/dist/components/ai-prompt-input/ai-prompt-input.js.map +1 -0
- package/dist/components/ai-prompt-input/index.d.ts +2 -0
- package/dist/components/ai-prompt-input/index.js +2 -0
- package/dist/components/ai-prompt-input/meta.js +17 -0
- package/dist/components/ai-prompt-input/meta.js.map +1 -0
- package/dist/components/ai-reasoning/ai-reasoning.d.ts +24 -0
- package/dist/components/ai-reasoning/ai-reasoning.d.ts.map +1 -0
- package/dist/components/ai-reasoning/ai-reasoning.js +64 -0
- package/dist/components/ai-reasoning/ai-reasoning.js.map +1 -0
- package/dist/components/ai-reasoning/index.d.ts +2 -0
- package/dist/components/ai-reasoning/index.js +2 -0
- package/dist/components/ai-reasoning/meta.js +17 -0
- package/dist/components/ai-reasoning/meta.js.map +1 -0
- package/dist/components/ai-response/ai-response.d.ts +36 -0
- package/dist/components/ai-response/ai-response.d.ts.map +1 -0
- package/dist/components/ai-response/ai-response.js +46 -0
- package/dist/components/ai-response/ai-response.js.map +1 -0
- package/dist/components/ai-response/index.d.ts +2 -0
- package/dist/components/ai-response/index.js +2 -0
- package/dist/components/ai-response/meta.js +17 -0
- package/dist/components/ai-response/meta.js.map +1 -0
- package/dist/components/ai-sources/ai-sources.d.ts +44 -0
- package/dist/components/ai-sources/ai-sources.d.ts.map +1 -0
- package/dist/components/ai-sources/ai-sources.js +112 -0
- package/dist/components/ai-sources/ai-sources.js.map +1 -0
- package/dist/components/ai-sources/index.d.ts +2 -0
- package/dist/components/ai-sources/index.js +2 -0
- package/dist/components/ai-sources/meta.js +17 -0
- package/dist/components/ai-sources/meta.js.map +1 -0
- package/dist/components/ai-token-usage/ai-token-usage.d.ts +34 -0
- package/dist/components/ai-token-usage/ai-token-usage.d.ts.map +1 -0
- package/dist/components/ai-token-usage/ai-token-usage.js +58 -0
- package/dist/components/ai-token-usage/ai-token-usage.js.map +1 -0
- package/dist/components/ai-token-usage/index.d.ts +2 -0
- package/dist/components/ai-token-usage/index.js +2 -0
- package/dist/components/ai-token-usage/meta.js +17 -0
- package/dist/components/ai-token-usage/meta.js.map +1 -0
- package/dist/components/ai-tool/ai-tool.d.ts +50 -0
- package/dist/components/ai-tool/ai-tool.d.ts.map +1 -0
- package/dist/components/ai-tool/ai-tool.js +129 -0
- package/dist/components/ai-tool/ai-tool.js.map +1 -0
- package/dist/components/ai-tool/index.d.ts +2 -0
- package/dist/components/ai-tool/index.js +2 -0
- package/dist/components/ai-tool/meta.js +17 -0
- package/dist/components/ai-tool/meta.js.map +1 -0
- package/dist/components/alert/alert.d.ts +32 -0
- package/dist/components/alert/alert.d.ts.map +1 -0
- package/dist/components/alert/alert.js +49 -0
- package/dist/components/alert/alert.js.map +1 -0
- package/dist/components/alert/index.d.ts +2 -0
- package/dist/components/alert/index.js +2 -0
- package/dist/components/alert/meta.js +17 -0
- package/dist/components/alert/meta.js.map +1 -0
- package/dist/components/avatar/avatar.d.ts +23 -0
- package/dist/components/avatar/avatar.d.ts.map +1 -0
- package/dist/components/avatar/avatar.js +44 -0
- package/dist/components/avatar/avatar.js.map +1 -0
- package/dist/components/avatar/index.d.ts +2 -0
- package/dist/components/avatar/index.js +2 -0
- package/dist/components/avatar/meta.js +17 -0
- package/dist/components/avatar/meta.js.map +1 -0
- package/dist/components/badge/badge.d.ts +20 -0
- package/dist/components/badge/badge.d.ts.map +1 -0
- package/dist/components/badge/badge.js +47 -0
- package/dist/components/badge/badge.js.map +1 -0
- package/dist/components/badge/index.d.ts +2 -0
- package/dist/components/badge/index.js +2 -0
- package/dist/components/badge/meta.js +17 -0
- package/dist/components/badge/meta.js.map +1 -0
- package/dist/components/button/button.d.ts +28 -0
- package/dist/components/button/button.d.ts.map +1 -0
- package/dist/components/button/button.js +77 -0
- package/dist/components/button/button.js.map +1 -0
- package/dist/components/button/index.d.ts +2 -0
- package/dist/components/button/index.js +2 -0
- package/dist/components/button/meta.js +17 -0
- package/dist/components/button/meta.js.map +1 -0
- package/dist/components/calendar/calendar.d.ts +16 -0
- package/dist/components/calendar/calendar.d.ts.map +1 -0
- package/dist/components/calendar/calendar.js +70 -0
- package/dist/components/calendar/calendar.js.map +1 -0
- package/dist/components/calendar/index.d.ts +2 -0
- package/dist/components/calendar/index.js +2 -0
- package/dist/components/calendar/meta.js +17 -0
- package/dist/components/calendar/meta.js.map +1 -0
- package/dist/components/card/card.d.ts +23 -0
- package/dist/components/card/card.d.ts.map +1 -0
- package/dist/components/card/card.js +53 -0
- package/dist/components/card/card.js.map +1 -0
- package/dist/components/card/index.d.ts +2 -0
- package/dist/components/card/index.js +2 -0
- package/dist/components/card/meta.js +17 -0
- package/dist/components/card/meta.js.map +1 -0
- package/dist/components/checkbox/checkbox.d.ts +15 -0
- package/dist/components/checkbox/checkbox.d.ts.map +1 -0
- package/dist/components/checkbox/checkbox.js +45 -0
- package/dist/components/checkbox/checkbox.js.map +1 -0
- package/dist/components/checkbox/index.d.ts +2 -0
- package/dist/components/checkbox/index.js +2 -0
- package/dist/components/checkbox/meta.js +17 -0
- package/dist/components/checkbox/meta.js.map +1 -0
- package/dist/components/code-block/code-block.d.ts +46 -0
- package/dist/components/code-block/code-block.d.ts.map +1 -0
- package/dist/components/code-block/code-block.js +110 -0
- package/dist/components/code-block/code-block.js.map +1 -0
- package/dist/components/code-block/index.d.ts +2 -0
- package/dist/components/code-block/index.js +2 -0
- package/dist/components/code-block/meta.js +17 -0
- package/dist/components/code-block/meta.js.map +1 -0
- package/dist/components/combobox/combobox.d.ts +59 -0
- package/dist/components/combobox/combobox.d.ts.map +1 -0
- package/dist/components/combobox/combobox.js +346 -0
- package/dist/components/combobox/combobox.js.map +1 -0
- package/dist/components/combobox/index.d.ts +2 -0
- package/dist/components/combobox/index.js +2 -0
- package/dist/components/combobox/meta.js +17 -0
- package/dist/components/combobox/meta.js.map +1 -0
- package/dist/components/command/command.d.ts +65 -0
- package/dist/components/command/command.d.ts.map +1 -0
- package/dist/components/command/command.js +330 -0
- package/dist/components/command/command.js.map +1 -0
- package/dist/components/command/index.d.ts +2 -0
- package/dist/components/command/index.js +2 -0
- package/dist/components/command/meta.js +17 -0
- package/dist/components/command/meta.js.map +1 -0
- package/dist/components/data-table/data-table.d.ts +91 -0
- package/dist/components/data-table/data-table.d.ts.map +1 -0
- package/dist/components/data-table/data-table.js +263 -0
- package/dist/components/data-table/data-table.js.map +1 -0
- package/dist/components/data-table/index.d.ts +2 -0
- package/dist/components/data-table/index.js +2 -0
- package/dist/components/data-table/meta.js +22 -0
- package/dist/components/data-table/meta.js.map +1 -0
- package/dist/components/date-picker/date-picker.d.ts +31 -0
- package/dist/components/date-picker/date-picker.d.ts.map +1 -0
- package/dist/components/date-picker/date-picker.js +123 -0
- package/dist/components/date-picker/date-picker.js.map +1 -0
- package/dist/components/date-picker/index.d.ts +2 -0
- package/dist/components/date-picker/index.js +2 -0
- package/dist/components/date-picker/meta.js +21 -0
- package/dist/components/date-picker/meta.js.map +1 -0
- package/dist/components/dialog/dialog.d.ts +30 -0
- package/dist/components/dialog/dialog.d.ts.map +1 -0
- package/dist/components/dialog/dialog.js +79 -0
- package/dist/components/dialog/dialog.js.map +1 -0
- package/dist/components/dialog/index.d.ts +2 -0
- package/dist/components/dialog/index.js +2 -0
- package/dist/components/dialog/meta.js +17 -0
- package/dist/components/dialog/meta.js.map +1 -0
- package/dist/components/drawer/drawer.d.ts +32 -0
- package/dist/components/drawer/drawer.d.ts.map +1 -0
- package/dist/components/drawer/drawer.js +153 -0
- package/dist/components/drawer/drawer.js.map +1 -0
- package/dist/components/drawer/index.d.ts +2 -0
- package/dist/components/drawer/index.js +2 -0
- package/dist/components/drawer/meta.js +17 -0
- package/dist/components/drawer/meta.js.map +1 -0
- package/dist/components/dropdown-menu/dropdown-menu.d.ts +43 -0
- package/dist/components/dropdown-menu/dropdown-menu.d.ts.map +1 -0
- package/dist/components/dropdown-menu/dropdown-menu.js +130 -0
- package/dist/components/dropdown-menu/dropdown-menu.js.map +1 -0
- package/dist/components/dropdown-menu/index.d.ts +2 -0
- package/dist/components/dropdown-menu/index.js +2 -0
- package/dist/components/dropdown-menu/meta.js +17 -0
- package/dist/components/dropdown-menu/meta.js.map +1 -0
- package/dist/components/empty-state/empty-state.d.ts +24 -0
- package/dist/components/empty-state/empty-state.d.ts.map +1 -0
- package/dist/components/empty-state/empty-state.js +73 -0
- package/dist/components/empty-state/empty-state.js.map +1 -0
- package/dist/components/empty-state/index.d.ts +2 -0
- package/dist/components/empty-state/index.js +2 -0
- package/dist/components/empty-state/meta.js +17 -0
- package/dist/components/empty-state/meta.js.map +1 -0
- package/dist/components/form/form.d.ts +43 -0
- package/dist/components/form/form.d.ts.map +1 -0
- package/dist/components/form/form.js +127 -0
- package/dist/components/form/form.js.map +1 -0
- package/dist/components/form/index.d.ts +2 -0
- package/dist/components/form/index.js +2 -0
- package/dist/components/form/meta.js +17 -0
- package/dist/components/form/meta.js.map +1 -0
- package/dist/components/input/index.d.ts +2 -0
- package/dist/components/input/index.js +2 -0
- package/dist/components/input/input.d.ts +21 -0
- package/dist/components/input/input.d.ts.map +1 -0
- package/dist/components/input/input.js +34 -0
- package/dist/components/input/input.js.map +1 -0
- package/dist/components/input/meta.js +17 -0
- package/dist/components/input/meta.js.map +1 -0
- package/dist/components/label/index.d.ts +2 -0
- package/dist/components/label/index.js +2 -0
- package/dist/components/label/label.d.ts +14 -0
- package/dist/components/label/label.d.ts.map +1 -0
- package/dist/components/label/label.js +20 -0
- package/dist/components/label/label.js.map +1 -0
- package/dist/components/label/meta.js +17 -0
- package/dist/components/label/meta.js.map +1 -0
- package/dist/components/pagination/index.d.ts +2 -0
- package/dist/components/pagination/index.js +2 -0
- package/dist/components/pagination/meta.js +17 -0
- package/dist/components/pagination/meta.js.map +1 -0
- package/dist/components/pagination/pagination.d.ts +33 -0
- package/dist/components/pagination/pagination.d.ts.map +1 -0
- package/dist/components/pagination/pagination.js +143 -0
- package/dist/components/pagination/pagination.js.map +1 -0
- package/dist/components/popover/index.d.ts +2 -0
- package/dist/components/popover/index.js +2 -0
- package/dist/components/popover/meta.js +17 -0
- package/dist/components/popover/meta.js.map +1 -0
- package/dist/components/popover/popover.d.ts +24 -0
- package/dist/components/popover/popover.d.ts.map +1 -0
- package/dist/components/popover/popover.js +60 -0
- package/dist/components/popover/popover.js.map +1 -0
- package/dist/components/progress/index.d.ts +2 -0
- package/dist/components/progress/index.js +2 -0
- package/dist/components/progress/meta.js +17 -0
- package/dist/components/progress/meta.js.map +1 -0
- package/dist/components/progress/progress.d.ts +21 -0
- package/dist/components/progress/progress.d.ts.map +1 -0
- package/dist/components/progress/progress.js +55 -0
- package/dist/components/progress/progress.js.map +1 -0
- package/dist/components/radio-group/index.d.ts +2 -0
- package/dist/components/radio-group/index.js +2 -0
- package/dist/components/radio-group/meta.js +17 -0
- package/dist/components/radio-group/meta.js.map +1 -0
- package/dist/components/radio-group/radio-group.d.ts +17 -0
- package/dist/components/radio-group/radio-group.d.ts.map +1 -0
- package/dist/components/radio-group/radio-group.js +29 -0
- package/dist/components/radio-group/radio-group.js.map +1 -0
- package/dist/components/select/index.d.ts +2 -0
- package/dist/components/select/index.js +2 -0
- package/dist/components/select/meta.js +17 -0
- package/dist/components/select/meta.js.map +1 -0
- package/dist/components/select/select.d.ts +37 -0
- package/dist/components/select/select.d.ts.map +1 -0
- package/dist/components/select/select.js +128 -0
- package/dist/components/select/select.js.map +1 -0
- package/dist/components/separator/index.d.ts +2 -0
- package/dist/components/separator/index.js +2 -0
- package/dist/components/separator/meta.js +17 -0
- package/dist/components/separator/meta.js.map +1 -0
- package/dist/components/separator/separator.d.ts +15 -0
- package/dist/components/separator/separator.d.ts.map +1 -0
- package/dist/components/separator/separator.js +23 -0
- package/dist/components/separator/separator.js.map +1 -0
- package/dist/components/sheet/index.d.ts +2 -0
- package/dist/components/sheet/index.js +2 -0
- package/dist/components/sheet/meta.js +17 -0
- package/dist/components/sheet/meta.js.map +1 -0
- package/dist/components/sheet/sheet.d.ts +31 -0
- package/dist/components/sheet/sheet.d.ts.map +1 -0
- package/dist/components/sheet/sheet.js +90 -0
- package/dist/components/sheet/sheet.js.map +1 -0
- package/dist/components/skeleton/index.d.ts +2 -0
- package/dist/components/skeleton/index.js +2 -0
- package/dist/components/skeleton/meta.js +17 -0
- package/dist/components/skeleton/meta.js.map +1 -0
- package/dist/components/skeleton/skeleton.d.ts +20 -0
- package/dist/components/skeleton/skeleton.d.ts.map +1 -0
- package/dist/components/skeleton/skeleton.js +29 -0
- package/dist/components/skeleton/skeleton.js.map +1 -0
- package/dist/components/slider/index.d.ts +2 -0
- package/dist/components/slider/index.js +2 -0
- package/dist/components/slider/meta.js +17 -0
- package/dist/components/slider/meta.js.map +1 -0
- package/dist/components/slider/slider.d.ts +29 -0
- package/dist/components/slider/slider.d.ts.map +1 -0
- package/dist/components/slider/slider.js +61 -0
- package/dist/components/slider/slider.js.map +1 -0
- package/dist/components/spinner/index.d.ts +2 -0
- package/dist/components/spinner/index.js +2 -0
- package/dist/components/spinner/meta.js +17 -0
- package/dist/components/spinner/meta.js.map +1 -0
- package/dist/components/spinner/spinner.d.ts +21 -0
- package/dist/components/spinner/spinner.d.ts.map +1 -0
- package/dist/components/spinner/spinner.js +45 -0
- package/dist/components/spinner/spinner.js.map +1 -0
- package/dist/components/switch/index.d.ts +2 -0
- package/dist/components/switch/index.js +2 -0
- package/dist/components/switch/meta.js +17 -0
- package/dist/components/switch/meta.js.map +1 -0
- package/dist/components/switch/switch.d.ts +15 -0
- package/dist/components/switch/switch.d.ts.map +1 -0
- package/dist/components/switch/switch.js +21 -0
- package/dist/components/switch/switch.js.map +1 -0
- package/dist/components/table/index.d.ts +2 -0
- package/dist/components/table/index.js +2 -0
- package/dist/components/table/meta.js +17 -0
- package/dist/components/table/meta.js.map +1 -0
- package/dist/components/table/table.d.ts +41 -0
- package/dist/components/table/table.d.ts.map +1 -0
- package/dist/components/table/table.js +78 -0
- package/dist/components/table/table.js.map +1 -0
- package/dist/components/tabs/index.d.ts +2 -0
- package/dist/components/tabs/index.js +2 -0
- package/dist/components/tabs/meta.js +17 -0
- package/dist/components/tabs/meta.js.map +1 -0
- package/dist/components/tabs/tabs.d.ts +28 -0
- package/dist/components/tabs/tabs.d.ts.map +1 -0
- package/dist/components/tabs/tabs.js +58 -0
- package/dist/components/tabs/tabs.js.map +1 -0
- package/dist/components/toast/index.d.ts +3 -0
- package/dist/components/toast/index.js +3 -0
- package/dist/components/toast/meta.js +17 -0
- package/dist/components/toast/meta.js.map +1 -0
- package/dist/components/toast/toast-store.d.ts +84 -0
- package/dist/components/toast/toast-store.d.ts.map +1 -0
- package/dist/components/toast/toast-store.js +115 -0
- package/dist/components/toast/toast-store.js.map +1 -0
- package/dist/components/toast/toast.d.ts +39 -0
- package/dist/components/toast/toast.d.ts.map +1 -0
- package/dist/components/toast/toast.js +140 -0
- package/dist/components/toast/toast.js.map +1 -0
- package/dist/components/tooltip/index.d.ts +2 -0
- package/dist/components/tooltip/index.js +2 -0
- package/dist/components/tooltip/meta.js +17 -0
- package/dist/components/tooltip/meta.js.map +1 -0
- package/dist/components/tooltip/tooltip.d.ts +24 -0
- package/dist/components/tooltip/tooltip.d.ts.map +1 -0
- package/dist/components/tooltip/tooltip.js +38 -0
- package/dist/components/tooltip/tooltip.js.map +1 -0
- package/dist/index.d.ts +97 -0
- package/dist/index.js +51 -0
- package/dist/lib/styles.d.ts +21 -0
- package/dist/lib/styles.d.ts.map +1 -0
- package/dist/lib/styles.js +22 -0
- package/dist/lib/styles.js.map +1 -0
- package/dist/lib/utils.d.ts +11 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/lib/utils.js +21 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/registry/blocks.d.ts +15 -0
- package/dist/registry/blocks.d.ts.map +1 -0
- package/dist/registry/blocks.js +32 -0
- package/dist/registry/blocks.js.map +1 -0
- package/dist/registry/components.d.ts +18 -0
- package/dist/registry/components.d.ts.map +1 -0
- package/dist/registry/components.js +112 -0
- package/dist/registry/components.js.map +1 -0
- package/dist/registry/schema.d.ts +44 -0
- package/dist/registry/schema.d.ts.map +1 -0
- package/dist/registry/schema.js +33 -0
- package/dist/registry/schema.js.map +1 -0
- package/package.json +74 -0
- package/src/blocks/admin-users/admin-users.stories.tsx +83 -0
- package/src/blocks/admin-users/admin-users.test.tsx +159 -0
- package/src/blocks/admin-users/admin-users.tsx +251 -0
- package/src/blocks/admin-users/index.ts +1 -0
- package/src/blocks/admin-users/meta.ts +27 -0
- package/src/blocks/ai-chat/ai-chat.stories.tsx +149 -0
- package/src/blocks/ai-chat/ai-chat.test.tsx +166 -0
- package/src/blocks/ai-chat/ai-chat.tsx +280 -0
- package/src/blocks/ai-chat/index.ts +7 -0
- package/src/blocks/ai-chat/meta.ts +32 -0
- package/src/blocks/dashboard/dashboard.stories.tsx +106 -0
- package/src/blocks/dashboard/dashboard.test.tsx +94 -0
- package/src/blocks/dashboard/dashboard.tsx +192 -0
- package/src/blocks/dashboard/index.ts +6 -0
- package/src/blocks/dashboard/meta.ts +18 -0
- package/src/blocks/forgot-password/forgot-password.stories.tsx +41 -0
- package/src/blocks/forgot-password/forgot-password.test.tsx +62 -0
- package/src/blocks/forgot-password/forgot-password.tsx +158 -0
- package/src/blocks/forgot-password/index.ts +1 -0
- package/src/blocks/forgot-password/meta.ts +18 -0
- package/src/blocks/login/index.ts +1 -0
- package/src/blocks/login/login.stories.tsx +46 -0
- package/src/blocks/login/login.test.tsx +100 -0
- package/src/blocks/login/login.tsx +178 -0
- package/src/blocks/login/meta.ts +18 -0
- package/src/blocks/pricing/index.ts +1 -0
- package/src/blocks/pricing/meta.ts +18 -0
- package/src/blocks/pricing/pricing.stories.tsx +62 -0
- package/src/blocks/pricing/pricing.test.tsx +101 -0
- package/src/blocks/pricing/pricing.tsx +176 -0
- package/src/blocks/settings/index.ts +6 -0
- package/src/blocks/settings/meta.ts +29 -0
- package/src/blocks/settings/settings.stories.tsx +94 -0
- package/src/blocks/settings/settings.test.tsx +167 -0
- package/src/blocks/settings/settings.tsx +317 -0
- package/src/blocks/signup/index.ts +1 -0
- package/src/blocks/signup/meta.ts +18 -0
- package/src/blocks/signup/signup.stories.tsx +27 -0
- package/src/blocks/signup/signup.test.tsx +97 -0
- package/src/blocks/signup/signup.tsx +240 -0
- package/src/components/accordion/accordion.stories.tsx +90 -0
- package/src/components/accordion/accordion.test.tsx +156 -0
- package/src/components/accordion/accordion.tsx +88 -0
- package/src/components/accordion/index.ts +9 -0
- package/src/components/accordion/meta.ts +16 -0
- package/src/components/activity-feed/activity-feed.stories.tsx +163 -0
- package/src/components/activity-feed/activity-feed.test.tsx +125 -0
- package/src/components/activity-feed/activity-feed.tsx +115 -0
- package/src/components/activity-feed/index.ts +12 -0
- package/src/components/activity-feed/meta.ts +17 -0
- package/src/components/ai-agent-status/ai-agent-status.stories.tsx +86 -0
- package/src/components/ai-agent-status/ai-agent-status.test.tsx +66 -0
- package/src/components/ai-agent-status/ai-agent-status.tsx +88 -0
- package/src/components/ai-agent-status/index.ts +6 -0
- package/src/components/ai-agent-status/meta.ts +17 -0
- package/src/components/ai-conversation/ai-conversation.stories.tsx +126 -0
- package/src/components/ai-conversation/ai-conversation.test.tsx +144 -0
- package/src/components/ai-conversation/ai-conversation.tsx +229 -0
- package/src/components/ai-conversation/index.ts +9 -0
- package/src/components/ai-conversation/meta.ts +20 -0
- package/src/components/ai-message/ai-message.stories.tsx +106 -0
- package/src/components/ai-message/ai-message.test.tsx +160 -0
- package/src/components/ai-message/ai-message.tsx +162 -0
- package/src/components/ai-message/index.ts +13 -0
- package/src/components/ai-message/meta.ts +17 -0
- package/src/components/ai-model-selector/ai-model-selector.stories.tsx +66 -0
- package/src/components/ai-model-selector/ai-model-selector.test.tsx +120 -0
- package/src/components/ai-model-selector/ai-model-selector.tsx +112 -0
- package/src/components/ai-model-selector/index.ts +1 -0
- package/src/components/ai-model-selector/meta.ts +17 -0
- package/src/components/ai-prompt-input/ai-prompt-input.stories.tsx +145 -0
- package/src/components/ai-prompt-input/ai-prompt-input.test.tsx +273 -0
- package/src/components/ai-prompt-input/ai-prompt-input.tsx +306 -0
- package/src/components/ai-prompt-input/index.ts +11 -0
- package/src/components/ai-prompt-input/meta.ts +18 -0
- package/src/components/ai-reasoning/ai-reasoning.stories.tsx +60 -0
- package/src/components/ai-reasoning/ai-reasoning.test.tsx +95 -0
- package/src/components/ai-reasoning/ai-reasoning.tsx +106 -0
- package/src/components/ai-reasoning/index.ts +7 -0
- package/src/components/ai-reasoning/meta.ts +17 -0
- package/src/components/ai-response/ai-response.stories.tsx +75 -0
- package/src/components/ai-response/ai-response.test.tsx +96 -0
- package/src/components/ai-response/ai-response.tsx +95 -0
- package/src/components/ai-response/index.ts +7 -0
- package/src/components/ai-response/meta.ts +17 -0
- package/src/components/ai-sources/ai-sources.stories.tsx +93 -0
- package/src/components/ai-sources/ai-sources.test.tsx +102 -0
- package/src/components/ai-sources/ai-sources.tsx +186 -0
- package/src/components/ai-sources/index.ts +11 -0
- package/src/components/ai-sources/meta.ts +17 -0
- package/src/components/ai-token-usage/ai-token-usage.stories.tsx +59 -0
- package/src/components/ai-token-usage/ai-token-usage.test.tsx +83 -0
- package/src/components/ai-token-usage/ai-token-usage.tsx +105 -0
- package/src/components/ai-token-usage/index.ts +6 -0
- package/src/components/ai-token-usage/meta.ts +16 -0
- package/src/components/ai-tool/ai-tool.stories.tsx +96 -0
- package/src/components/ai-tool/ai-tool.test.tsx +137 -0
- package/src/components/ai-tool/ai-tool.tsx +235 -0
- package/src/components/ai-tool/index.ts +13 -0
- package/src/components/ai-tool/meta.ts +17 -0
- package/src/components/alert/alert.stories.tsx +101 -0
- package/src/components/alert/alert.test.tsx +94 -0
- package/src/components/alert/alert.tsx +89 -0
- package/src/components/alert/index.ts +8 -0
- package/src/components/alert/meta.ts +16 -0
- package/src/components/avatar/avatar.stories.tsx +58 -0
- package/src/components/avatar/avatar.test.tsx +64 -0
- package/src/components/avatar/avatar.tsx +68 -0
- package/src/components/avatar/index.ts +9 -0
- package/src/components/avatar/meta.ts +15 -0
- package/src/components/badge/badge.stories.tsx +68 -0
- package/src/components/badge/badge.test.tsx +61 -0
- package/src/components/badge/badge.tsx +54 -0
- package/src/components/badge/index.ts +1 -0
- package/src/components/badge/meta.ts +15 -0
- package/src/components/button/button.stories.tsx +128 -0
- package/src/components/button/button.test.tsx +224 -0
- package/src/components/button/button.tsx +114 -0
- package/src/components/button/index.ts +1 -0
- package/src/components/button/meta.ts +16 -0
- package/src/components/calendar/calendar.stories.tsx +105 -0
- package/src/components/calendar/calendar.test.tsx +255 -0
- package/src/components/calendar/calendar.tsx +115 -0
- package/src/components/calendar/index.ts +1 -0
- package/src/components/calendar/meta.ts +17 -0
- package/src/components/card/card.stories.tsx +61 -0
- package/src/components/card/card.test.tsx +66 -0
- package/src/components/card/card.tsx +81 -0
- package/src/components/card/index.ts +9 -0
- package/src/components/card/meta.ts +16 -0
- package/src/components/checkbox/checkbox.stories.tsx +124 -0
- package/src/components/checkbox/checkbox.test.tsx +121 -0
- package/src/components/checkbox/checkbox.tsx +66 -0
- package/src/components/checkbox/index.ts +1 -0
- package/src/components/checkbox/meta.ts +16 -0
- package/src/components/code-block/code-block.stories.tsx +62 -0
- package/src/components/code-block/code-block.test.tsx +139 -0
- package/src/components/code-block/code-block.tsx +188 -0
- package/src/components/code-block/index.ts +1 -0
- package/src/components/code-block/meta.ts +17 -0
- package/src/components/combobox/combobox.stories.tsx +171 -0
- package/src/components/combobox/combobox.test.tsx +429 -0
- package/src/components/combobox/combobox.tsx +544 -0
- package/src/components/combobox/index.ts +15 -0
- package/src/components/combobox/meta.ts +17 -0
- package/src/components/command/command.stories.tsx +152 -0
- package/src/components/command/command.test.tsx +380 -0
- package/src/components/command/command.tsx +482 -0
- package/src/components/command/index.ts +17 -0
- package/src/components/command/meta.ts +18 -0
- package/src/components/data-table/data-table.stories.tsx +151 -0
- package/src/components/data-table/data-table.test.tsx +288 -0
- package/src/components/data-table/data-table.tsx +485 -0
- package/src/components/data-table/index.ts +13 -0
- package/src/components/data-table/meta.ts +19 -0
- package/src/components/date-picker/date-picker.stories.tsx +103 -0
- package/src/components/date-picker/date-picker.test.tsx +205 -0
- package/src/components/date-picker/date-picker.tsx +198 -0
- package/src/components/date-picker/index.ts +6 -0
- package/src/components/date-picker/meta.ts +18 -0
- package/src/components/dialog/dialog.stories.tsx +140 -0
- package/src/components/dialog/dialog.test.tsx +186 -0
- package/src/components/dialog/dialog.tsx +132 -0
- package/src/components/dialog/index.ts +16 -0
- package/src/components/dialog/meta.ts +16 -0
- package/src/components/drawer/drawer.stories.tsx +111 -0
- package/src/components/drawer/drawer.test.tsx +187 -0
- package/src/components/drawer/drawer.tsx +293 -0
- package/src/components/drawer/index.ts +16 -0
- package/src/components/drawer/meta.ts +16 -0
- package/src/components/dropdown-menu/dropdown-menu.stories.tsx +128 -0
- package/src/components/dropdown-menu/dropdown-menu.test.tsx +321 -0
- package/src/components/dropdown-menu/dropdown-menu.tsx +242 -0
- package/src/components/dropdown-menu/index.ts +21 -0
- package/src/components/dropdown-menu/meta.ts +17 -0
- package/src/components/empty-state/empty-state.stories.tsx +70 -0
- package/src/components/empty-state/empty-state.test.tsx +97 -0
- package/src/components/empty-state/empty-state.tsx +92 -0
- package/src/components/empty-state/index.ts +9 -0
- package/src/components/empty-state/meta.ts +16 -0
- package/src/components/form/form.stories.tsx +144 -0
- package/src/components/form/form.test.tsx +203 -0
- package/src/components/form/form.tsx +221 -0
- package/src/components/form/index.ts +13 -0
- package/src/components/form/meta.ts +17 -0
- package/src/components/input/index.ts +1 -0
- package/src/components/input/input.stories.tsx +84 -0
- package/src/components/input/input.test.tsx +108 -0
- package/src/components/input/input.tsx +51 -0
- package/src/components/input/meta.ts +15 -0
- package/src/components/label/index.ts +1 -0
- package/src/components/label/label.stories.tsx +51 -0
- package/src/components/label/label.test.tsx +55 -0
- package/src/components/label/label.tsx +26 -0
- package/src/components/label/meta.ts +15 -0
- package/src/components/pagination/index.ts +10 -0
- package/src/components/pagination/meta.ts +17 -0
- package/src/components/pagination/pagination.stories.tsx +129 -0
- package/src/components/pagination/pagination.test.tsx +119 -0
- package/src/components/pagination/pagination.tsx +142 -0
- package/src/components/popover/index.ts +9 -0
- package/src/components/popover/meta.ts +18 -0
- package/src/components/popover/popover.stories.tsx +84 -0
- package/src/components/popover/popover.test.tsx +163 -0
- package/src/components/popover/popover.tsx +89 -0
- package/src/components/progress/index.ts +1 -0
- package/src/components/progress/meta.ts +17 -0
- package/src/components/progress/progress.stories.tsx +90 -0
- package/src/components/progress/progress.test.tsx +78 -0
- package/src/components/progress/progress.tsx +70 -0
- package/src/components/radio-group/index.ts +6 -0
- package/src/components/radio-group/meta.ts +16 -0
- package/src/components/radio-group/radio-group.stories.tsx +102 -0
- package/src/components/radio-group/radio-group.test.tsx +152 -0
- package/src/components/radio-group/radio-group.tsx +53 -0
- package/src/components/select/index.ts +14 -0
- package/src/components/select/meta.ts +16 -0
- package/src/components/select/select.stories.tsx +137 -0
- package/src/components/select/select.test.tsx +209 -0
- package/src/components/select/select.tsx +222 -0
- package/src/components/separator/index.ts +1 -0
- package/src/components/separator/meta.ts +15 -0
- package/src/components/separator/separator.stories.tsx +42 -0
- package/src/components/separator/separator.test.tsx +46 -0
- package/src/components/separator/separator.tsx +33 -0
- package/src/components/sheet/index.ts +14 -0
- package/src/components/sheet/meta.ts +16 -0
- package/src/components/sheet/sheet.stories.tsx +107 -0
- package/src/components/sheet/sheet.test.tsx +152 -0
- package/src/components/sheet/sheet.tsx +160 -0
- package/src/components/skeleton/index.ts +1 -0
- package/src/components/skeleton/meta.ts +15 -0
- package/src/components/skeleton/skeleton.stories.tsx +46 -0
- package/src/components/skeleton/skeleton.test.tsx +57 -0
- package/src/components/skeleton/skeleton.tsx +28 -0
- package/src/components/slider/index.ts +1 -0
- package/src/components/slider/meta.ts +19 -0
- package/src/components/slider/slider.stories.tsx +87 -0
- package/src/components/slider/slider.test.tsx +148 -0
- package/src/components/slider/slider.tsx +135 -0
- package/src/components/spinner/index.ts +1 -0
- package/src/components/spinner/meta.ts +15 -0
- package/src/components/spinner/spinner.stories.tsx +47 -0
- package/src/components/spinner/spinner.test.tsx +41 -0
- package/src/components/spinner/spinner.tsx +68 -0
- package/src/components/switch/index.ts +1 -0
- package/src/components/switch/meta.ts +15 -0
- package/src/components/switch/switch.stories.tsx +70 -0
- package/src/components/switch/switch.test.tsx +101 -0
- package/src/components/switch/switch.tsx +42 -0
- package/src/components/table/index.ts +11 -0
- package/src/components/table/meta.ts +17 -0
- package/src/components/table/table.stories.tsx +131 -0
- package/src/components/table/table.test.tsx +153 -0
- package/src/components/table/table.tsx +138 -0
- package/src/components/tabs/index.ts +11 -0
- package/src/components/tabs/meta.ts +17 -0
- package/src/components/tabs/tabs.stories.tsx +139 -0
- package/src/components/tabs/tabs.test.tsx +148 -0
- package/src/components/tabs/tabs.tsx +106 -0
- package/src/components/toast/index.ts +24 -0
- package/src/components/toast/meta.ts +18 -0
- package/src/components/toast/toast-store.ts +181 -0
- package/src/components/toast/toast.stories.tsx +167 -0
- package/src/components/toast/toast.test.tsx +306 -0
- package/src/components/toast/toast.tsx +241 -0
- package/src/components/tooltip/index.ts +8 -0
- package/src/components/tooltip/meta.ts +17 -0
- package/src/components/tooltip/tooltip.stories.tsx +89 -0
- package/src/components/tooltip/tooltip.test.tsx +120 -0
- package/src/components/tooltip/tooltip.tsx +58 -0
- package/src/index.ts +50 -0
- package/src/lib/styles.ts +26 -0
- package/src/lib/utils.test.ts +32 -0
- package/src/lib/utils.ts +24 -0
- package/src/registry/blocks.ts +30 -0
- package/src/registry/components.ts +114 -0
- package/src/registry/meta.test.ts +234 -0
- package/src/registry/schema.ts +58 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
|
|
3
|
+
import { Button } from "@/components/button";
|
|
4
|
+
|
|
5
|
+
import { Toaster, type ToastPosition } from "./toast";
|
|
6
|
+
import { toast } from "./toast-store";
|
|
7
|
+
|
|
8
|
+
const meta = {
|
|
9
|
+
title: "Feedback/Toast",
|
|
10
|
+
component: Toaster,
|
|
11
|
+
args: { position: "bottom-right" },
|
|
12
|
+
argTypes: {
|
|
13
|
+
position: {
|
|
14
|
+
control: "select",
|
|
15
|
+
options: [
|
|
16
|
+
"top-left",
|
|
17
|
+
"top-center",
|
|
18
|
+
"top-right",
|
|
19
|
+
"bottom-left",
|
|
20
|
+
"bottom-center",
|
|
21
|
+
"bottom-right",
|
|
22
|
+
] satisfies ToastPosition[],
|
|
23
|
+
},
|
|
24
|
+
duration: { control: { type: "number", min: 1000, max: 20000, step: 500 } },
|
|
25
|
+
},
|
|
26
|
+
} satisfies Meta<typeof Toaster>;
|
|
27
|
+
|
|
28
|
+
export default meta;
|
|
29
|
+
type Story = StoryObj<typeof meta>;
|
|
30
|
+
|
|
31
|
+
export const Default: Story = {
|
|
32
|
+
render: (args) => (
|
|
33
|
+
<>
|
|
34
|
+
<Button onClick={() => toast("Project created")}>Show toast</Button>
|
|
35
|
+
<Toaster {...args} />
|
|
36
|
+
</>
|
|
37
|
+
),
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const Variants: Story = {
|
|
41
|
+
render: (args) => (
|
|
42
|
+
<>
|
|
43
|
+
<div className="flex flex-wrap gap-2">
|
|
44
|
+
<Button variant="outline" onClick={() => toast("Saved")}>
|
|
45
|
+
Default
|
|
46
|
+
</Button>
|
|
47
|
+
<Button variant="outline" onClick={() => toast.success("Deployment succeeded")}>
|
|
48
|
+
Success
|
|
49
|
+
</Button>
|
|
50
|
+
<Button variant="outline" onClick={() => toast.info("Build queued")}>
|
|
51
|
+
Info
|
|
52
|
+
</Button>
|
|
53
|
+
<Button variant="outline" onClick={() => toast.warning("Approaching your quota")}>
|
|
54
|
+
Warning
|
|
55
|
+
</Button>
|
|
56
|
+
<Button variant="outline" onClick={() => toast.error("Payment failed")}>
|
|
57
|
+
Error
|
|
58
|
+
</Button>
|
|
59
|
+
</div>
|
|
60
|
+
<Toaster {...args} />
|
|
61
|
+
</>
|
|
62
|
+
),
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const WithDescription: Story = {
|
|
66
|
+
render: (args) => (
|
|
67
|
+
<>
|
|
68
|
+
<Button
|
|
69
|
+
onClick={() =>
|
|
70
|
+
toast.success("Project created", {
|
|
71
|
+
description: "acme-inc is ready. Deploy when you are.",
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
>
|
|
75
|
+
Show toast
|
|
76
|
+
</Button>
|
|
77
|
+
<Toaster {...args} />
|
|
78
|
+
</>
|
|
79
|
+
),
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/** An action needs alt text: "Undo" alone is meaningless once the toast is gone. */
|
|
83
|
+
export const WithAction: Story = {
|
|
84
|
+
render: (args) => (
|
|
85
|
+
<>
|
|
86
|
+
<Button
|
|
87
|
+
onClick={() =>
|
|
88
|
+
toast("Message archived", {
|
|
89
|
+
action: {
|
|
90
|
+
label: "Undo",
|
|
91
|
+
altText: "Undo archiving the message",
|
|
92
|
+
onClick: () => toast.success("Message restored"),
|
|
93
|
+
},
|
|
94
|
+
})
|
|
95
|
+
}
|
|
96
|
+
>
|
|
97
|
+
Archive message
|
|
98
|
+
</Button>
|
|
99
|
+
<Toaster {...args} />
|
|
100
|
+
</>
|
|
101
|
+
),
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const Persistent: Story = {
|
|
105
|
+
render: (args) => (
|
|
106
|
+
<>
|
|
107
|
+
<Button
|
|
108
|
+
variant="outline"
|
|
109
|
+
onClick={() =>
|
|
110
|
+
toast.custom({
|
|
111
|
+
title: "Connection lost",
|
|
112
|
+
description: "Reconnecting…",
|
|
113
|
+
variant: "destructive",
|
|
114
|
+
duration: Infinity,
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
>
|
|
118
|
+
Show until dismissed
|
|
119
|
+
</Button>
|
|
120
|
+
<Toaster {...args} />
|
|
121
|
+
</>
|
|
122
|
+
),
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export const Promise: Story = {
|
|
126
|
+
render: (args) => (
|
|
127
|
+
<>
|
|
128
|
+
<Button
|
|
129
|
+
variant="outline"
|
|
130
|
+
onClick={() => {
|
|
131
|
+
const work = new window.Promise<string>((resolve) => {
|
|
132
|
+
window.setTimeout(() => {
|
|
133
|
+
resolve("acme-inc");
|
|
134
|
+
}, 1500);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
void toast.promise(work, {
|
|
138
|
+
loading: "Creating project…",
|
|
139
|
+
success: (name) => `Created ${name}`,
|
|
140
|
+
error: "Could not create the project",
|
|
141
|
+
});
|
|
142
|
+
}}
|
|
143
|
+
>
|
|
144
|
+
Create project
|
|
145
|
+
</Button>
|
|
146
|
+
<Toaster {...args} />
|
|
147
|
+
</>
|
|
148
|
+
),
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export const Stacking: Story = {
|
|
152
|
+
render: (args) => (
|
|
153
|
+
<>
|
|
154
|
+
<Button
|
|
155
|
+
variant="outline"
|
|
156
|
+
onClick={() => {
|
|
157
|
+
for (let index = 1; index <= 6; index += 1) {
|
|
158
|
+
toast(`Event ${String(index)}`);
|
|
159
|
+
}
|
|
160
|
+
}}
|
|
161
|
+
>
|
|
162
|
+
Raise six toasts
|
|
163
|
+
</Button>
|
|
164
|
+
<Toaster {...args} />
|
|
165
|
+
</>
|
|
166
|
+
),
|
|
167
|
+
};
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { act, render, screen, waitFor } from "@testing-library/react";
|
|
2
|
+
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
import { expectNoA11yViolations } from "../../../test/a11y";
|
|
6
|
+
import { Toaster } from "./toast";
|
|
7
|
+
import { TOAST_LIMIT, resetToasts, toast } from "./toast-store";
|
|
8
|
+
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
act(() => {
|
|
11
|
+
resetToasts();
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
function raise(fn: () => void) {
|
|
16
|
+
act(() => {
|
|
17
|
+
fn();
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe("toast store", () => {
|
|
22
|
+
it("returns the id it created", () => {
|
|
23
|
+
let id = "";
|
|
24
|
+
raise(() => {
|
|
25
|
+
id = toast("Saved");
|
|
26
|
+
});
|
|
27
|
+
expect(id).toMatch(/^toast-\d+$/);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("honours an explicit id, replacing rather than duplicating", async () => {
|
|
31
|
+
render(<Toaster />);
|
|
32
|
+
|
|
33
|
+
raise(() => toast.custom({ id: "sync", title: "Syncing" }));
|
|
34
|
+
expect(await screen.findByText("Syncing")).toBeInTheDocument();
|
|
35
|
+
|
|
36
|
+
raise(() => toast.custom({ id: "sync", title: "Synced" }));
|
|
37
|
+
await waitFor(() => {
|
|
38
|
+
expect(screen.getByText("Synced")).toBeInTheDocument();
|
|
39
|
+
});
|
|
40
|
+
expect(screen.queryByText("Syncing")).not.toBeInTheDocument();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("keeps only the most recent toasts", async () => {
|
|
44
|
+
render(<Toaster />);
|
|
45
|
+
|
|
46
|
+
raise(() => {
|
|
47
|
+
for (let index = 0; index < TOAST_LIMIT + 3; index += 1) {
|
|
48
|
+
toast(`Message ${String(index)}`);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
await waitFor(() => {
|
|
53
|
+
expect(document.querySelectorAll("[data-slot='toast']")).toHaveLength(TOAST_LIMIT);
|
|
54
|
+
});
|
|
55
|
+
expect(screen.queryByText("Message 0")).not.toBeInTheDocument();
|
|
56
|
+
expect(screen.getByText(`Message ${String(TOAST_LIMIT + 2)}`)).toBeInTheDocument();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("calls onDismiss when a toast is removed", () => {
|
|
60
|
+
const onDismiss = vi.fn();
|
|
61
|
+
let id = "";
|
|
62
|
+
raise(() => {
|
|
63
|
+
id = toast.custom({ title: "Saved", onDismiss });
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
raise(() => {
|
|
67
|
+
toast.dismiss(id);
|
|
68
|
+
});
|
|
69
|
+
expect(onDismiss).toHaveBeenCalledWith(id);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("updates a toast in place", async () => {
|
|
73
|
+
render(<Toaster />);
|
|
74
|
+
|
|
75
|
+
let id = "";
|
|
76
|
+
raise(() => {
|
|
77
|
+
id = toast("Uploading");
|
|
78
|
+
});
|
|
79
|
+
await screen.findByText("Uploading");
|
|
80
|
+
|
|
81
|
+
raise(() => {
|
|
82
|
+
toast.update(id, { title: "Uploaded", variant: "success" });
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
await waitFor(() => {
|
|
86
|
+
expect(screen.getByText("Uploaded")).toBeInTheDocument();
|
|
87
|
+
});
|
|
88
|
+
expect(document.querySelector("[data-slot='toast']")).toHaveClass("border-success/30");
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("exposes a helper per variant", async () => {
|
|
92
|
+
render(<Toaster />);
|
|
93
|
+
|
|
94
|
+
raise(() => {
|
|
95
|
+
toast.default("Plain");
|
|
96
|
+
toast.info("Informational");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
expect(await screen.findByText("Plain")).toBeInTheDocument();
|
|
100
|
+
expect(screen.getByText("Informational")).toBeInTheDocument();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("dismisses everything at once", async () => {
|
|
104
|
+
render(<Toaster />);
|
|
105
|
+
|
|
106
|
+
raise(() => {
|
|
107
|
+
toast("One");
|
|
108
|
+
toast("Two");
|
|
109
|
+
});
|
|
110
|
+
await screen.findByText("One");
|
|
111
|
+
|
|
112
|
+
raise(() => {
|
|
113
|
+
toast.dismissAll();
|
|
114
|
+
});
|
|
115
|
+
await waitFor(() => {
|
|
116
|
+
expect(screen.queryByText("One")).not.toBeInTheDocument();
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
describe("promise", () => {
|
|
121
|
+
it("resolves the pending toast into a success toast", async () => {
|
|
122
|
+
render(<Toaster />);
|
|
123
|
+
|
|
124
|
+
let resolve!: (value: string) => void;
|
|
125
|
+
const pending = new Promise<string>((r) => {
|
|
126
|
+
resolve = r;
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
raise(() => {
|
|
130
|
+
void toast.promise(pending, {
|
|
131
|
+
loading: "Saving…",
|
|
132
|
+
success: (value) => `Saved ${value}`,
|
|
133
|
+
error: "Failed",
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
expect(await screen.findByText("Saving…")).toBeInTheDocument();
|
|
138
|
+
|
|
139
|
+
await act(async () => {
|
|
140
|
+
resolve("project");
|
|
141
|
+
await pending;
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
await waitFor(() => {
|
|
145
|
+
expect(screen.getByText("Saved project")).toBeInTheDocument();
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("turns a rejection into an error toast and still rejects", async () => {
|
|
150
|
+
render(<Toaster />);
|
|
151
|
+
|
|
152
|
+
const failure = new Error("network");
|
|
153
|
+
const pending = Promise.reject(failure);
|
|
154
|
+
|
|
155
|
+
let returned!: Promise<never>;
|
|
156
|
+
raise(() => {
|
|
157
|
+
returned = toast.promise(pending, {
|
|
158
|
+
loading: "Saving…",
|
|
159
|
+
success: "Saved",
|
|
160
|
+
error: (error) => `Failed: ${(error as Error).message}`,
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// The original promise is returned untouched, so callers still handle it.
|
|
165
|
+
await expect(returned).rejects.toThrow("network");
|
|
166
|
+
await waitFor(() => {
|
|
167
|
+
expect(screen.getByText("Failed: network")).toBeInTheDocument();
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe("Toaster", () => {
|
|
174
|
+
it("renders nothing until a toast is raised", () => {
|
|
175
|
+
render(<Toaster />);
|
|
176
|
+
expect(document.querySelector("[data-slot='toast']")).not.toBeInTheDocument();
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("renders a title and description", async () => {
|
|
180
|
+
render(<Toaster />);
|
|
181
|
+
raise(() => toast("Project created", { description: "It is ready to use." }));
|
|
182
|
+
|
|
183
|
+
expect(await screen.findByText("Project created")).toBeInTheDocument();
|
|
184
|
+
expect(screen.getByText("It is ready to use.")).toBeInTheDocument();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it.each([
|
|
188
|
+
["success", "border-success/30"],
|
|
189
|
+
["warning", "border-warning/35"],
|
|
190
|
+
["destructive", "border-destructive/30"],
|
|
191
|
+
["info", "border-info/30"],
|
|
192
|
+
] as const)("applies the %s variant", async (variant, expectedClass) => {
|
|
193
|
+
render(<Toaster />);
|
|
194
|
+
raise(() => toast.custom({ title: "Message", variant }));
|
|
195
|
+
await screen.findByText("Message");
|
|
196
|
+
|
|
197
|
+
expect(document.querySelector("[data-slot='toast']")).toHaveClass(expectedClass);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("interrupts for problems and waits for a pause otherwise", async () => {
|
|
201
|
+
render(<Toaster />);
|
|
202
|
+
|
|
203
|
+
raise(() => toast.error("Payment failed"));
|
|
204
|
+
const problem = await screen.findByText("Payment failed");
|
|
205
|
+
expect(problem.closest("[data-slot='toast']")).toHaveAttribute("data-type", "foreground");
|
|
206
|
+
|
|
207
|
+
raise(() => toast.success("Saved"));
|
|
208
|
+
const routine = await screen.findByText("Saved");
|
|
209
|
+
expect(routine.closest("[data-slot='toast']")).toHaveAttribute("data-type", "background");
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("announces a problem assertively through a live region", async () => {
|
|
213
|
+
render(<Toaster />);
|
|
214
|
+
raise(() => toast.error("Payment failed"));
|
|
215
|
+
|
|
216
|
+
const announcement = await screen.findByRole("status");
|
|
217
|
+
expect(announcement).toHaveAttribute("aria-live", "assertive");
|
|
218
|
+
// The primitive mounts the region first and fills it on a later tick.
|
|
219
|
+
await waitFor(() => {
|
|
220
|
+
expect(announcement).toHaveTextContent("Payment failed");
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("dismisses from the close button", async () => {
|
|
225
|
+
const user = userEvent.setup();
|
|
226
|
+
render(<Toaster />);
|
|
227
|
+
raise(() => toast("Saved"));
|
|
228
|
+
await screen.findByText("Saved");
|
|
229
|
+
|
|
230
|
+
await user.click(screen.getByRole("button", { name: "Dismiss" }));
|
|
231
|
+
await waitFor(() => {
|
|
232
|
+
expect(screen.queryByText("Saved")).not.toBeInTheDocument();
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it("runs an action and exposes alt text for screen readers", async () => {
|
|
237
|
+
const onClick = vi.fn();
|
|
238
|
+
const user = userEvent.setup();
|
|
239
|
+
render(<Toaster />);
|
|
240
|
+
|
|
241
|
+
raise(() =>
|
|
242
|
+
toast.custom({
|
|
243
|
+
title: "Message archived",
|
|
244
|
+
action: { label: "Undo", altText: "Undo archiving the message", onClick },
|
|
245
|
+
}),
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
const action = await screen.findByRole("button", { name: "Undo" });
|
|
249
|
+
// The primitive announces the alt text in place of the visible label, since
|
|
250
|
+
// "Undo" alone is meaningless once the toast is gone.
|
|
251
|
+
expect(action).toHaveAttribute(
|
|
252
|
+
"data-radix-toast-announce-alt",
|
|
253
|
+
"Undo archiving the message",
|
|
254
|
+
);
|
|
255
|
+
const announcement = await screen.findByRole("status");
|
|
256
|
+
await waitFor(() => {
|
|
257
|
+
expect(announcement).toHaveTextContent("Undo archiving the message");
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
await user.click(action);
|
|
261
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it("falls back to the action label for alt text", async () => {
|
|
265
|
+
render(<Toaster />);
|
|
266
|
+
raise(() =>
|
|
267
|
+
toast.custom({
|
|
268
|
+
title: "Message archived",
|
|
269
|
+
action: { label: "Undo", onClick: () => undefined },
|
|
270
|
+
}),
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
expect(await screen.findByRole("button", { name: "Undo" })).toHaveAttribute(
|
|
274
|
+
"data-radix-toast-announce-alt",
|
|
275
|
+
"Undo",
|
|
276
|
+
);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it.each([
|
|
280
|
+
["top-left", "top-0"],
|
|
281
|
+
["bottom-right", "bottom-0"],
|
|
282
|
+
["bottom-center", "left-1/2"],
|
|
283
|
+
] as const)("positions the viewport for %s", async (position, expectedClass) => {
|
|
284
|
+
const { baseElement } = render(<Toaster position={position} />);
|
|
285
|
+
raise(() => toast("Message"));
|
|
286
|
+
await screen.findByText("Message");
|
|
287
|
+
|
|
288
|
+
expect(baseElement.querySelector("[data-slot='toast-viewport']")).toHaveClass(
|
|
289
|
+
expectedClass,
|
|
290
|
+
);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("has no accessibility violations", async () => {
|
|
294
|
+
const { baseElement } = render(<Toaster />);
|
|
295
|
+
raise(() =>
|
|
296
|
+
toast.custom({
|
|
297
|
+
title: "Project created",
|
|
298
|
+
description: "It is ready to use.",
|
|
299
|
+
action: { label: "View", onClick: () => undefined },
|
|
300
|
+
}),
|
|
301
|
+
);
|
|
302
|
+
await screen.findByText("Project created");
|
|
303
|
+
|
|
304
|
+
await expectNoA11yViolations(baseElement);
|
|
305
|
+
});
|
|
306
|
+
});
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { cva, type VariantProps } from "class-variance-authority";
|
|
4
|
+
import { Toast as ToastPrimitive } from "radix-ui";
|
|
5
|
+
import type { ComponentPropsWithRef } from "react";
|
|
6
|
+
|
|
7
|
+
import { focusRing } from "@/lib/styles";
|
|
8
|
+
import { cn } from "@/lib/utils";
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
DEFAULT_TOAST_DURATION,
|
|
12
|
+
toast,
|
|
13
|
+
useToasts,
|
|
14
|
+
type ToastRecord,
|
|
15
|
+
type ToastVariant,
|
|
16
|
+
} from "./toast-store";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Brief, non-blocking messages about something that just happened.
|
|
20
|
+
*
|
|
21
|
+
* Render one `<Toaster />` near the root of the app; raise messages from
|
|
22
|
+
* anywhere with `toast()`. The primitive underneath supplies the parts that are
|
|
23
|
+
* easy to get wrong: a screen-reader announcement region, timers that pause on
|
|
24
|
+
* hover, focus and window blur, swipe-to-dismiss, and F8 to jump focus into the
|
|
25
|
+
* toast list from anywhere on the page.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const toastVariants = cva(
|
|
29
|
+
cn(
|
|
30
|
+
"group pointer-events-auto relative flex w-full items-start gap-3 overflow-hidden",
|
|
31
|
+
"rounded-lg border p-4 pr-10 shadow-lg",
|
|
32
|
+
"[--slide-x:calc(100%+1rem)]",
|
|
33
|
+
"data-[state=closed]:animate-float-out data-[state=open]:animate-slide-in",
|
|
34
|
+
"data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none",
|
|
35
|
+
"data-[swipe=cancel]:translate-x-0 data-[swipe=cancel]:transition-transform",
|
|
36
|
+
"data-[swipe=end]:animate-toast-swipe-out",
|
|
37
|
+
),
|
|
38
|
+
{
|
|
39
|
+
variants: {
|
|
40
|
+
variant: {
|
|
41
|
+
default: "border-border bg-popover text-popover-foreground",
|
|
42
|
+
success: "border-success/30 bg-popover text-popover-foreground [&_svg]:text-success",
|
|
43
|
+
warning: "border-warning/35 bg-popover text-popover-foreground [&_svg]:text-warning",
|
|
44
|
+
destructive:
|
|
45
|
+
"border-destructive/30 bg-popover text-popover-foreground [&_svg]:text-destructive",
|
|
46
|
+
info: "border-info/30 bg-popover text-popover-foreground [&_svg]:text-info",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
defaultVariants: {
|
|
50
|
+
variant: "default",
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export const ToastProvider = ToastPrimitive.Provider;
|
|
56
|
+
|
|
57
|
+
export interface ToastProps
|
|
58
|
+
extends
|
|
59
|
+
ComponentPropsWithRef<typeof ToastPrimitive.Root>,
|
|
60
|
+
VariantProps<typeof toastVariants> {}
|
|
61
|
+
|
|
62
|
+
export function Toast({ className, variant, ...props }: ToastProps) {
|
|
63
|
+
return (
|
|
64
|
+
<ToastPrimitive.Root
|
|
65
|
+
data-slot="toast"
|
|
66
|
+
className={cn(toastVariants({ variant }), className)}
|
|
67
|
+
{...props}
|
|
68
|
+
/>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function ToastTitle({
|
|
73
|
+
className,
|
|
74
|
+
...props
|
|
75
|
+
}: ComponentPropsWithRef<typeof ToastPrimitive.Title>) {
|
|
76
|
+
return (
|
|
77
|
+
<ToastPrimitive.Title
|
|
78
|
+
data-slot="toast-title"
|
|
79
|
+
className={cn("text-sm leading-snug font-medium", className)}
|
|
80
|
+
{...props}
|
|
81
|
+
/>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function ToastDescription({
|
|
86
|
+
className,
|
|
87
|
+
...props
|
|
88
|
+
}: ComponentPropsWithRef<typeof ToastPrimitive.Description>) {
|
|
89
|
+
return (
|
|
90
|
+
<ToastPrimitive.Description
|
|
91
|
+
data-slot="toast-description"
|
|
92
|
+
className={cn("text-sm text-muted-foreground", className)}
|
|
93
|
+
{...props}
|
|
94
|
+
/>
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function ToastAction({
|
|
99
|
+
className,
|
|
100
|
+
...props
|
|
101
|
+
}: ComponentPropsWithRef<typeof ToastPrimitive.Action>) {
|
|
102
|
+
return (
|
|
103
|
+
<ToastPrimitive.Action
|
|
104
|
+
data-slot="toast-action"
|
|
105
|
+
className={cn(
|
|
106
|
+
"inline-flex h-8 shrink-0 items-center rounded-md border border-input bg-transparent px-3 text-xs font-medium",
|
|
107
|
+
"transition-colors duration-[var(--duration-fast)] hover:bg-accent hover:text-accent-foreground",
|
|
108
|
+
focusRing,
|
|
109
|
+
className,
|
|
110
|
+
)}
|
|
111
|
+
{...props}
|
|
112
|
+
/>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function ToastClose({
|
|
117
|
+
className,
|
|
118
|
+
...props
|
|
119
|
+
}: ComponentPropsWithRef<typeof ToastPrimitive.Close>) {
|
|
120
|
+
return (
|
|
121
|
+
<ToastPrimitive.Close
|
|
122
|
+
data-slot="toast-close"
|
|
123
|
+
aria-label="Dismiss"
|
|
124
|
+
className={cn(
|
|
125
|
+
"absolute top-3 right-3 grid size-6 place-items-center rounded-md text-muted-foreground",
|
|
126
|
+
"transition-colors duration-[var(--duration-fast)] hover:bg-accent hover:text-foreground",
|
|
127
|
+
focusRing,
|
|
128
|
+
className,
|
|
129
|
+
)}
|
|
130
|
+
{...props}
|
|
131
|
+
>
|
|
132
|
+
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true" className="size-3.5">
|
|
133
|
+
<path
|
|
134
|
+
d="m6 6 12 12M18 6 6 18"
|
|
135
|
+
stroke="currentColor"
|
|
136
|
+
strokeWidth="2"
|
|
137
|
+
strokeLinecap="round"
|
|
138
|
+
/>
|
|
139
|
+
</svg>
|
|
140
|
+
</ToastPrimitive.Close>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export type ToastPosition =
|
|
145
|
+
"top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right";
|
|
146
|
+
|
|
147
|
+
const viewportPositions: Record<ToastPosition, string> = {
|
|
148
|
+
"top-left": "top-0 left-0 sm:flex-col-reverse",
|
|
149
|
+
"top-center": "top-0 left-1/2 -translate-x-1/2 sm:flex-col-reverse",
|
|
150
|
+
"top-right": "top-0 right-0 sm:flex-col-reverse",
|
|
151
|
+
"bottom-left": "bottom-0 left-0",
|
|
152
|
+
"bottom-center": "bottom-0 left-1/2 -translate-x-1/2",
|
|
153
|
+
"bottom-right": "bottom-0 right-0",
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export interface ToasterProps {
|
|
157
|
+
position?: ToastPosition;
|
|
158
|
+
/** Default auto-dismiss in ms. Individual toasts may override it. */
|
|
159
|
+
duration?: number;
|
|
160
|
+
className?: string;
|
|
161
|
+
/** Names the toast region for assistive technology. */
|
|
162
|
+
label?: string;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Renders the toast queue. Mount once, near the root of the application.
|
|
167
|
+
*/
|
|
168
|
+
export function Toaster({
|
|
169
|
+
position = "bottom-right",
|
|
170
|
+
duration = DEFAULT_TOAST_DURATION,
|
|
171
|
+
className,
|
|
172
|
+
label = "Notifications",
|
|
173
|
+
}: ToasterProps) {
|
|
174
|
+
const toasts = useToasts();
|
|
175
|
+
// Swiping should follow the edge the toasts are docked against.
|
|
176
|
+
const swipeDirection = position.endsWith("left") ? "left" : "right";
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<ToastPrimitive.Provider swipeDirection={swipeDirection} duration={duration} label={label}>
|
|
180
|
+
{toasts.map((record) => (
|
|
181
|
+
<ToastItem key={record.id} record={record} />
|
|
182
|
+
))}
|
|
183
|
+
<ToastPrimitive.Viewport
|
|
184
|
+
data-slot="toast-viewport"
|
|
185
|
+
className={cn(
|
|
186
|
+
"pointer-events-none fixed z-[var(--z-toast)] flex max-h-screen w-full flex-col gap-2 p-4 sm:max-w-sm",
|
|
187
|
+
viewportPositions[position],
|
|
188
|
+
className,
|
|
189
|
+
)}
|
|
190
|
+
/>
|
|
191
|
+
</ToastPrimitive.Provider>
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** Variants that report a problem should interrupt rather than wait for a pause. */
|
|
196
|
+
const FOREGROUND_VARIANTS = new Set<ToastVariant>(["destructive", "warning"]);
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Largest delay setTimeout accepts (2^31 - 1 ms, about 24 days).
|
|
200
|
+
*
|
|
201
|
+
* Anything above this silently overflows to a 32-bit integer and fires almost
|
|
202
|
+
* immediately, so mapping `Infinity` to MAX_SAFE_INTEGER would dismiss a
|
|
203
|
+
* persistent toast after roughly one millisecond — the exact opposite of what
|
|
204
|
+
* was asked for.
|
|
205
|
+
*/
|
|
206
|
+
const MAX_TIMEOUT_MS = 2_147_483_647;
|
|
207
|
+
|
|
208
|
+
function ToastItem({ record }: { record: ToastRecord }) {
|
|
209
|
+
const { id, title, description, variant, action, duration } = record;
|
|
210
|
+
|
|
211
|
+
const type = FOREGROUND_VARIANTS.has(variant) ? "foreground" : "background";
|
|
212
|
+
|
|
213
|
+
return (
|
|
214
|
+
<Toast
|
|
215
|
+
variant={variant}
|
|
216
|
+
type={type}
|
|
217
|
+
// Mirrored onto the element because the primitive expresses `type` only
|
|
218
|
+
// through the transient live region it renders elsewhere. Having it here
|
|
219
|
+
// gives styling and tests something stable to read.
|
|
220
|
+
data-type={type}
|
|
221
|
+
duration={duration === Infinity ? MAX_TIMEOUT_MS : duration}
|
|
222
|
+
onOpenChange={(open) => {
|
|
223
|
+
// Covers every route out: the timer, the close button and a swipe.
|
|
224
|
+
if (!open) toast.dismiss(id);
|
|
225
|
+
}}
|
|
226
|
+
>
|
|
227
|
+
<div className="flex min-w-0 flex-1 flex-col gap-1">
|
|
228
|
+
{title === undefined ? null : <ToastTitle>{title}</ToastTitle>}
|
|
229
|
+
{description === undefined ? null : <ToastDescription>{description}</ToastDescription>}
|
|
230
|
+
</div>
|
|
231
|
+
{action ? (
|
|
232
|
+
<ToastAction altText={action.altText ?? action.label} onClick={action.onClick}>
|
|
233
|
+
{action.label}
|
|
234
|
+
</ToastAction>
|
|
235
|
+
) : null}
|
|
236
|
+
<ToastClose />
|
|
237
|
+
</Toast>
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export { toastVariants };
|