Feedbackbeta

    Toast

    Notifications powered by Crisp Toast, with light and dark themes, state colors, and stacked messages.

    Follow the installation and quick start below to use Toast in your project, or read the complete setup guide.

    Accessible by designLight & darkCopy. Customize. Ship.
    On this page
    Live previewFluid

    Powered by Crisp Toast. Explore more variants, placements, and async notifications.

    Interactive exampleReact / TypeScript / Tailwind CSS
    ADD TO YOUR PROJECT

    Installation

    1. Initialize once

    Run from an existing React project with Node.js 18 or later. Skip this step if the project already has u-lib.json. Initialization copies the shared stylesheet and adds its import to your application entry.

    npx @scriptwithahmad/u-lib@0.2.2 init

    2. Add Toast and example components

    This command includes the UI components used by this page's usage examples. The CLI copies editable source into your components directory and installs each component's dependencies. Existing source files are preserved.

    npx @scriptwithahmad/u-lib@0.2.2 add button

    3. Install example dependencies

    These packages are imported directly by the examples. Some may already have been installed by the CLI.

    npm install crisp-toast lucide-react next-themes

    Choose the tab for your package manager. Yarn commands require modern Yarn; Yarn Classic users can use npx. Use --dry-run to preview changes. See the installation guide for custom paths, JavaScript output and package-import alternatives.

    USE IN YOUR APP

    Quick start

    Copy this example into src/Example.tsx (or Example.tsx at the project root when you do not use src). Imports assume the default CLI paths. From a nested file such as src/app/page.tsx, adjust ./components to ../components. Keep the client directive in Next.js when using state or event handlers.

    toast-example.tsx
    "use client";
    
    import { toast } from "crisp-toast";
    import "crisp-toast/style.css";
    import { ExternalLink } from "lucide-react";
    import { useTheme } from "next-themes";
    import { Button } from "./components/ui/button";
    
    // Install: npm install crisp-toast
    export default function ToastUi() {
      const { resolvedTheme } = useTheme();
    
      const showToast = (color: "success" | "danger" | "default") => {
        const id = `ulib-toast-${crypto.randomUUID()}`;
        toast({
          id,
          className: "ulib-crisp-toast",
          title: color === "success" ? "Changes saved" : color === "danger" ? "Something went wrong" : "A little update",
          description: color === "danger" ? "Please try your action again." : "Your notification is powered by Crisp Toast.",
          color,
          variant: "bordered",
          placement: "bottom-right",
          duration: 4000,
          darkMode: resolvedTheme === "dark",
          pauseOnHover: true,
        });
        const notification = document.getElementById(id);
        notification?.setAttribute("role", "status");
        notification?.setAttribute("aria-live", "polite");
        notification?.querySelector(".ct-close")?.setAttribute("aria-label", "Dismiss notification");
      };
    
      return (
        <div className="flex max-w-md flex-col items-center gap-5 text-center">
          <div className="flex flex-wrap justify-center gap-3">
            <Button onClick={() => showToast("default")}>Show toast</Button>
            <Button variant="outline" onClick={() => showToast("success")}>Success</Button>
            <Button variant="outline" onClick={() => showToast("danger")}>Error</Button>
          </div>
          <p className="text-sm text-muted-foreground">Powered by Crisp Toast. Explore more variants, placements, and async notifications.</p>
          <div className="flex flex-wrap justify-center gap-x-5 gap-y-3 text-sm">
            <a href="https://www.npmjs.com/package/crisp-toast" target="_blank" rel="noopener noreferrer" className="inline-flex items-center gap-1.5 rounded-sm text-[hsl(var(--brand))] underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
              crisp-toast on npm <ExternalLink className="size-3.5" aria-hidden="true" />
            </a>
            <a href="https://crisp-toast-playground.vercel.app/" target="_blank" rel="noopener noreferrer" className="inline-flex items-center gap-1.5 rounded-sm text-[hsl(var(--brand))] underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring">
              Explore toast playground <ExternalLink className="size-3.5" aria-hidden="true" />
            </a>
          </div>
        </div>
      );
    }

    This page demonstrates Crisp Toast, which is separate from the Radix toast primitives installed by add toast. Crisp Toast needs no toaster provider. The example uses next-themes: mount ThemeProvider in your app, or replace useTheme with your own resolved appearance.

    Keep the shared stylesheet imported once. Replace sample image URLs and data with your own. Examples may use layout utilities beyond the precompiled component styles; compile added Tailwind classes in your app or replace them with your own CSS. Customize local source or className, and preserve accessible names and keyboard behavior.

    BUILD WITH IT

    Usage examples

    1 examples

    Try each example, then switch to Code to copy its complete implementation. These catalog snippets use the website's @/components/ui alias; replace it with your local generated path as shown in Quick start.

    01

    Basic Usage

    A complete toast example. Copy this into a client component.

    Basic Usage

    Loading example…

    THE API

    Props & configuration

    Reference

    Everything you need to fine-tune this component.

    Props and configuration
    PropTypeDefaultDescription
    titlestring—Main notification message.
    descriptionstring—Supporting text below the title.
    color"default" | "primary" | "secondary" | "success" | "warning" | "danger"defaultNotification color and matching icon.
    variant"solid" | "bordered" | "flat"borderedCrisp Toast visual style.
    placement"top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right"bottom-rightPosition of the notification stack.
    durationnumber3000Milliseconds before dismissal. Use 0 or Infinity for a persistent toast.
    darkModebooleantrueSet from resolvedTheme to match the application appearance.
    pauseOnHoverbooleanfalsePause dismissal while hovering over the notification.
    progressBarbooleanfalseShow a dismissal countdown bar.