Toast

Transient messages with tone, a leading slot, and screen position.

Also known as: snackbar, notification toast, toast message, toast notification

Installation

Install with the CLI, or copy the component source into your project.

Add toast (npm)

npx --yes -p @default-file/ui df-ui add toast

Tones

Default success, error, info, and warning cards. Each tone sets the accent and the default leading icon.

Saved successfully

Something went wrong

Heads up

Check this value

Leading

Pass leading to replace the tone icon with any node, or null to hide the slot. Custom icons inherit the tone accent through currentColor unless you set a color.

Export ready for download

Custom mark in the leading slot

Message only, no leading

Chrome

Tune fill, border, shadow, radius, padding block and inline, inner gap, width, height, and close visibility with props or --df-toast-* variables. Stack gap and width use --df-toaster-* on Toaster.

Roomier padding and softer shadow

Custom fill, border, and no close

Fixed min height

Position

Place live toasts in any corner, along an edge centre, or dead centre. Use the direction pad to try each spot.

Active: Bottom right

Properties

Transient messages. Render Toast for static chrome, or mount Toaster once and call toast helpers for live messages. Tune chrome with props or --df-toast-* / --df-toaster-* CSS variables.

Toast

Presentational toast card. Toaster renders the same chrome for live messages.

PropTypeDefaultNotes
tone"success" | "error" | "info" | "warning"-Accent for the leading icon. Also selects the default leading icon when leading is omitted.
messagestring-Primary toast copy.
leadingReactNode-Leading slot before the message. Defaults to the tone icon. Pass a custom icon or node to replace it, or null to hide the slot. Custom icons inherit the tone accent through currentColor unless you set a color.
onDismiss() => void-When set, renders an interactive dismiss control. Omit for static chrome with a non-interactive close glyph when showClose is true.
backgroundstring-Card fill. Sets --df-toast-bg.
foregroundstring-Card text color. Sets --df-toast-fg.
borderColorstring-Card border color. Sets --df-toast-border.
borderWidthstring-Card border width. Sets --df-toast-border-width.
radiusstring-Card corner radius. Sets --df-toast-radius.
shadowstring-Card box shadow. Sets --df-toast-shadow.
paddingBlockstring-Top and bottom padding. Sets --df-toast-padding-block.
paddingInlinestring-Left and right padding. Sets --df-toast-padding-inline.
gapstring-Gap between leading, message, and close. Sets --df-toast-gap.
widthstring-Card width. Sets --df-toast-width. Default 100% of the stack.
heightstring-Card height. Sets --df-toast-height. Default auto.
minHeightstring-Card minimum height. Sets --df-toast-min-height.
showClosebooleantrueShow the close control. Set false to hide it.
cornerShape"round" | "smooth"-Instance corner curve. Omit to inherit --df-corner-shape from the theme (set at create/init).
classNamestring-Additional styles on the toast root.
styleCSSProperties-Inline styles. Merged after chrome props. Prefer chrome props or --df-toast-* variables.

Toaster

Portal host for live toasts. Mount once near the app root. Live toasts auto-dismiss after 3200ms. Card chrome props on Toaster inherit to every toast in the stack.

PropTypeDefaultNotes
position"top-left" | "top-center" | "top-right" | "left-center" | "center" | "right-center" | "bottom-left" | "bottom-center" | "bottom-right""bottom-right"Screen corner, edge centre, or dead centre for the stack.
stackWidthstring-Stack width. Sets --df-toaster-width.
stackGapstring-Gap between stacked toasts. Sets --df-toaster-gap.
insetstring-Distance from the viewport edge. Sets --df-toaster-inset.
viewportGutterstring-Horizontal viewport reserve used in the stack max-width clamp. Sets --df-toaster-viewport-gutter.
backgroundstring-Card fill. Sets --df-toast-bg.
foregroundstring-Card text color. Sets --df-toast-fg.
borderColorstring-Card border color. Sets --df-toast-border.
borderWidthstring-Card border width. Sets --df-toast-border-width.
radiusstring-Card corner radius. Sets --df-toast-radius.
shadowstring-Card box shadow. Sets --df-toast-shadow.
paddingBlockstring-Top and bottom padding. Sets --df-toast-padding-block.
paddingInlinestring-Left and right padding. Sets --df-toast-padding-inline.
gapstring-Gap between leading, message, and close. Sets --df-toast-gap.
widthstring-Card width. Sets --df-toast-width. Default 100% of the stack.
heightstring-Card height. Sets --df-toast-height. Default auto.
minHeightstring-Card minimum height. Sets --df-toast-min-height.
showClosebooleantrueShow the close control. Set false to hide it.
cornerShape"round" | "smooth"-Instance corner curve. Omit to inherit --df-corner-shape from the theme (set at create/init).
classNamestring-Additional styles on the toaster root.
styleCSSProperties-Inline styles on the toaster root. Merged after stack and chrome props.

