Toast

Brief notifications sent from anywhere with toast(). Built on Sonner and styled entirely by the theme.

Status: beta. Category: Feedback.

import { Toaster } from '@glyphui/ui'

Exports: Toaster, toast, toastStyles.

Notes

  • Mount one <Toaster /> near the root; call toast() from anywhere, including outside React.
  • Toasts are announced to screen readers and pause while hovered.

Example: Types

import { Button, toast } from '@glyphui/ui'

export default function Example() {
  return (
    <div className="flex flex-wrap gap-2">
      <Button variant="outline" onClick={() => toast('Draft saved')}>
        Default
      </Button>
      <Button
        variant="outline"
        onClick={() =>
          toast.success('Invoice sent', { description: 'Acme Inc. will get it by email.' })
        }
      >
        Success
      </Button>
      <Button variant="outline" onClick={() => toast.info('Sync runs every 15 minutes')}>
        Info
      </Button>
      <Button variant="outline" onClick={() => toast.warning('Your trial ends in 3 days')}>
        Warning
      </Button>
      <Button
        variant="outline"
        onClick={() =>
          toast.error('Couldn’t upload logo.png', { description: 'Files must be under 2 MB.' })
        }
      >
        Error
      </Button>
    </div>
  )
}

Example: Promise

One toast that follows a request from loading to success or error.

import { Button, toast } from '@glyphui/ui'

function publish() {
  return new Promise<{ version: string }>((resolve) =>
    setTimeout(() => resolve({ version: '0.2.0' }), 1500),
  )
}

export default function Example() {
  return (
    <Button
      onClick={() =>
        toast.promise(publish(), {
          loading: 'Publishing…',
          success: (result) => `Published ${result.version}`,
          error: 'Publishing failed. Try again.',
        })
      }
    >
      Publish release
    </Button>
  )
}

Example: With an action

Offer an undo instead of a confirmation dialog.

import { Button, toast } from '@glyphui/ui'

export default function Example() {
  return (
    <Button
      variant="outline"
      onClick={() =>
        toast('Issue archived', {
          action: { label: 'Undo', onClick: () => toast.success('Issue restored') },
        })
      }
    >
      Archive issue
    </Button>
  )
}

Live page: https://glyphui.xyz/components/toast