A message that provides feedback to users about an action or event, often temporary and dismissible.
FluxProvider shows toasts on every page. To place them yourself, render a Toast component, such as in a layout; while it's on the page, it replaces the provider's.
import { Toast } from '@fluxui-dev/react';<body> {/* ... */} <Toast /></body>
Once a toaster is on the page, import toast() from @fluxui-dev/react and call it from anywhere, such as an event handler or an Inertia callback:
import { Button, Toast, toast } from '@fluxui-dev/react';<Button onClick={() => toast('Your changes have been saved.')}>Save changes</Button><Toast />
The toast() function supports the following parameter signatures:
toast('Your changes have been saved.');toast('Changes saved', 'You can always update this in your settings.');toast('Invoice created.', { variant: 'success' });toast({ heading: 'Changes saved', text: 'Your changes have been saved.', variant: 'success',});
In an Inertia app, you can also flash a toast from a Laravel controller. See the Inertia guide.
Use a heading to provide additional context for the toast.
<Button onClick={() => toast({ heading: 'Changes saved', text: 'You can always update this in your settings.' })}>Save changes</Button>
Use the variant option to change the visual style of the toast.
<Button onClick={() => toast({ variant: 'success', ... })}>Success</Button><Button onClick={() => toast({ variant: 'warning', ... })}>Warning</Button><Button onClick={() => toast({ variant: 'danger', ... })}>Danger</Button>
Add invert to the Toast component in your layout to use a dark appearance in light mode and a light appearance in dark mode. This configures every toast while leaving variant available for per-message semantics.
<Toast invert />
Add an action to a toast when users need to respond to it, running an onClick function when clicked.
<Button onClick={() => toast({ heading: 'Changes saved', text: 'Your updates are now live.', duration: 0, variant: 'success', action: { label: 'Undo', onClick: async () => { await new Promise((resolve) => setTimeout(resolve, 1200)); toast('Your changes were undone.', { variant: 'success' }); }, }, }) }> Save changes</Button>
When onClick returns a promise, the action shows a loading indicator until it settles and then dismisses the toast. Pass dismiss: false to keep it open afterward.
An action can also be a real link. This keeps native link behavior such as opening in a new tab.
toast('Invoice created.', { action: { label: 'View', href: `/invoices/${invoice.id}`, },});
Add a link to a toast to give users a clear next step.
<Button onClick={() => toast('Invoice created.', { variant: 'success', link: { label: 'View invoice', href: '#' } })}>Create invoice</Button>
By default, the toast will appear in the bottom right corner of the page. You can customize this position using the position prop.
<Toast position="top end" />{/* Customize top padding for things like navbars... */}<Toast position="top end" className="pt-24" />
Override the position for an individual toast by passing position to toast().
<Button onClick={() => toast('Your changes have been saved.', { position: 'top end' })}>Save changes</Button>
By default, the toast will automatically dismiss after 5 seconds. You can customize this duration by passing a number of milliseconds to the duration option.
<Button onClick={() => toast('Your changes have been saved.', { duration: 1000 })}>Save changes</Button>
Use a value of 0 as the duration option to make the toast stay open indefinitely.
<Button onClick={() => toast('Your changes have been saved.', { duration: 0 })}>Save changes</Button>
To show a stack of toasts, you can wrap the Toast component in a Toast.Group component. By default, toasts in a stack overlap and expand on hover to show each toast vertically.
<Toast.Group> <Toast /></Toast.Group>
Use the expanded prop to always show the toast stack in an expanded state, making all toasts visible at once.
<Toast.Group expanded> <Toast /></Toast.Group>
The group component also accepts the position prop to control where the toast stack appears on the screen.
<Toast.Group position="top end"> <Toast /></Toast.Group>
With FluxProvider, pass the same options to its toast prop, with group for a stack.
<FluxProvider toast={{ group: true, expanded: true, position: 'top end' }}> {app}</FluxProvider>
|
Prop
|
Description
|
|---|---|
| position |
Position of the toast on the screen. Options: bottom end (default), bottom center, bottom start, top end, top center, top start.
|
| invert |
If true, uses a dark appearance in light mode and a light appearance in dark mode for every toast. Default: false.
|
|
CSS
|
Description
|
|---|---|
| className |
CSS classes added to each toast's outer element, such as pt-24 to clear a sticky navbar.
|
|
Attribute
|
Description
|
|---|---|
| data-flux-toast |
Applied to the toast viewport for styling and identification (data-flux-toast-group inside Toast.Group).
|
| data-flux-toast-dialog |
Applied to each toast.
|
|
Prop
|
Description
|
|---|---|
| position |
Position of the toast group on the screen. Options: bottom end (default), bottom center, bottom start, top end, top center, top start.
|
| expanded |
If true, always shows the toast stack in an expanded state, making all toasts visible at once. Default: false.
|
The JavaScript function used to trigger toasts from React components.
|
Parameter
|
Description
|
|---|---|
| heading |
Optional heading text for the toast.
|
| text |
Main content text of the toast.
|
| variant |
Visual style. Options: default, success, warning, danger, info.
|
| duration |
Duration in milliseconds. Use 0 for permanent toasts. Default: 5000.
|
| position |
Position of this toast, overriding the Toast position. Ignored inside Toast.Group.
|
| link |
Optional link configuration. Supports label, href, target, rel, and download.
|
| action |
Optional action configuration. Requires a label and either an onClick or href. Both support dismiss; link actions support target, rel, and download.
|
The flash key that the FluxProvider from @fluxui-dev/react/inertia shows as a toast, taking the same parameters as toast(), except that an action needs an href, since onClick cannot be flashed from PHP.