Toast

Brief notices for status updates and feedback.

Show a brief notice in the corner. Additional toasts stack behind the first, expand on hover, and dismiss with a downward or rightward swipe.

tsx
"use client"import { Button } from "@/components/ui/button"import { toast } from "@/components/ui/toast"export function Example() {  return (    <Button      variant="outline"      onClick={() => {        const id = toast.add({          title: "Event created",          description: "Sunday, December 3 at 9:00 AM",          actionProps: {            children: "Undo",            onClick() {              toast.close(id)            },          },        })      }}    >      Show Toast    </Button>  )}

Installation

npx @arctis-sh/@arctis-sh/ui@latest add toast

Add Toaster near the root of your app.

import { Toaster } from "@/components/ui/toast"export default function Layout({ children }) {  return (    <html lang="en">      <body>        <Toaster>{children}</Toaster>      </body>    </html>  )}

Usage

import { toast } from "@/components/ui/toast"
toast.add({  title: "Event created",  description: "Sunday, December 3 at 9:00 AM",})

Types

Set type to show a success, info, warning, or error icon. The loading type is used by toast.promise.

tsx
"use client"import { Button } from "@/components/ui/button"import { toast } from "@/components/ui/toast"export function Example() {  return (    <>      <Button        variant="outline"        onClick={() =>          toast.add({ description: "Event has been created." })        }      >        Default      </Button>      <Button        variant="outline"        onClick={() =>          toast.add({            type: "success",            description: "Event has been created.",          })        }      >        Success      </Button>      <Button        variant="outline"        onClick={() =>          toast.add({            type: "info",            description: "Arrive 10 minutes before the event.",          })        }      >        Info      </Button>      <Button        variant="outline"        onClick={() =>          toast.add({            type: "warning",            description: "The event cannot start before 8:00 AM.",          })        }      >        Warning      </Button>      <Button        variant="outline"        onClick={() =>          toast.add({            type: "error",            description: "The event could not be created.",            priority: "high",          })        }      >        Error      </Button>    </>  )}

Action

Pass actionProps to add a small outline button that matches the close control's height.

tsx
"use client"import { Button } from "@/components/ui/button"import { toast } from "@/components/ui/toast"export function Example() {  return (    <Button      variant="outline"      onClick={() => {        const id = toast.add({          title: "Event created",          actionProps: {            children: "Undo",            onClick() {              toast.close(id)            },          },        })      }}    >      Show Toast    </Button>  )}
const id = toast.add({  title: "Event created",  actionProps: {    children: "Undo",    onClick() {      toast.close(id)    },  },})

Promise

Use toast.promise to move one toast from loading to success or error.

tsx
"use client"import { Button } from "@/components/ui/button"import { toast } from "@/components/ui/toast"export function Example() {  return (    <Button      variant="outline"      onClick={() => {        toast.promise(          new Promise<{ name: string }>((resolve) => {            window.setTimeout(() => resolve({ name: "Event" }), 2000)          }),          {            loading: "Creating event…",            success: (data) => `${data.name} created.`,            error: "Could not create event.",          },        )      }}    >      Create Event    </Button>  )}

API Reference

toast

MethodTypeDescription
add(options) => stringCreate a toast and return its id
close(id?: string) => voidDismiss one toast, or all if no id
update(id, options) => voidPatch an existing toast
promise(promise, options) => PromiseDrive loading → success/error
toast.add({ title: "Saved" })

toast.add options

PropTypeDefault
titleReactNode
descriptionReactNode
type"success" | "info" | "warning" | "error" | "loading" | string
timeoutnumber5000
priority"low" | "high""low"
actionPropsbutton props
onClose() => void
onRemove() => void
toast.add({  title: "Saved",  description: "Your changes were stored.",  type: "success",})

toast.promise options

PropTypeDefault
loadingstring | options
successstring | options | (data) => …
errorstring | options | (error) => …
toast.promise(save(), {  loading: "Saving…",  success: "Saved",  error: "Something went wrong",})

Toaster

PropTypeDefault
timeoutnumber5000
limitnumber3
toastManagerToastManagershared manager
childrenReactNode

Hover or focus the viewport to expand the stack. Toasts beyond limit stay mounted with data-limited, allowing them to fade instead of disappearing at once.

<Toaster timeout={5000} limit={3} />