Skip to content
Noksha UIv0.1
Colour theme

overlay

Toast

Stacked notifications driven by a hook, with pause-on-hover and a swipe-to-dismiss region.

Examples

Tones and actions

Hover a toast to pause its timer. `duration: Infinity` keeps one up until it is acted on.

Updating in place

Pass the id you got back to replace a toast instead of stacking another.

Own the source

Noksha ships as a package and as copy-paste source. Take the files and they are yours to change. These are read from the generated registry, so they are exactly what the library ships — never a paraphrase of it.

Take these files, and internal helpers along with them — the imports below point at them. Or let the CLI do it: npx @noksha-ui/cli add toast writes them, follows the same dependency graph, and fixes up the imports.

export { ToastProvider, toastVariants, useToast } from './toast.js';
export type {
  ToastApi,
  ToastOptions,
  ToastPosition,
  ToastProviderProps,
  ToastRecord,
  ToastTone,
} from './toast.types.js';

API reference

Accepted values

ToastPosition
top-lefttop-centertop-rightbottom-leftbottom-centerbottom-right

ToastOptions

PropTypeDescription
titleReact.ReactNode
descriptionReact.ReactNode
toneToastTone
durationnumberHow long before it dismisses itself. `Infinity` keeps it until acted on.
actionReact.ReactNodeA single action. More than one belongs in a dialog, not a toast.
idstringReuse an id to replace a toast in place — a "saving" that becomes "saved".
onDismiss() => void

ToastRecord

Also accepts everything from ToastOptions.

PropTypeDescription
id*string
open*boolean

ToastProviderProps

PropTypeDescription
childrenReact.ReactNode
positionToastPosition
durationnumberDefault lifetime, in ms.
maxnumberHow many are shown at once. Older ones are dropped. A stack that grows without limit stops being a notification and becomes a wall the user has to dismiss their way through.
containerElement | nullWhere the viewport is portalled to.
labelstringAccessible name for the notification region.

ToastApi

PropTypeDescription
toast*(options: ToastOptions) => stringShows a toast and returns its id.
dismiss*(id: string) => void
dismissAll*() => void
toasts*ToastRecord[]