How to use
Toast is a provider-based notification system: mount ToastProvider once near the root of your app, then call the imperative toast(...) function from anywhere — a click handler, a data-fetching hook, deep inside a component tree — without threading state or props down to get there. It supports a promise-aware mode that walks a toast through loading → success/error automatically.
import { ToastProvider, toast } from "oks-ui";Mount ToastProvider once, high in the tree — it renders a portaled region (position defaults to bottom-right) that every toast() call anywhere in the app renders into. There's no toast context to consume and no hook to call at the use-site; toast(...) is a plain imported function.
// app root
<ToastProvider position="top-right" maxVisibleToasts={3}>
<App />
</ToastProvider>
// anywhere else in the tree
import { toast } from "oks-ui";
function SaveButton() {
return (
<Button onPress={() => toast.success("Saved", { description: "Your changes were saved." })}>
Save
</Button>
);
}toast.success/toast.error/toast.warning/toast.info are shortcuts that set both type and the matching default icon. For anything not covered by a shortcut, call toast(options) directly with the full ToastOptions shape — variant, size, duration, a dismiss/action button, whatever you need.
toast.success("Copied to clipboard");
toast.error("Upload failed", { description: "The file exceeded 10 MB.", persistent: true });
toast({
title: "Update available",
description: "A new version is ready to install.",
action: { label: "Reload", onClick: () => window.location.reload() },
duration: null,
});Pass a promise and toast walks through loading → success/error on its own — no manual success()/error() calls to keep in sync with the actual request. It shows a loading state immediately, then swaps to success or error once the promise settles.
toast.promise(saveProfile(formData), {
loading: "Saving…",
success: "Profile saved",
error: "Couldn't save profile",
});Every toast auto-dismisses after defaultDuration (6s) unless you override duration per-toast, or set persistent to remove the auto-dismiss timer entirely (typically paired with dismissible so the user still has a way to close it manually). showDurationBar renders a shrinking progress bar so the countdown is visible, not just implied.
toast.warning("Session expiring soon", { duration: 10000, showDurationBar: true });
toast.error("Payment failed", { persistent: true, dismissible: true });All available props for ToastProvider. See the full component page for an interactive playground.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Your app, rendered inside the provider. |
children
ReactNode
Default: —
Your app, rendered inside the provider.
| Prop | Type | Default | Description |
|---|---|---|---|
position | "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right" | "bottom-right" | Where the toast region renders. |
maxToasts | number | 12 | Total toasts kept in the queue (visible + pending). |
maxVisibleToasts | number | 3 | Toasts shown at once before stacking/queuing. |
toastOffset | number | 0 | Extra offset from the viewport edge. |
container | Element | DocumentFragment | null | — | Custom portal mount target. |
position
"top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right"
Default: "bottom-right"
Where the toast region renders.
maxToasts
number
Default: 12
Total toasts kept in the queue (visible + pending).
maxVisibleToasts
number
Default: 3
Toasts shown at once before stacking/queuing.
toastOffset
number
Default: 0
Extra offset from the viewport edge.
container
Element | DocumentFragment | null
Default: —
Custom portal mount target.
| Prop | Type | Default | Description |
|---|---|---|---|
defaultDuration | number | 6000 | Auto-dismiss duration in ms, unless overridden per-toast or persistent. |
toastProps | ToastOptions | — | Default options applied to every toast from this provider. |
defaultDuration
number
Default: 6000
Auto-dismiss duration in ms, unless overridden per-toast or persistent.
toastProps
ToastOptions
Default: —
Default options applied to every toast from this provider.
| Prop | Type | Default | Description |
|---|---|---|---|
motion | "auto" | "reduced" | "default" | "auto" | Animation mode; "auto" respects prefers-reduced-motion. |
disableAnimation | boolean | false | Disables all toast animation. |
motion
"auto" | "reduced" | "default"
Default: "auto"
Animation mode; "auto" respects prefers-reduced-motion.
disableAnimation
boolean
Default: false
Disables all toast animation.
| Prop | Type | Default | Description |
|---|---|---|---|
regionProps | ToastRegionProps | — | Extra props for the toast region container. |
className | string | — | Class applied to the toast region. |
style | CSSProperties | — | Inline styles for the toast region. |
regionProps
ToastRegionProps
Default: —
Extra props for the toast region container.
className
string
Default: —
Class applied to the toast region.
style
CSSProperties
Default: —
Inline styles for the toast region.
| Prop | Type | Default | Description |
|---|---|---|---|
title | ReactNode | — | Toast title. |
description / message | ReactNode | — | Toast body content. |
icon | ReactNode | — | Overrides the default type-derived icon. |
endContent | ReactNode | — | Content rendered at the end of the toast. |
action | { label: string; onClick?: () => void } | — | An inline action button. |
title
ReactNode
Default: —
Toast title.
description / message
ReactNode
Default: —
Toast body content.
icon
ReactNode
Default: —
Overrides the default type-derived icon.
endContent
ReactNode
Default: —
Content rendered at the end of the toast.
action
{ label: string; onClick?: () => void }
Default: —
An inline action button.
| Prop | Type | Default | Description |
|---|---|---|---|
type | "default" | "info" | "success" | "warning" | "error" | "loading" | derived from color, else "default" | Semantic type, also picks the default icon. |
color | ToastColor | — | Semantic color. |
variant | "solid" | "soft" | "flat" | "bordered" | "flat" | Visual style variant. |
radius | OksRadius | "md" | Border radius. |
size | OksSize | "md" | Toast size. |
type
"default" | "info" | "success" | "warning" | "error" | "loading"
Default: derived from color, else "default"
Semantic type, also picks the default icon.
color
ToastColor
Default: —
Semantic color.
variant
"solid" | "soft" | "flat" | "bordered"
Default: "flat"
Visual style variant.
radius
OksRadius
Default: "md"
Border radius.
size
OksSize
Default: "md"
Toast size.
| Prop | Type | Default | Description |
|---|---|---|---|
position | ToastPosition | provider's position | Per-toast position override. |
position
ToastPosition
Default: provider's position
Per-toast position override.
| Prop | Type | Default | Description |
|---|---|---|---|
duration | number | null | 6000 | Auto-dismiss duration in ms; null disables auto-dismiss. |
persistent | boolean | false | Never auto-dismisses. |
showDurationBar | boolean | false | Shows a countdown progress bar. |
dismissible | boolean | true | Shows a close button. |
promise | Promise<unknown> | — | Drives the promise-aware loading/success/error flow. |
duration
number | null
Default: 6000
Auto-dismiss duration in ms; null disables auto-dismiss.
persistent
boolean
Default: false
Never auto-dismisses.
showDurationBar
boolean
Default: false
Shows a countdown progress bar.
dismissible
boolean
Default: true
Shows a close button.
promise
Promise<unknown>
Default: —
Drives the promise-aware loading/success/error flow.
| Prop | Type | Default | Description |
|---|---|---|---|
onDismiss | (id: ToastId) => void | — | Called when the toast is dismissed. |
onDismiss
(id: ToastId) => void
Default: —
Called when the toast is dismissed.
| Prop | Type | Default | Description |
|---|---|---|---|
closeIcon | ReactNode | — | Overrides the default close icon. |
classNames | ToastClassNames | — | Per-slot class overrides. |
className | string | — | Class applied to this toast's root element. |
closeIcon
ReactNode
Default: —
Overrides the default close icon.
classNames
ToastClassNames
Default: —
Per-slot class overrides.
className
string
Default: —
Class applied to this toast's root element.