Helpers

Imperative helpers for showing and dismissing live toasts. Requires a mounted Toaster.

PropTypeDefaultNotes
toast.success(message: string, options?: ToastShowOptions) => string-Show a success toast. Returns the toast id.
toast.error(message: string, options?: ToastShowOptions) => string-Show an error toast. Returns the toast id.
toast.info(message: string, options?: ToastShowOptions) => string-Show an info toast. Returns the toast id.
toast.warning(message: string, options?: ToastShowOptions) => string-Show a warning toast. Returns the toast id.
toast.dismiss(id?: string) => void-Dismiss one toast by id, or all toasts when id is omitted.
setToastPosition(position: ToastPosition) => void-Update where new and existing live toasts stack. Same values as Toaster position.

ToastShowOptions

Optional second argument to toast.success, toast.error, toast.info, and toast.warning.

PropTypeDefaultNotes
leadingReactNode-Same contract as Toast leading. Replaces the tone icon, or null to hide the slot.

Tokens

Theme defaults live on :root. Override globally, on Toaster (inherits to the stack), or on Toast. Chrome props set the matching variables.

TokenTypeDefaultNotes
--df-toaster-widthCSS length22remToaster stack width.
--df-toaster-gapCSS lengthcalc(2 * var(--spacing-unit))Gap between stacked toasts.
--df-toaster-insetCSS lengthcalc(4 * var(--spacing-unit))Distance from the viewport edge.
--df-toaster-viewport-gutterCSS lengthcalc(8 * var(--spacing-unit))Horizontal viewport reserve for the stack max-width clamp.
--z-toastnumber60Stack layer above overlays.
--df-toast-widthCSS length100%Toast card width.
--df-toast-heightCSS lengthautoToast card height.
--df-toast-min-heightCSS lengthautoToast card minimum height.
--df-toast-bgCSS colorvar(--popover)Toast fill.
--df-toast-fgCSS colorvar(--popover-foreground)Toast text color.
--df-toast-borderCSS colorvar(--border)Toast border color.
--df-toast-border-widthCSS lengthvar(--border-width-hairline)Toast border width.
--df-toast-radiusCSS lengthvar(--radius)Toast corner radius.
--df-toast-shadowCSS shadowvar(--df-shadow-lg)Toast box shadow.
--df-toast-padding-blockCSS lengthcalc(3 * var(--spacing-unit))Top and bottom padding.
--df-toast-padding-inlineCSS lengthcalc(3.5 * var(--spacing-unit))Left and right padding.
--df-toast-gapCSS lengthcalc(2.5 * var(--spacing-unit))Gap between leading, message, and close.
--df-toast-icon-successCSS colorvar(--success)Success tone icon accent.
--df-toast-icon-errorCSS colorvar(--destructive)Error tone icon accent.
--df-toast-icon-warningCSS colorvar(--warning)Warning tone icon accent.
--df-toast-icon-infoCSS colorvar(--muted-foreground)Info tone icon accent.
--df-toast-close-sizeCSS lengthvar(--df-control-height-2xs)Close control width and height.
--df-toast-close-fgCSS colorvar(--muted-foreground)Close control icon color.
--df-toast-close-hover-bgCSS colorvar(--muted)Close control hover fill.
--df-toast-close-hover-fgCSS colorvar(--foreground)Close control hover icon color.
--df-corner-shapeCSS corner-shapevar(--df-corner-shape-round)Theme corner curve for all kit chrome. round = circular arcs; smooth = continuous squircle. Set with df-ui init --corner-shape, or override on :root. Default round.