Installation
Add the component
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/page-transition.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, type HTMLMotionProps } from "motion/react";
import { cn } from "@/lib/utils";
import { easeInOut, useReduceMotion } from "./motion";
export type PageTransitionProps = Omit<HTMLMotionProps<"div">, "children"> & {
pageKey: React.Key;
children: React.ReactNode;
duration?: number;
from?: "top" | "bottom" | "left" | "right";
fade?: boolean;
};
function hiddenClip(from: PageTransitionProps["from"]) {
switch (from) {
case "bottom":
return "inset(100% 0 0 0)";
case "left":
return "inset(0 100% 0 0)";
case "right":
return "inset(0 0 0 100%)";
default:
return "inset(0 0 100% 0)";
}
}
export function PageTransition({
pageKey,
children,
duration = 0.55,
from = "top",
fade = true,
className,
...props
}: PageTransitionProps) {
const reduce = useReduceMotion();
return (
<AnimatePresence mode="wait" initial={false}>
<motion.div
key={pageKey}
data-slot="page-transition"
initial={
reduce
? { opacity: 0 }
: { clipPath: hiddenClip(from), opacity: fade ? 0.6 : 1 }
}
animate={{ clipPath: "inset(0 0 0% 0)", opacity: 1 }}
exit={reduce ? { opacity: 0 } : { opacity: 0 }}
transition={reduce ? { duration: 0 } : { duration, ease: easeInOut }}
className={cn("min-w-0", className)}
{...props}
>
{children}
</motion.div>
</AnimatePresence>
);
}Install
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/page-transition.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 { PageTransition } from "@/components/prequelui/page-transition";
export default function Demo() {
return (
<PageTransition pageKey="overview" from="top">
<h2>A calm overview</h2>
<p>Every change, in order.</p>
</PageTransition>
);
}import { PageTransition } from "@/components/prequelui/page-transition";
export function Variant() {
return (
<PageTransition tempo={1.2}>
…
</PageTransition>
);
}Animation
The new view is revealed by a closing inset from the chosen edge. The outgoing page fades underneath, so the swap reads as one surface turning over rather than two pages stacked.
- Reveal: 550 ms on cubic-bezier(0.77, 0, 0.175, 1).
- The inset can start from any of the four edges.
- The outgoing page fades over the same interval.
- Reduced motion replaces the inset with a pure fade.
API Reference
Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.
PageTransition
| Prop | Type | Default |
|---|---|---|
| pageKey | Key | — |
| from | "top" | "bottom" | "left" | "right" | "top" |
| duration | number | 0.55 |
| fade | boolean | true |
| children | ReactNode | — |