Toast
A toast system — provider, imperative API, tones, and a live region for screen readers.
Live — this one is real
Usage
"use client";
import type { ReactNode } from "react";
import { Button, ToastProvider, useToast } from "mizu-ui";
export function App({ children }: { children: ReactNode }) {
return <ToastProvider>{children}</ToastProvider>;
}
export function Saver() {
const { toast } = useToast();
const notify = () => toast("Notification received", { tone: "success" });
return <Button onClick={notify}>Notify</Button>;
}
It starts with "use client" because it keeps state or passes functions to components, so it pastes into a Next.js page as it is. Other React setups ignore the directive.
Source & setup
Add this component to your project with the shadcn CLI. The command copies its source into your configured UI directory, with base.css, Mizu’s tokens, and the stylesheets that hold its rules. Each rule lives in one stylesheet, so components you add together never repeat CSS. In a project without a components.json, run npx shadcn@latest init 0xuser64bit/mizu/preset first: plain init installs shadcn’s theme into your global CSS. Then load the fonts.
npx shadcn@latest add 0xuser64bit/mizu/toast 0xuser64bit/mizu/buttonThe example also uses Button, so the command adds it too.
Every component imports from its own path, its name in kebab case. To paste the example, replace its mizu-ui import with:
import { ToastProvider, useToast } from "@/components/ui/mizu/toast";
import { Button } from "@/components/ui/mizu/button";For npm imports, import mizu-ui/styles.css once. Fonts are optional via mizu-ui/fonts.css. Override --mizu-* tokens or use className for local styling. Requires React and Motion. A Client Component: its source starts with “use client”.
Inspect feedback/Toast.tsx
Source is included in the npm package under src/feedback/Toast.tsx.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| toast | (message, options?) => void | — | Push a toast. options: tone (default | success | error), duration (ms). |
Accessibility
The viewport is aria-live=polite — toasts are announced without stealing focus.
Motion
Expo rise on enter, slide-fade on exit. Maximum 4 visible; oldest is replaced.