Playground

Toast

A short message that appears briefly and does not block the page.

  • Built on radix-ui/Toast
  • 7 parts, named exports
  • Announced politely by assistive tech without moving focus.
  • Pauses its timer on hover and focus; F8 jumps focus to the toast region.
  • Never the only place a critical result appears; keep an inline message too.
  • Styles in one file: toast.css

Import

import '@monoline/css';
import {Toast} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add toast

It needs radix-ui; install it if your project does not have it:

npm install radix-ui

Usage

import {useState} from 'react';
import {Button, Toast, ToastAction, ToastClose, ToastDescription, ToastProvider, ToastTitle, ToastViewport} from '@monoline/react';

function Example() {
  const [open, setOpen] = useState(false);
  return (
    <ToastProvider duration={5000}>
      <Button variant="line" onClick={() => setOpen(true)}>Save draft</Button>
      <Toast open={open} onOpenChange={setOpen}>
        <ToastTitle>Draft saved</ToastTitle>
        <ToastDescription>Stored on this device.</ToastDescription>
        <ToastAction altText="Undo the save">Undo</ToastAction>
        <ToastClose />
      </Toast>
      <ToastViewport label="Notifications" />
    </ToastProvider>
  );
}

<Example />

Anatomy

Import the parts you need and nest them like this.

import {ToastProvider, ToastViewport, Toast, ToastTitle, ToastDescription, ToastAction, ToastClose} from '@monoline/react';

<ToastProvider>
  <ToastViewport />
  <Toast />
  <ToastTitle />
  <ToastDescription />
  <ToastAction />
  <ToastClose />
</ToastProvider>

Examples

Trigger a toast

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

CSS classes

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

  • Announced politely by assistive tech without moving focus.
  • Pauses its timer on hover and focus; F8 jumps focus to the toast region.
  • Never the only place a critical result appears; keep an inline message too.