Toaster
Show a toast from anywhere with toast('Saved'). Mount one Toaster; call toast.success, toast.error or toast.promise from handlers.
SourceStyles source@monoline/react 0.5.0Markdown for AI toolsstable
- Built on native elements
- 2 parts, named exports
- Info and success toasts are announced politely; errors are announced assertively.
- F8 moves focus to the notification region; hovering or focusing a toast pauses its timer.
- Each toast has a Dismiss button and an optional action button; Escape closes the focused toast.
- Styles in one file:
toast.css
Import
import '@monoline/css';
import {Toaster} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add toaster
Usage
import {Button, Toaster, toast} from '@monoline/react';
function Example() {
return (
<div style={{display: 'flex', gap: 8, flexWrap: 'wrap'}}>
<Button variant="line" onClick={() => toast('Draft saved')}>Default</Button>
<Button variant="line" onClick={() => toast.success('Profile updated', {description: 'Changes are live.'})}>Success</Button>
<Button variant="line" onClick={() => toast.error('Could not save', {description: 'Check your connection.', action: {label: 'Retry', onClick: () => toast.info('Retrying')}})}>Error with retry</Button>
<Button variant="line" onClick={() => toast.warning('Storage almost full')}>Warning</Button>
<Button variant="line" onClick={() => toast.promise(new Promise((r) => setTimeout(r, 1500)), {loading: 'Uploading', success: 'Uploaded', error: 'Upload failed'})}>Promise</Button>
<Button variant="ghost" onClick={() => toast.dismiss()}>Dismiss all</Button>
<Toaster />
</div>
);
}
<Example />
Anatomy
Import the parts you need and nest them like this.
import {Toaster, toast} from '@monoline/react';
<Toaster>
<toast />
</Toaster>
Examples
Call toast() from any handler
Mount one Toaster, then call toast anywhere. No provider or hook is needed.
Props
ToasterProps
| Prop | Type | Default | Description |
|---|---|---|---|
limit | number | 3 | Most toasts shown at once. Older ones wait out of sight and return when there is room. Default 3. |
position | "center" | "start" | "end" | 'end' | Where the stack sits. `end` is the bottom corner at the end of the reading direction. Default "end". |
label | string | 'Notifications' | Names the region for screen readers. Default "Notifications". |
dismissLabel | string | 'Dismiss' | Text of each close button. Default "Dismiss". |
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
| Attribute | Stylesheet |
|---|---|
[data-state="closed"] | toast.css |
[data-state="open"] | toast.css |
[data-kind="error"] | toaster.css |
[data-kind="loading"] | toaster.css |
[data-kind="success"] | toaster.css |
[data-kind="warning"] | toaster.css |
[data-position="center"] | toaster.css |
[data-position="start"] | toaster.css |
[data-swipe="cancel"] | toaster.css |
[data-swipe="move"] | toaster.css |
CSS classes
| Class | Stylesheet |
|---|---|
.toast-action | toast.css |
.toast-close | toast.css |
.toast-description | toast.css |
.toast-item | toast.css |
.toast-title | toast.css |
.toast-viewport | toast.css |
.toaster-item | toaster.css |
.toaster-viewport | toaster.css |
Customization
Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.
app.css
.toast-action {
border-color: var(--accent);
}
.toast-action[data-state="closed"] {
background: var(--wash);
}
Accessibility
- Info and success toasts are announced politely; errors are announced assertively.
- F8 moves focus to the notification region; hovering or focusing a toast pauses its timer.
- Each toast has a Dismiss button and an optional action button; Escape closes the focused toast.
- A stack limit keeps at most three visible by default (older ones wait); motion is removed with prefers-reduced-motion.
- Never the only place a critical result appears; keep an inline message too.
Keyboard
| Keys | Action |
|---|---|
| Escape | Closes the focused toast |