Components

Toast

Displays brief, non-blocking notifications triggered imperatively via the toast() function.

Category: Feedback / Global Service

Dependency: @base-ui-components/react/toast

Import from @hareru/ui:

import { toast, useToast, Toaster } from "@hareru/ui"

Exports

ExportDescription
ToastIndividual toast element
ToastProviderIncluded internally by Toaster. Use directly only when placing the toast viewport in a different DOM subtree
ToastViewportRenders the toast stack in the DOM
ToastTitleTitle text inside a toast
ToastDescriptionBody text inside a toast
ToastActionOptional action button
ToastCloseDismiss button
ToasterConvenience wrapper that renders ToastViewport and all active toasts
toastImperative function to trigger a new toast
useToastHook that returns { toast, toasts, dismiss }
toastVariantsCVA variant function for external use

Provider Setup

Toaster must be placed in the provider tree (typically in your root layout). See Getting Started for the full provider setup.

import { ThemeProvider, Toaster } from "@hareru/ui"

<ThemeProvider defaultTheme="system">
  {children}
  <Toaster />
</ThemeProvider>

Variants

toast() accepts a variant option:

ValueDescription
defaultNeutral notification (default)
destructiveError or danger notification

toast() Options

OptionTypeDescription
titlestringToast heading text
descriptionstringSupporting body text
variant"default" | "destructive"Visual style
actionToastActionElementOptional action button element

States

StateTypeValuesDefaultCSS Reflection
openboolean

Accessibility

  • Roles: status
  • Keyboard:
    • Escape to dismiss
  • Live region: Yes (screen readers announce changes automatically)

Usage

import { toast } from "@hareru/ui"

// Success notification
toast({ title: "Done", description: "The operation completed successfully." })

// Error notification
toast({ title: "Error", description: "Something went wrong.", variant: "destructive" })

With an action button:

import { toast, ToastAction } from "@hareru/ui"

toast({
  title: "File deleted",
  description: "The file has been moved to trash.",
  action: <ToastAction altText="Undo deletion">Undo</ToastAction>,
})

On this page