Dialog
A focus-managed conversation with a clear way back.
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/dialog.jsonUse it
Scroll horizontally for long lines
"use client";
import {
Dialog,
DialogTrigger,
DialogContent,
DialogHeader,
DialogTitle,
DialogDescription,
DialogFooter,
DialogClose,
} from "@/components/jez-ui/ui/dialog";
import { Button } from "@/components/jez-ui/ui/button";
import { FormField } from "@/components/jez-ui/ui/form-field";
import { Input } from "@/components/jez-ui/ui/input";
export default function Example() {
return (
<>
<Dialog>
<DialogTrigger asChild>
<Button>Open dialog</Button>
</DialogTrigger>
<DialogContent showClose={false}>
<DialogHeader>
<DialogTitle>Make it yours.</DialogTitle>
<DialogDescription>
Give your project a name before you begin.
</DialogDescription>
</DialogHeader>
<FormField label="Project name">
<Input placeholder="Field notes" />
</FormField>
<DialogFooter>
<DialogClose asChild>
<Button variant="outline">Close</Button>
</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
</>
);
}
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 { Dialog, DialogTrigger, DialogPortal, DialogClose, DialogOverlay, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription } from "@/components/jez-ui/ui/dialog";Props & types
Scroll horizontally for long lines
React.ComponentProps<typeof P.Root> & {
trigger?: React.ReactNode;
title?: React.ReactNode;
description?: React.ReactNode;
className?: string;
closeLabel?: string;
cancelLabel?: string;
confirmLabel?: string;
}Source
View 3 source files
registry/ui/dialog.tsx
Scroll horizontally for long lines
"use client";
import * as React from "react";
import { Dialog as P } from "radix-ui";
import { X } from "lucide-react";
import { cn } from "./utils";
import { Button } from "./button";
export function Dialog({
trigger,
title,
description,
children,
className,
closeLabel = "Close",
...props
}: React.ComponentProps<typeof P.Root> & {
trigger?: React.ReactNode;
title?: React.ReactNode;
description?: React.ReactNode;
className?: string;
closeLabel?: string;
cancelLabel?: string;
confirmLabel?: string;
}) {
return (
<P.Root {...props}>
{trigger !== undefined ? (
<>
<DialogTrigger asChild>{trigger}</DialogTrigger>
<DialogContent showClose={false} className={className}>
<DialogHeader>
<DialogTitle>{title}</DialogTitle>
<DialogDescription>{description}</DialogDescription>
</DialogHeader>
{children}
<DialogFooter>
<DialogClose asChild>
<Button variant="outline">{closeLabel}</Button>
</DialogClose>
</DialogFooter>
</DialogContent>
</>
) : (
children
)}
</P.Root>
);
}
export const DialogTrigger = P.Trigger;
export const DialogPortal = P.Portal;
export const DialogClose = P.Close;
export function DialogOverlay({
className,
...props
}: React.ComponentProps<typeof P.Overlay>) {
return (
<P.Overlay
className={cn("jez-overlay fixed inset-0 z-50 bg-black/40", className)}
{...props}
/>
);
}
export function DialogContent({
className,
children,
showClose = true,
closeLabel = "Close",
...props
}: React.ComponentProps<typeof P.Content> & {
showClose?: boolean;
closeLabel?: string;
}) {
return (
<P.Portal>
<DialogOverlay />
<P.Content
className={cn(
"jez-popover fixed left-1/2 top-1/2 z-50 w-[min(92vw,460px)] max-h-[85dvh] overflow-auto -translate-x-1/2 -translate-y-1/2 rounded-2xl border border-border bg-background p-7 text-foreground shadow-xl",
className,
)}
{...props}
>
{children}
{showClose && (
<P.Close
aria-label={closeLabel}
className="absolute right-4 top-4 grid size-8 place-items-center rounded-md text-muted-foreground hover:bg-muted"
>
<X size={16} />
</P.Close>
)}
</P.Content>
</P.Portal>
);
}
export function DialogHeader({
className,
...props
}: React.ComponentProps<"div">) {
return <div className={cn("mb-6 grid gap-2 pr-8", className)} {...props} />;
}
export function DialogFooter({
className,
...props
}: React.ComponentProps<"div">) {
return (
<div
className={cn("mt-6 flex flex-wrap justify-end gap-3", className)}
{...props}
/>
);
}
export function DialogTitle({
className,
...props
}: React.ComponentProps<typeof P.Title>) {
return (
<P.Title
className={cn(
"font-display text-xl font-semibold tracking-tight",
className,
)}
{...props}
/>
);
}
export function DialogDescription({
className,
...props
}: React.ComponentProps<typeof P.Description>) {
return (
<P.Description
className={cn("text-sm leading-relaxed text-muted-foreground", className)}
{...props}
/>
);
}
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 · lucide-react@0.577.0 · clsx@2.1.1 · tailwind-merge@3.5.0
Accessibility & behaviour
Provide meaningful labels and preserve keyboard focus styles. Check contrast when customising theme colours.
Read the accessibility and performance guide →