Toast
Toast with thoughtful defaults, semantic styling, and editable source.
Make it yours.
Install the editable source and its dependencies into your React + Tailwind project.
Scroll horizontally for long lines
pnpm dlx shadcn@4.0.8 add http://localhost:3000/r/toast.jsonUse it
Scroll horizontally for long lines
"use client";
import { Toast } from "@/components/jez-ui/ui/toast";
export default function Example() {
return (
<>
<Toast
title="Changes saved"
description="Your project is ready for its next chapter."
/>
</>
);
}
Compose your own
These styled parts are included in the same install. Use children to build your layout; add className only when you want an override.
Scroll horizontally for long lines
import { Toast, ToastProvider, ToastRoot, ToastViewport, ToastTitle, ToastDescription, ToastClose, ToastAction } from "@/components/jez-ui/ui/toast";Props & types
Scroll horizontally for long lines
{
title: React.ReactNode;
description: React.ReactNode;
trigger?: React.ReactNode;
dismissLabel?: string;
className?: string;
}Source
View 3 source files
registry/ui/toast.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { cn } from "./utils";
import { Toast as P } from "radix-ui";
import { Button } from "./button";
export const ToastProvider = P.Provider;
export function ToastRoot({
className,
...props
}: React.ComponentProps<typeof P.Root>) {
return (
<P.Root
className={cn(
"jez-popover rounded-xl border border-border bg-background p-5 text-foreground shadow-lg data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=cancel]:translate-x-0 data-[swipe=cancel]:transition-transform",
className,
)}
{...props}
/>
);
}
export function ToastViewport({
className,
...props
}: React.ComponentProps<typeof P.Viewport>) {
return (
<P.Viewport
className={cn(
"fixed bottom-5 right-5 z-[100] grid w-[min(90vw,360px)] gap-3 outline-none",
className,
)}
{...props}
/>
);
}
export function ToastTitle({
className,
...props
}: React.ComponentProps<typeof P.Title>) {
return <P.Title className={cn("font-medium", className)} {...props} />;
}
export function ToastDescription({
className,
...props
}: React.ComponentProps<typeof P.Description>) {
return (
<P.Description
className={cn(
"mt-1 text-sm leading-relaxed text-muted-foreground",
className,
)}
{...props}
/>
);
}
export function ToastClose({
className,
...props
}: React.ComponentProps<typeof P.Close>) {
return (
<P.Close
className={cn(
"mt-3 rounded text-sm underline underline-offset-4",
className,
)}
{...props}
/>
);
}
export function ToastAction({
className,
...props
}: React.ComponentProps<typeof P.Action>) {
return (
<P.Action
className={cn(
"mt-3 inline-flex items-center justify-center rounded-md border border-border px-3 py-2 text-sm font-medium hover:bg-muted",
className,
)}
{...props}
/>
);
}
export function Toast({
title,
description,
trigger = "Show notification",
dismissLabel = "Dismiss",
className,
}: {
title: React.ReactNode;
description: React.ReactNode;
trigger?: React.ReactNode;
dismissLabel?: string;
className?: string;
}) {
const [open, setOpen] = React.useState(false);
return (
<ToastProvider swipeDirection="right">
<Button variant="outline" onClick={() => setOpen(true)}>
{trigger}
</Button>
<ToastRoot open={open} onOpenChange={setOpen} className={className}>
<ToastTitle>{title}</ToastTitle>
<ToastDescription>{description}</ToastDescription>
<ToastClose aria-label={dismissLabel}>{dismissLabel}</ToastClose>
</ToastRoot>
<ToastViewport />
</ToastProvider>
);
}
registry/ui/utils.ts
Scroll horizontally for long lines
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";
export function cn(...values: ClassValue[]) {
return twMerge(clsx(values));
}
registry/ui/button.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { Slot } from "radix-ui";
import { LoaderCircle } from "lucide-react";
import { cn } from "./utils";
export type ButtonProps = React.ComponentProps<"button"> & {
variant?: "primary" | "secondary" | "outline" | "ghost" | "danger";
size?: "sm" | "md" | "lg";
loading?: boolean;
asChild?: boolean;
};
export function Button({
variant = "primary",
size = "md",
loading,
asChild,
className,
children,
disabled,
...props
}: ButtonProps) {
const Comp = asChild ? Slot.Root : "button";
return (
<Comp
type={asChild ? undefined : "button"}
disabled={asChild ? undefined : disabled || loading}
aria-disabled={disabled || loading || undefined}
aria-busy={loading || undefined}
className={cn(
"relative inline-flex shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-lg border border-transparent text-sm font-medium leading-none transition-[background-color,border-color,box-shadow,transform] duration-150 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary active:scale-[.98] disabled:pointer-events-none disabled:opacity-45 aria-disabled:pointer-events-none [&_svg]:shrink-0",
{
"bg-primary text-primary-foreground shadow-[inset_0_1px_0_#ffffff26,0_1px_2px_#00000012] hover:bg-primary/90":
variant === "primary",
"border-border/60 bg-muted text-foreground hover:bg-muted/70":
variant === "secondary",
"border-border bg-background text-foreground shadow-sm hover:bg-muted/60":
variant === "outline",
"text-muted-foreground hover:bg-muted hover:text-foreground":
variant === "ghost",
"bg-danger text-danger-foreground hover:bg-danger/90":
variant === "danger",
},
{
"h-8 px-3 text-xs": size === "sm",
"h-10 px-4": size === "md",
"h-12 px-6": size === "lg",
},
className,
)}
{...props}
>
{asChild ? (
children
) : (
<>
<span
className={cn(
"inline-flex min-w-0 flex-1 items-center justify-center gap-2",
loading && "invisible",
)}
>
{children}
</span>
{loading && (
<LoaderCircle
aria-hidden="true"
className="absolute size-4 animate-spin motion-reduce:animate-none"
/>
)}
</>
)}
</Comp>
);
}
Dependencies
radix-ui@1.6.7 · clsx@2.1.1 · tailwind-merge@3.5.0 · lucide-react@0.577.0
Accessibility & behaviour
Provide meaningful labels and preserve keyboard focus styles. Check contrast when customising theme colours.
Read the accessibility and performance guide →