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.
On this page
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 init2. 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 button3. 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-themesChoose 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.
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.
"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.
Usage 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.
Basic Usage
A complete toast example. Copy this into a client component.
Loading example…
Props & configuration
Everything you need to fine-tune this component.
| Prop | Type | Default | Description |
|---|---|---|---|
title | string | — | Main notification message. |
description | string | — | Supporting text below the title. |
color | "default" | "primary" | "secondary" | "success" | "warning" | "danger" | default | Notification color and matching icon. |
variant | "solid" | "bordered" | "flat" | bordered | Crisp Toast visual style. |
placement | "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right" | bottom-right | Position of the notification stack. |
duration | number | 3000 | Milliseconds before dismissal. Use 0 or Infinity for a persistent toast. |
darkMode | boolean | true | Set from resolvedTheme to match the application appearance. |
pauseOnHover | boolean | false | Pause dismissal while hovering over the notification. |
progressBar | boolean | false | Show a dismissal countdown bar. |
