Tonic UI
Getting StartedColor ModeColor StyleVersionsContributing
THEME
BordersBreakpointsColorsOutlinesPositionsSpacingSizesShadowsTypography
BUILDING BLOCKS
BoxControlBox
UTILITIES

Toast

A toast notification is a small popup that appears at either side of the screen, and disappears after a short time. The toast notification is used to notify the user of something that has happened, but it is not intended to be used as a permanent message.

Import

Usage

Add ToastProvider to the root.

For the Hook version, use the useToast Hook to get all the methods, properties, and state. See the useToast Hook section for detailed usage.

Layout

  • Increase the vertical padding space to 4x (or 1rem) for a multiline paragraph.
  • Set the minimum horizontal margin space to 4x (or 1rem) before the close button.
  • Set the minimum horizontal margin space to 4x (or 1rem) between the icon and the content.
  • Apply vertical margin space with 2x (or .5rem) between the title and its content.
  • Apply vertical margin space with 6x (or 1.5rem) between the end of the content and the action button (or action link).
EDITABLE EXAMPLE

Appearances

You can control the appearance of a toast notification. If specified, the value can be one of success, info, warning, or error.

EDITABLE EXAMPLE

Icons

The icon prop allows you to override the default icon for the specified appearance.

Setting the icon prop to false will remove the icon altogether.

EDITABLE EXAMPLE

Toast

NameTypeDefaultDescription
isClosablebooleanIf true, a close button will appear on the right side.
onClosefunctionA callback called when the close button is clicked.
appearancestring'none'One of: 'none', 'success', 'info', 'warning', 'error'
iconstring | ReactNode | falseOverride the icon displayed before the children. Unless provided, the icon is mapped to the value of the appearance prop.

ToastProvider

NameTypeDefaultDescription
childrenReactNode
containerDOM element
placementstring'bottom-right'Set the default placement to place toasts. One of: 'top', 'top-right', 'top-left', 'bottom', 'bottom-left', 'bottom-right'

useToast Hook

The useToast hook has the following signature:

toast.close(id)

Close a toast at its placement.

Arguments

  • id (string): The id to close the toast.

Returns

This method returns undefined.

toast.closeAll([options={}])

Close all toasts at once with the given placements, including top, top-left, top-right, bottom, bottom-left, bottom-right.

Arguments

  • [options={}] (Object): The options object.
  • [options.placements=[]] (Array): An array of placements to close toasts.

Returns

This method returns undefined.

toast.find(id)

Find the first toast in the array that matches the provided toast id. Otherwise, undefined is returned if not found. If no values satisfy the testing function, undefined is returned.

Arguments

  • id (string): The id to find the toast.

Returns

(Object): Returns the toast object.

toast.findIndex(id)

Find the first toast in the array that matches the provided toast id. Otherwise, -1 is returned if not found.

Arguments

  • id (string): The id to find the toast.

Returns

(number): Returns the array index.

toast.notify(message, [options={}])

Create a toast at the specified placement and return the toast id.

Arguments

  • message (Function|string): The toast message to render.
  • [options={}] (Object): The options object.
  • [options.duration=null] (number): The duration (in milliseconds) that the toast should remain on the screen. If set to null, toast will never dismiss.
  • [options.id] (string): A unique ID of the toast.
  • [options.placement] (string): The placement of the toast.

Aliases

toast(message, [options={}])

Returns

(string): Returns the toast id.

toast.update(id, [options={}])

Update a specific toast with new options based on the given toast id.

Arguments

  • id (string): The id to update the toast.
  • [options={}] (Object): The options object.
  • [options.duration=null] (number): The duration (in milliseconds) that the toast should remain on the screen. If set to null, toast will never dismiss.
  • [options.message] (Function|string): The toast message to render.

Returns

Returns true if the toast exists, else false.

toast.placement

Specify the placement to place the toast. The default placement will be used if the placement option is not explicitly specified.

toast.state

The toast state is a placement object, each placement contains an array of objects representing the current toasts.