Veil UI
Components

Toast

A provider, hook and viewport for transient, accessible notifications.

Installation

$ npx veil-ui@latest add toast

Usage

import { Button } from "@/components/ui/button";
import { Toaster, ToastProvider, useToast } from "@/components/ui/toast";

function SaveButton() {
  const { toast } = useToast();
  return (
    <Button
      onClick={() =>
        toast({
          title: "Changes saved",
          description: "Your profile was updated.",
        })
      }
    >
      Save
    </Button>
  );
}

<ToastProvider>
  <SaveButton />
  <Toaster />
</ToastProvider>;

Examples

Basic

    Variants

      With action

        Persistent

          API reference

          useToast()

          Returns { toast, dismiss }. toast(options) queues a message and returns its id; dismiss(id) closes it early.

          PropTypeDefaultDescription
          titleReact.ReactNode—Headline of the toast.
          descriptionReact.ReactNode—Supporting copy.
          variant"default" | "success" | "destructive""default"Visual tone.
          durationnumberprovider duration (5000)Milliseconds before auto-dismiss; use Infinity to keep it open.
          actionReact.ReactNode—Optional inline control such as Undo.

          ToastProvider accepts duration and label (the screen-reader label for the region). Toaster renders the fixed viewport and must be inside the provider.

          Accessibility

          • Radix Toast announces entries through a labelled live region and pauses dismissal while focused or hovered.
          • The close control is named “Dismiss notification”.
          • Use destructive for failures and avoid stacking many toasts at once.

          Vue and plain HTML

          This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add toast --framework vue or switch the framework in components.json.

          <script setup lang="ts">
          import { ToastProvider as RekaToastProvider } from "reka-ui";
          
          import type { ToastSwipeDirection } from "./types";
          import { provideToast } from "./use-toast";
          
          const props = withDefaults(
            defineProps<{
              /** Default auto-dismiss delay for every toast in this provider. */
              duration?: number;
              /** Screen-reader label for the toast region. */
              label?: string;
              /** Direction of the pointer swipe that closes a toast. */
              swipeDirection?: ToastSwipeDirection;
            }>(),
            { duration: 5000, label: "Notification", swipeDirection: "right" },
          );
          
          provideToast();
          </script>
          
          <template>
            <RekaToastProvider
              :duration="props.duration"
              :label="props.label"
              :swipe-direction="props.swipeDirection"
            >
              <slot />
            </RekaToastProvider>
          </template>
          

          On this page