Playground

Toaster

Show a toast from anywhere with toast('Saved'). Mount one Toaster; call toast.success, toast.error or toast.promise from handlers.

  • 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

PropTypeDefaultDescription
limitnumber3Most 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".
labelstring'Notifications'Names the region for screen readers. Default "Notifications".
dismissLabelstring'Dismiss'Text of each close button. Default "Dismiss".

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

AttributeStylesheet
[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

ClassStylesheet
.toast-actiontoast.css
.toast-closetoast.css
.toast-descriptiontoast.css
.toast-itemtoast.css
.toast-titletoast.css
.toast-viewporttoast.css
.toaster-itemtoaster.css
.toaster-viewporttoaster.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

KeysAction
EscapeCloses the focused toast