Toast
Overview
notify event. New toasts sit in front. Older ones tuck behind in 14px peeks and fan open on hover or focus. A right swipe dismisses the front toast. Alt+T moves focus into the stack, and Escape dismisses the focused toast. Every stack on the page hears the same event.
Setup
<neura::toast />
Toast Types
// JavaScript
window.dispatchEvent(new CustomEvent('notify', {
detail: {
type: 'success',
content: 'Operation completed successfully!',
duration: 4000
}
}));
// PHP (after redirect)
toast()->success('Operation completed successfully!');
PHP Helper Function
toast()
helper function in your controllers or Livewire components:
// Success toast
toast()->success('Operation completed successfully!');
// Error toast
toast()->error('Something went wrong');
// Warning toast
toast()->warning('Please check your input');
// Info toast
toast()->info('Here is some information');
// Custom duration (in milliseconds)
toast()->success('Saved!', 6000);
JavaScript Events
window.dispatchEvent(new CustomEvent('notify', {
detail: {
type: 'success', // 'info', 'success', 'error', 'warning'
content: 'Message text',
duration: 4000, // Duration in milliseconds (0 = persistent)
showProgress: true // Show progress bar (default: true)
}
}));
Position
position
prop:
Top Left
Top Right
Bottom Left
Bottom Right (Default)
<neura::toast position="top-left" />
<neura::toast position="top-right" />
<neura::toast position="bottom-left" />
<neura::toast position="bottom-right" />
Maximum Toasts
<neura::toast maxToasts="3" />
Features
Auto-dismiss
Toasts automatically disappear after the specified duration (default: 4000ms). Set duration to 0 for persistent toasts.
Progress Bar
A thin timer along the bottom edge. It pauses while the stack is hovered, focused, dragged, or the tab is hidden.
Hover to Pause
Hovering or focusing the stack fans the toasts open and pauses their timers. A right swipe throws the front toast away. A left drag rubber-bands back.
Manual Dismiss
Users can manually close toasts by clicking the close button.
Best Practices
Do
- Use appropriate toast types for different scenarios
- Keep messages concise and clear
- Use success toasts for completed actions
- Use error toasts for failures that need user attention
- Set reasonable durations (3000-5000ms for most cases)
Don't
- Overuse toasts (don't show one for every action)
- Use toasts for critical errors that require immediate action
- Make messages too long (keep under 100 characters when possible)
- Show too many toasts at once (use maxToasts to limit)
Properties
| Property | Type | Default | Description |
|---|---|---|---|
| position | string | 'bottom-right' | Toast position: 'top-left', 'top-right', 'bottom-left', or 'bottom-right' |
| maxToasts | int | 5 | How many toasts the stack keeps. Three stay visible; the rest peek until hover. |