@zuilib/toast
v0.1.0
Published
Toast notifications for ZUI component library - built on sonner.
Maintainers
Readme
@zuilib/toast
Toast notifications for ZUI — a thin wrapper around Sonner using ZUI design tokens.
When to use
- Transient success/error/info feedback after user actions
- Promise-based loading → success/error flows
- You already load
@zuilib/components/styles.css(toasts inherit token variables)
Prerequisites
| Package | Version |
|---------|---------|
| react, react-dom | ^18.0.0 |
| @zuilib/components | dependency (tokens); import core styles in the app |
Installation
pnpm add @zuilib/toast @zuilib/components @headlessui/reactMonorepo:
{
"dependencies": {
"@zuilib/toast": "workspace:*",
"@zuilib/components": "workspace:*"
}
}Import rules
| Rule | Detail |
|------|--------|
| Named exports from root | import { Toaster, toast } from '@zuilib/toast' |
| Styles subpath | import '@zuilib/toast/styles.css' — required for toast appearance. Every value in it is a token (--info / --success / --destructive surfaces, --spacing, --text-sm, --radius-*, --duration-fast); the buttons tint from the toast's own text colour, so a retheme moves the toasts too |
| Full Sonner API | toast.success, toast.error, toast.promise, etc. are re-exported unchanged |
Exports
| Subpath | Exports |
|---------|---------|
| @zuilib/toast | Toaster, ToasterProps, toast, Toast, ToastOptions |
| @zuilib/toast/styles.css | Toast-specific CSS (import once) |
Quick start
// main.tsx or App.tsx
import '@zuilib/components/styles.css'
import '@zuilib/toast/styles.css'
import { Toaster, toast } from '@zuilib/toast'
export function App() {
return (
<>
<Toaster />
<YourRoutes />
</>
)
}
// Any child component
function SaveButton() {
return (
<button onClick={() => toast.success('Saved')}>Save</button>
)
}API
Toaster
Mount once at the app root (sibling to your app tree, not inside a portal-heavy subtree that unmounts).
<Toaster
theme="light" // 'light' | 'dark' | 'system'
position="bottom-right"
duration={4000}
closeButton
/>ToasterProps extends Sonner’s ToasterProps with theme defaulting to 'light'. All Sonner Toaster props pass through.
toast
Re-exported from sonner:
| Call | Appearance |
|------|------------|
| toast('Message') | Neutral / info (card-like) |
| toast.success('Done') | Uses --success tokens |
| toast.error('Failed') | Uses --destructive tokens |
| toast.warning, toast.info, toast.loading, … | Sonner variants |
toast('Title', {
description: 'Details',
duration: 3000,
action: { label: 'Undo', onClick: () => {} },
})
toast.promise(save(), {
loading: 'Saving…',
success: 'Saved',
error: 'Failed to save',
})Types: Toast, ToastOptions from @zuilib/toast.
Theming
Toasts read ZUI CSS variables (--success, --destructive, --info, etc.). Override in your app:
:root {
--success: #22c55e;
--destructive: #ef4444;
}Dark mode: ensure .dark is on the root element (same as @zuilib/components).
Related packages
@zuilib/components— globalstyles.cssfor shared tokens@zuilib/form— showtoast.erroron submit failure
Build (maintainers)
pnpm --filter @zuilib/toast buildTests (vitest + jsdom + axe, mirroring @zuilib/components):
pnpm --filter @zuilib/toast test
pnpm --filter @zuilib/toast typecheck