Simple toasts for preact
- 💅 CSS based
- ⚡️ Built on @preact/signals
- 📦 Tiny bundle size (~1KB GZipped)
- 🤌 Simple API
npm i @preachjs/toast
import { toast, Toaster } from '@preachjs/toast'
const App = () => {
return (
<div>
<button onClick={() => toast('hello')}>toast</button>
<Toaster />
</div>
)
}
Component that acts a container for the toasts.
Displays a toast with the provided message.
Name | Type | Default | Description |
---|---|---|---|
position | string | 'top-center' | Position of the toast. Available options: 'top-left', 'top-center', 'top-right', 'bottom-left', 'bottom-center', 'bottom-right' |
closeDelay | number | 3000 | Delay in milliseconds before the toast automatically closes. |
Can be either a string or a JSX element:
type MessageInput = string | JSX.Element
toast.success(message: MessageInput, options?: Options)
- Green success toasttoast.error(message: MessageInput, options?: Options)
- Red error toasttoast.info(message: MessageInput, options?: Options)
- Blue info toasttoast.warning(message: MessageInput, options?: Options)
- Yellow warning toast
Displays toasts for different promise states.
Name | Type | Description |
---|---|---|
loading | string | Message to display while the promise is pending. |
success | string | Message to display if the promise resolves. |
error | string | Message to display if the promise rejects. |
const saveData = async () => {
const promise = fetch('/api/data')
toast.promise(promise, {
loading: 'Saving...',
success: 'Data saved!',
error: 'Failed to save data',
})
}
MIT