Usage
To display a toast, import the useToast
hook and call the toast
function. The only required prop is title
. By default, the toast will render a close button on hover and an icon according to the variant
.
Descriptions
Provide a description
to add more context to your toast.
Variants
Toasts can have different variants to indicate the nature of the message: info
(default), success
, warning
, or error
. Each variant will display a default icon associated with that status. You can also set a custom icon.
Icons
Override the default icon for a toast by passing a FontAwesome icon to the icon
prop.
Actions
To display actions on a toast, import ToastAction
and ToastActionGroup
from stylus-ui/Toast
, and pass them to the action
prop. ToastAction
accepts the same props as <Button>
. Each ToastAction
requires an altText
prop for accessibility.
Dismissing toasts
API Reference
useToast
Most often, the useToast
hook is how you’ll trigger a toast. useToast
returns two objects: toast
and dismiss
.
Prop | Type | Default |
---|---|---|
dismiss | (toastId?: string) => void | |
toast | (props: ToastProps) => { id: string; dismiss: () => void; update: (props: ToastProps) => void } |
Toast
These props can be passed to the toast
function from useToast
.
Prop | Type | Default |
---|---|---|
title | string | |
action | ToastActionElement | |
description | string | |
duration | number | 5000 |
icon | IconDefinition | faInfoCircle |
type | "foreground" "background" | "foreground" |
variant | "info" "success" "warning" "error" | "info" |
Less common props are also available: see Radix UI docs for the full list.
ToastAction
Prop | Type | Default |
---|---|---|
altText | string | |
asChild | boolean | false |
variant | "primary" "secondary" "danger" "ghost" "link" | "primary" |