Skip to Content
NarakUI

Toast

A notification component that displays temporary messages to users, typically for feedback on actions or system status.

Basic

Call a method from useToast to show a toast. Toasts appear in ToastRenderer, so render it once near the root of the app.

Types

success and warning toasts show an icon. progress and loading toasts stay open until they are dismissed; see Progress and loading.

Duration

duration sets how long a toast stays open, in milliseconds. The default is 3500. The timer pauses while the pointer is over the toasts.

With actions

actionLabel and onAction add a button to the toast. The toast closes after the action runs. With a description, the button sits under it by default; set actionPlacement: 'inline' to keep it beside the text.

Progress and loading

toast.progress() shows a progress bar under the description and has no close button. Update it with toast.updateProgress(id, progress) and close it with toast.dismiss(id). toast.loading() shows a spinner and stays open until it is closed.

Dismiss

Set duration: 0 to keep a toast open until it is closed. toast.dismiss(id) closes a toast from code, using the id the method returned. onDismiss runs only when the person closes the toast with the close button or a swipe.

Installation

pnpm dlx shadcn@latest add @narakui/toast

Add "@narakui": "https://ui.narakcode.dev/r/{name}.json" to components.json, or install directly from https://ui.narakcode.dev/r/toast.json.

Usage

import { ToastRenderer, useToast } from '@/components/ui/toast';

function App() {
  return (
    <>
      <Page />
      <ToastRenderer />
    </>
  );
}

function SaveButton() {
  const toast = useToast();

  return (
    <button
      onClick={() =>
        toast.success({
          heading: 'Report saved',
          description: 'Your visibility report is ready to share.',
        })
      }
    >
      Save report
    </button>
  );
}

Toast Options

PropTypeDefaultDescription
idstring—Custom identifier for the toast (auto-generated if omitted)
headingstring—The main title of the toast. Without it, the description becomes the title, or a default title for the type is used
descriptionstring—The description text of the toast notification
durationnumber3500Duration in milliseconds before the toast auto-dismisses (0 = persistent). Ignored for progress and loading toasts
type'success' | 'warning' | 'default' | 'progress' | 'loading''default'The type of toast notification. The toast methods set it for you
actionLabelstring—Label for the action button. Shown only together with onAction
onAction() => void—Callback fired when the action button is clicked. The toast closes after it runs
actionPlacement'stacked' | 'inline''stacked'Where the action button sits when there is a description: under it, or beside the text
onDismiss() => void—Callback fired when the person closes the toast with the close button or a swipe. Not called when the timer ends, the action runs, or code dismisses it
progressnumber0Progress value (0–100) for progress toasts. The bar shows only with a description
iconReact.ReactNode—Custom icon to display in the toast. Pass null to hide the icon of the type
descriptionLineClamp2 | 5 | 'none'2How many lines of description copy to show
data-dd-privacy'mask'—Masks the toast's text in session replay. Screen readers then hear only the heading, so keep names in the description

Toast Methods

MethodTypeDescription
toast()(options: ToastOptions) => stringShows a default toast and returns its id
toast.success()(options: ToastOptions) => stringShows a success toast and returns its id
toast.warning()(options: ToastOptions) => stringShows a warning toast and returns its id
toast.default()(options: ToastOptions) => stringShows a default toast and returns its id
toast.progress()(options: ToastOptions) => stringShows a progress toast that stays open until dismissed. It has no close button
toast.loading()(options: ToastOptions) => stringShows a loading toast that stays open until it is closed
toast.dismiss()(toastId: string) => voidDismisses a toast by id
toast.updateProgress()(toastId: string, progress: number, message?: string) => voidUpdates a progress toast's value and, optionally, its description