Oddmash UI
All components

Toast

Confirm a completed action in a dismissible notification.

Usage

Mount controlled Toasts within ToastViewport to stack notifications. For automatically expiring notifications with a countdown, use ToastProvider and set duration when needed. Hover or focus pauses expiry.

Accessibility

Use neutral, success, info, warning or loading for polite updates and danger or error for urgent errors. Keep the dismiss button available and restore focus to the next notification or trigger. Custom icons are decorative; use null to hide the icon.

PropertyTypeDefault
openbooleanRequired
titlestringRequired
onDismiss() => voidRequired
dismissLabelstringDismiss notification
toneneutral | success | info | warning | danger | error | loadingneutral
iconReactNodeTone icon; null hides it
progressnumber (0–1)None
import { useRef, useState } from 'react';

const toastMessages = {
  neutral: { label: 'Notice', title: 'Project updated', description: 'The project has a new update.' },
  loading: { label: 'Loading', title: 'Saving project', description: 'Your changes are being synchronized.' },
  success: { label: 'Success', title: 'Project saved', description: 'Your changes are ready.' },
  info: { label: 'Information', title: 'Export ready', description: 'Your export is available in the project history.' },
  warning: { label: 'Warning', title: 'Connection interrupted', description: 'Your changes are preserved locally. Reconnect before continuing.' },
  error: { label: 'Error', title: 'Save failed', description: 'Your changes could not be synchronized. Check your network connection and retry when you are ready.' },
} as const;

type PreviewTone = keyof typeof toastMessages;

const NoticeControls = () => {
  const trigger = useRef<HTMLButtonElement>(null);
  const { showToast } = useToast();
  const [tone, setTone] = useState<PreviewTone>('success');
  const options = (Object.keys(toastMessages) as PreviewTone[]).map(value => ({ value, label: toastMessages[value].label }));
  const show = () => showToast({
    title: toastMessages[tone].title,
    description: toastMessages[tone].description,
    tone,
    duration: tone === 'neutral' || tone === 'success' || tone === 'info' ? 10000 : null,
    restoreFocusTo: trigger.current,
  });
  return (
    <div className="preview-toast-controls">
      <Select aria-label={'Notification tone'} options={options} value={tone} onValueChange={value => {
        if (Object.hasOwn(toastMessages, value)) setTone(value as PreviewTone);
      }} />
      <Button ref={trigger} variant="secondary" onClick={show}>
        {'Show toast'}
      </Button>
    </div>
  );
};

export const SaveNotice = () => (
  <div className="preview-toast">
    <ToastProvider className="preview-toast-viewport" maxVisible={3}>
      <NoticeControls />
    </ToastProvider>
  </div>
);

Interactive documentation