Components
Toast

Toast

The Toast component provides you with popup notifications with auto-dismiss and positioning.

Import

import { Toast, ToastProvider, useToast } from '@nostromo/ui-core'
// or
import { Toast, ToastProvider, useToast } from '@nostromo/ui-core/toast'

Usage

import { ToastProvider, useToast } from '@nostromo/ui-core'
 
function App() {
  return (
    <ToastProvider>
      <MyComponent />
    </ToastProvider>
  )
}
 
function MyComponent() {
  const { addToast } = useToast()
  
  const handleClick = () => {
    addToast({
      variant: 'success',
      title: 'Success!',
      description: 'Your action was completed.'
    })
  }
  
  return <button onClick={handleClick}>Show Toast</button>
}

Live Examples

Using the Hook

Live Example
☀️
Copy
Storybook →
View Code
import { ToastProvider, useToast } from '@nostromo/ui-core' function ToastDemo() { const { addToast } = useToast() return ( <div className="space-x-2"> <button onClick={() => addToast({ variant: 'success', title: 'Success!',...

With Action

Live Example
☀️
Copy
Storybook →
View Code
import { ToastProvider, useToast } from '@nostromo/ui-core' function ToastWithAction() { const { addToast } = useToast() return ( <button onClick={() => addToast({ variant: 'default', title: 'File deleted', description: 'The file has been moved to trash.',...

Best Practices

Do ✅

  • Wrap your app with ToastProvider at the root level
  • Use the useToast hook for easy toast management
  • Provide clear title and description for each toast
  • Use appropriate variant for different message types
  • Set duration={0} for important toasts that require user action

Don't ❌

  • Don't show too many toasts at once
  • Don't use toasts for critical errors (use dialogs instead)
  • Don't forget to handle toast actions
  • Don't use toasts for form validation (use inline errors)

Props

Toast

PropTypeDefaultRequiredDescription
variant"default" | "success" | "error" | "warning" | "info""default"NoVisual variant of the toast
position"top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right""top-right"NoToast position
titlestringundefinedNoToast title
descriptionstringundefinedNoToast description
durationnumber5000NoAuto-dismiss duration in ms (0 = no auto-dismiss)
onClose() => voidundefinedNoCallback when toast is closed
action{ label: string; onClick: () => void }undefinedNoAction button configuration
appearDelaynumber10NoDelay before toast appears (ms)
animationMsnumber150NoExit animation duration (ms)
classNamestringundefinedNoAdditional CSS classes
childrenReact.ReactNodeundefinedNoToast content

ToastProvider

PropTypeDefaultRequiredDescription
childrenReact.ReactNode-YesApp content

useToast Hook

Returns:

  • toasts: ToastProps[] - Array of current toasts
  • addToast: (toast: Omit<ToastProps, 'id'>) => string - Add a new toast (returns toast ID)
  • removeToast: (id: string) => void - Remove a toast by ID
  • clearToasts: () => void - Clear all toasts