Toast
Alignment target:@astryxdesign/core v0.7.1 · Toast
Toast Props #
| Name | Type | Default | Description |
|---|---|---|---|
type | ToastType | 'info' | Visual type. Optional: info, success, warning, error. |
body | string | - | Toast message text. |
isAutoHide | boolean | true for every type except error | Whether the toast dismisses itself. Error toasts stay until they are dismissed unless this is set. |
autoHideDuration | number | 5000 | Auto-dismiss duration in milliseconds. A pause on hover, focus, or window blur keeps at least one second on the clock. |
autoClose | boolean | - | Older name of isAutoHide. Both work; isAutoHide wins. |
duration | number | - | Older name of autoHideDuration. Both work; autoHideDuration wins. |
uniqueID | string | - | Identity shared by toasts that collapse into one. |
collisionBehavior | 'ignore' | 'overwrite' | 'overwrite' | What happens when a toast reuses a visible uniqueID. |
endContent | Component | - | Trailing action, such as an undo button. Use the end slot for one-off content. |
onDismiss | (reason: 'auto' | 'manual') => void | - | Runs when the toast is dismissed from inside the card: the timer, the close button, or custom content. Options for useToast() only. |
onHide | (reason: 'auto' | 'manual') => void | - | Runs when the toast is removed, however it was dismissed, including the dismiss function returned by useToast(). Options for useToast() only. |
Toast Events #
| Name | Description |
|---|---|
dismiss | Emitted with the reason ('auto' or 'manual') when the card dismisses itself. |
close | Older name of dismiss, emitted at the same time without the reason. |
Toast Slots #
| Name | Description |
|---|---|
default | Custom toast content. Defaults to body. |
end | Trailing content, replacing endContent. |
content | Replaces the whole card content and receives { body, endContent, type, isAutoHide, autoHideDuration, dismiss }. The empty-state close button is not rendered, so the custom layout owns every control. |
ToastViewport Props #
| Name | Type | Default | Description |
|---|---|---|---|
placement | ToastPlacement | 'bottom-end' | Position of the toast stack in the viewport. Optional: top-start, top-center, top-end, bottom-start, bottom-center, bottom-end. |
useToast #
TypeScript
const toast = useToast()
const dismiss = toast({
body: 'Hello',
type: 'info',
autoHideDuration: 3000,
onDismiss: reason => console.log('dismissed', reason),
onHide: reason => console.log('removed', reason),
})
// dismiss manually
dismiss()
// dismiss all
toast.clear()