Toast
A toast notification component for displaying brief messages.
Installation
npm install fuyukaki-uiUsage
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
| Option | Type | Default |
|---|---|---|
| title | string | - |
| description | string | - |
| variant | 'default' | 'success' | 'error' | 'warning' | 'default' |
| duration | number | 5000 |
| closable | boolean | true |
| action | { label: string, onClick: () => void } | - |
ToastViewport Props
| Prop | Type | Default |
|---|---|---|
| position | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'bottom-right' |
