Toast API
View componentThe full prop reference for the Toast component. A succinct message that is displayed temporarily.
Import
import { Toast } from '@structyl/styled';Props
Provider
Toast context provider — wraps your app to enable toast functionality
| Prop | Type | Default |
|---|---|---|
| children# | React.ReactNodeThe app content that can access toast context | — |
| label# | stringAria label for the toast region | 'Notifications' |
| duration# | numberTime in ms to auto-dismiss toasts; set to Infinity to disable | 5000 |
| swipeDirection# | 'up' | 'down' | 'left' | 'right'Direction users can swipe to dismiss toasts | 'right' |
| swipeThreshold# | numberDistance in px to consider a swipe a dismissal | 50 |
Viewport
Container that holds and positions all toasts; automatically styled in the styled layer
| Prop | Type | Default |
|---|---|---|
| asChild# | booleanRender as child element instead of creating wrapper | — |
| hotkey# | string[]Keyboard keys to focus the toast viewport | ['F8'] |
| label# | stringAria label for the toast list | '{hotkey} hotkey to focus toasts' |
| className# | stringAdditional CSS classes (styled layer provides sensible defaults) | — |
| ...rest# | React.ComponentPropsWithoutRef<'ol'>All native ol HTML attributes (style, role, aria-*, etc.) | — |
Root
Individual toast component — represents a single toast notification
| Prop | Type | Default |
|---|---|---|
| type# | 'foreground' | 'background'Aria-live priority: foreground=assertive, background=polite | 'foreground' |
| open# | booleanControlled: whether the toast is visible | — |
| defaultOpen# | booleanUncontrolled: initial visibility state | true |
| onOpenChange# | (open: boolean) => voidFired when toast visibility changes | — |
| duration# | numberOverrides Provider duration for this toast; Infinity to keep open | — |
| forceMount# | booleanAlways render in DOM (even when closed) for animation control | — |
| onEscapeKeyDown# | (event: KeyboardEvent) => voidFired when Escape key is pressed on focused toast | — |
| onPause# | () => voidFired when toast auto-dismiss timer pauses (hover/focus) | — |
| onResume# | () => voidFired when toast auto-dismiss timer resumes | — |
| onSwipeStart# | (event: React.PointerEvent) => voidFired when swipe gesture begins | — |
| onSwipeMove# | (event: React.PointerEvent) => voidFired continuously while swiping | — |
| onSwipeEnd# | (event: React.PointerEvent) => voidFired when swipe distance exceeds threshold and toast closes | — |
| onSwipeCancel# | (event: React.PointerEvent) => voidFired when swipe is released but below threshold | — |
| variant# | 'default' | 'destructive' | 'error' | 'success' | 'warning' | 'info'Visual style variant (styled layer only) | 'default' |
| className# | stringAdditional CSS classes (merges with variant styles) | — |
| ...rest# | React.ComponentPropsWithoutRef<'li'>All native li HTML attributes (role, data-*, etc.) | — |
Title
Toast title text — renders inside Toast.Root
| Prop | Type | Default |
|---|---|---|
| asChild# | booleanRender as child element instead of creating wrapper | — |
| className# | stringAdditional CSS classes (styled layer provides typography defaults) | — |
| children# | React.ReactNodeTitle text or content | — |
| ...rest# | React.ComponentPropsWithoutRef<'div'>All native div HTML attributes | — |
Description
Toast description text — renders inside Toast.Root
| Prop | Type | Default |
|---|---|---|
| asChild# | booleanRender as child element instead of creating wrapper | — |
| className# | stringAdditional CSS classes (styled layer provides typography defaults) | — |
| children# | React.ReactNodeDescription text or content | — |
| ...rest# | React.ComponentPropsWithoutRef<'div'>All native div HTML attributes | — |
Action
Action button in the toast — automatically closes toast on click
| Prop | Type | Default |
|---|---|---|
| altText# | stringRequired alt text for screen readers (hidden visually) | — |
| asChild# | booleanRender as child element instead of creating button | — |
| className# | stringAdditional CSS classes (styled layer provides button styles) | — |
| children# | React.ReactNodeButton label or content | — |
| ...rest# | React.ComponentPropsWithoutRef<'button'>All native button HTML attributes (onClick, disabled, etc.) | — |
Close
Close/dismiss button in the toast — automatically closes toast on click
| Prop | Type | Default |
|---|---|---|
| asChild# | booleanRender as child element instead of creating button | — |
| className# | stringAdditional CSS classes (styled layer provides default icon and styles) | — |
| children# | React.ReactNodeButton content (styled layer provides X icon by default) | — |
| ...rest# | React.ComponentPropsWithoutRef<'button'>All native button HTML attributes (onClick, disabled, etc.) | — |
Portal
Portal helper — renders toast content into a specific DOM container
| Prop | Type | Default |
|---|---|---|
| children# | React.ReactNodeContent to portal | — |
| container# | Element | DocumentFragment | nullTarget DOM node; defaults to document.body | — |
Toaster
Singleton component — renders all imperative toasts. Drop once in your app root (e.g. layout.tsx)
| Prop | Type | Default |
|---|---|---|
| horizontal# | 'left' | 'center' | 'right'Default horizontal alignment for all toasts | 'right' |
| vertical# | 'top' | 'bottom'Default vertical alignment for all toasts | 'bottom' |
| maxToasts# | numberMaximum number of toasts visible at once per position group | 5 |
| className# | stringAdditional CSS classes forwarded to viewport wrappers | — |
| ...rest# | React.ComponentPropsWithoutRef<typeof Viewport>Viewport props (hotkey, label, style, aria-*, etc.) | — |
toast.show()
Imperative API — fire a toast with full control over all options
| Prop | Type | Default |
|---|---|---|
| options.id# | stringReuse/update existing toast when same ID is fired again | — |
| options.title# | stringMain toast text | — |
| options.description# | stringSecondary toast text | — |
| options.variant# | 'default' | 'success' | 'error' | 'warning' | 'info' | 'loading'Visual style and icon | 'default' |
| options.duration# | numberAuto-dismiss in ms; pass Infinity to keep until manually dismissed | 4000 |
| options.horizontal# | 'left' | 'center' | 'right'Horizontal position (overrides Toaster default) | — |
| options.vertical# | 'top' | 'bottom'Vertical position (overrides Toaster default) | — |
| options.action# | { label: string; onClick: () => void }Custom action button; takes priority over retry if both provided | — |
| options.retry# | () => voidAdds a Retry button (action takes priority for button label) | — |
| options.onDismiss# | (id: string) => voidCallback fired when toast is dismissed (before animation) | — |
toast.success()
Convenience method — fire a success toast
toast.error()
Convenience method — fire an error toast
toast.warning()
Convenience method — fire a warning toast
toast.info()
Convenience method — fire an info toast
toast.loading()
Convenience method — fire a loading toast (spinner icon, duration defaults to Infinity)
toast.promise()
Async helper — show loading toast, then update to success or error when promise settles
| Prop | Type | Default |
|---|---|---|
| promise# | Promise<T>The promise to track | — |
| messages.loading# | stringText while promise is pending | — |
| messages.success# | string | ((data: T) => string)Text when promise resolves; can be a function to format the resolved value | — |
| messages.error# | string | ((err: unknown) => string)Text when promise rejects; can be a function to format the error | — |
| options# | Omit<ToastOptions, 'title' | 'variant'>Same as toast.show() except title and variant are managed by promise state | — |
toast.dismiss()
Close a toast with exit animation; omit id to dismiss all
| Prop | Type | Default |
|---|---|---|
| id# | stringToast ID to close; omit to dismiss all open toasts | — |
toast.remove()
Instantly remove a toast from the store without animation
| Prop | Type | Default |
|---|---|---|
| id# | stringToast ID to remove | — |
useToast()
Hook to subscribe to the toast store inside a React component
| Prop | Type | Default |
|---|---|---|
| return.toasts# | ToastItem[]Array of current toast items in the store | — |
| return.toast# | typeof toastThe complete toast imperative API (show, success, error, etc.) | — |
| return.dismiss# | (id?: string) => voidClose toast(s) with animation | — |
| return.remove# | (id: string) => voidInstantly remove a toast | — |
Keyboard interactions
| Key | Description |
|---|---|
| F8 | Jumps focus into the toast viewport. |
| Tab | Moves focus through the toast. |
| Esc | Closes the focused toast. |
Source code
If you didn't find what you need here, read the component implementation .