Installation
Add the component
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/react/dialog.jsonFirst component? Set up your project first
Frameworks
The live preview is React. Each tab below is the file that ships for that framework, with the same durations, springs and reduced-motion rule.
"use client";
import * as React from "react";
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import { X } from "lucide-react";
import { cn } from "@/lib/utils";
export type DialogProps = {
trigger?: React.ReactNode;
title?: string;
description?: string;
open?: boolean;
defaultOpen?: boolean;
onOpenChange?: (open: boolean) => void;
children?: React.ReactNode;
className?: string;
};
const popupSpring = { type: "spring", stiffness: 150, damping: 25 } as const;
const veil = { duration: 0.4, ease: [0.215, 0.61, 0.355, 1] } as const;
export function Dialog({
trigger = "Open dialog",
title = "Edit profile",
description = "Make changes to your profile here.",
open,
defaultOpen = false,
onOpenChange,
children,
className,
}: DialogProps) {
const [internal, setInternal] = React.useState(defaultOpen);
const value = open ?? internal;
const reduce = useReducedMotion();
const titleId = React.useId();
const descriptionId = React.useId();
const setOpen = (next: boolean) => {
if (open === undefined) setInternal(next);
onOpenChange?.(next);
};
React.useEffect(() => {
if (!value) return;
const onKey = (event: KeyboardEvent) => {
if (event.key === "Escape") setOpen(false);
};
document.addEventListener("keydown", onKey);
return () => document.removeEventListener("keydown", onKey);
});
return (
<>
<button
type="button"
onClick={() => setOpen(true)}
className="inline-flex h-8 items-center rounded-md bg-foreground px-3 text-[13px] font-medium text-background"
>
{trigger}
</button>
<AnimatePresence>
{value && (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
<motion.button
type="button"
aria-label="Close dialog"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={veil}
onClick={() => setOpen(false)}
className="absolute inset-0 bg-background/60 backdrop-blur-sm"
/>
<motion.div
role="dialog"
aria-modal="true"
aria-labelledby={titleId}
aria-describedby={descriptionId}
initial={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.96, y: 8, filter: "blur(4px)" }}
animate={reduce ? { opacity: 1 } : { opacity: 1, scale: 1, y: 0, filter: "blur(0px)" }}
exit={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.97, y: 4, filter: "blur(2px)" }}
transition={reduce ? { duration: 0.2 } : popupSpring}
className={cn("relative w-full max-w-sm rounded-xl border bg-background p-5 shadow-2xl", className)}
>
<button
type="button"
aria-label="Close"
onClick={() => setOpen(false)}
className="absolute right-3 top-3 rounded-md p-1 text-muted-foreground hover:bg-accent"
>
<X className="size-4" />
</button>
<h2 id={titleId} className="text-[15px] font-medium">{title}</h2>
<p id={descriptionId} className="mt-1.5 text-[13px] leading-6 text-muted-foreground">{description}</p>
{children}
<div className="mt-5 flex justify-end gap-2">
<button type="button" onClick={() => setOpen(false)} className="h-8 rounded-md border px-3 text-[13px]">
Cancel
</button>
<button type="button" onClick={() => setOpen(false)} className="h-8 rounded-md bg-foreground px-3 text-[13px] font-medium text-background">
Save
</button>
</div>
</motion.div>
</div>
)}
</AnimatePresence>
</>
);
}Install
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/react/dialog.jsonDependencies
motion lucide-reactThe registry keeps the component source, its motion tokens and the reduced-motion branch together, so the install never pulls a different animation from the preview.
Usage
Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.
import {
Dialog,
DialogTrigger,
DialogContent,
DialogTitle,
DialogDescription,
DialogFooter,
DialogClose,
} from "@/components/prequelui/dialog";
import { Button } from "@/components/ui/button";
export default function Demo() {
return (
<Dialog>
<DialogTrigger asChild>
<Button>Open dialog</Button>
</DialogTrigger>
<DialogContent side="top">
<DialogTitle>Invite a teammate</DialogTitle>
<DialogDescription>
They will receive an email with a link to join this workspace.
</DialogDescription>
<DialogFooter>
<DialogClose asChild>
<Button variant="ghost">Cancel</Button>
</DialogClose>
<Button>Send invite</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}import { Dialog } from "@/components/prequelui/dialog";
export function Variant() {
return (
<Dialog tempo={1.2}>
…
</Dialog>
);
}Animation
The popup behaves like a card standing on the page: it tips from the edge it belongs to while the veil both tints and blurs the page behind it. The veil animates colour and filter together, never opacity alone.
- Popup spring: stiffness 150, damping 25.
- Entry: perspective 500 px, 20° tilt, scale 0.8, 4 px blur.
- Exit: 200 ms away-ease, faster than the entrance and without the tilt.
- Reopening mid-close starts from the current colour and blur.
- Reduced motion removes the 3D tilt and the blur, keeping the fade.
API Reference
Every part takes exactly the props of the Dialog primitive. The animated surface adds only motion props, so the accessibility tree and keyboard behaviour stay the same.
Dialog
| Prop | Type | Default |
|---|---|---|
| open | boolean | — |
| defaultOpen | boolean | false |
| onOpenChange | (open: boolean) => void | — |
| modal | boolean | true |
| side | "top" | "bottom" | "left" | "right" | "top" |
DialogContent
| Prop | Type | Default |
|---|---|---|
| side | "top" | "bottom" | "left" | "right" | inherited |
| showClose | boolean | true |
| hideOverlay | boolean | false |
| transition | Transition | component spring or tween |
| exitTransition | Transition | 200 ms, away ease |
| className | string | — |
DialogTrigger / DialogClose
| Prop | Type | Default |
|---|---|---|
| asChild | boolean | false |
| className | string | — |