Toast

A toast notification component for displaying brief messages.

Installation

npm install fuyukaki-ui

Usage

import { ToastProvider, ToastViewport, useToast } from 'fuyukaki-ui'

function App() {
  return (
    <ToastProvider>
      <MyComponent />
      <ToastViewport />
    </ToastProvider>
  )
}

function MyComponent() {
  const { toast } = useToast()

  return (
    <button onClick={() => toast({ title: 'Hello!' })}>
      Show Toast
    </button>
  )
}

Examples

Toast Options

// Basic toast
toast({ title: 'Hello World' })

// With description
toast({
  title: 'Success',
  description: 'Your changes have been saved.',
})

// With variant
toast({
  title: 'Error',
  description: 'Something went wrong.',
  variant: 'error',
})

// With action
toast({
  title: 'Deleted',
  description: 'The item has been deleted.',
  action: {
    label: 'Undo',
    onClick: () => handleUndo(),
  },
})

// Custom duration (ms)
toast({
  title: 'Quick toast',
  duration: 2000,
})

Props

OptionTypeDefault
titlestring-
descriptionstring-
variant'default' | 'success' | 'error' | 'warning''default'
durationnumber5000
closablebooleantrue
action{ label: string, onClick: () => void }-

ToastViewport Props

PropTypeDefault
position'top-left' | 'top-right' | 'bottom-left' | 'bottom-right''bottom-right'