Installation
Add the component
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/react/popover.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 { cn } from "@/lib/utils";
export type PopoverProps = {
trigger?: React.ReactNode;
title?: string;
description?: string;
children?: React.ReactNode;
side?: "top" | "bottom";
className?: string;
};
const pop = { type: "spring", stiffness: 400, damping: 29 } as const;
export function Popover({
trigger = "Share project",
title = "Anyone with the link",
description = "People with the link can view this project but cannot edit it.",
children,
side = "bottom",
className,
}: PopoverProps) {
const [open, setOpen] = React.useState(false);
const reduce = useReducedMotion();
const root = React.useRef<HTMLDivElement>(null);
const titleId = React.useId();
const descriptionId = React.useId();
React.useEffect(() => {
if (!open) return;
const onPointer = (event: PointerEvent) => {
if (!root.current?.contains(event.target as Node)) setOpen(false);
};
const onKey = (event: KeyboardEvent) => {
if (event.key === "Escape") setOpen(false);
};
document.addEventListener("pointerdown", onPointer);
document.addEventListener("keydown", onKey);
return () => {
document.removeEventListener("pointerdown", onPointer);
document.removeEventListener("keydown", onKey);
};
}, [open]);
return (
<div ref={root} className="relative inline-block">
<button
type="button"
aria-haspopup="dialog"
aria-expanded={open}
onClick={() => setOpen((value) => !value)}
className="inline-flex h-8 items-center rounded-md border px-3 text-[13px] font-medium"
>
{trigger}
</button>
<AnimatePresence>
{open && (
<motion.div
role="dialog"
aria-labelledby={titleId}
aria-describedby={descriptionId}
initial={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.8 }}
animate={reduce ? { opacity: 1 } : { opacity: 1, scale: 1 }}
exit={reduce ? { opacity: 0 } : { opacity: 0, scale: 0.8 }}
transition={reduce ? { duration: 0.15 } : pop}
style={{ transformOrigin: side === "top" ? "bottom" : "top" }}
className={cn(
"absolute left-0 z-40 w-64 rounded-xl border bg-popover p-3 text-popover-foreground shadow-xl",
side === "top" ? "bottom-full mb-2" : "top-full mt-2",
className,
)}
>
<p id={titleId} className="text-[13px] font-medium">
{title}
</p>
<p id={descriptionId} className="mt-1 text-[13px] leading-5 text-muted-foreground">
{description}
</p>
{children}
</motion.div>
)}
</AnimatePresence>
</div>
);
}Install
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/react/popover.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 { Popover } from "@/components/prequelui/popover";
export default function Demo() {
return (
<Popover>
{/* compose the parts exactly like the underlying primitive */}
</Popover>
);
}import { Popover } from "@/components/prequelui/popover";
export function Variant() {
return (
<Popover tempo={1.2}>
…
</Popover>
);
}Animation
This primitive keeps the API and semantics of the underlying component and adds motion at the surface edges. Entrances are slower and more settled than exits, so closing never feels like waiting.
- Springs for position, scale and size; tweens for colour and opacity.
- The exit is shorter than the entrance, and keeps the current position as its starting point.
- All measurements are taken again when content or font metrics change.
- With reduced motion, the surface fades in place and never travels.
API Reference
Every part takes exactly the props of the Popover primitive. The animated surface adds only motion props, so the accessibility tree and keyboard behaviour stay the same.
Popover
| Prop | Type | Default |
|---|---|---|
| children | ReactNode | — |
| disabled | boolean | false |
| transition | Transition | spring.press |
| className | string | — |