Installation
Add the component
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/react/accordion.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 { ChevronDown } from "lucide-react";
import { cn } from "@/lib/utils";
export type AccordionItemData = {
value: string;
title: React.ReactNode;
content: React.ReactNode;
};
export type AccordionProps = {
items: AccordionItemData[];
type?: "single" | "multiple";
defaultValue?: string | string[];
collapsible?: boolean;
className?: string;
};
const heightSpring = {
type: "spring",
stiffness: 300,
damping: 30,
bounce: 0,
restDelta: 0.01,
} as const;
const fade = { duration: 0.25, ease: [0.215, 0.61, 0.355, 1] } as const;
function toArray(value: string | string[] | undefined) {
if (value === undefined) return [];
return Array.isArray(value) ? value : [value];
}
export function Accordion({
items,
type = "single",
defaultValue,
collapsible = true,
className,
}: AccordionProps) {
const [open, setOpen] = React.useState<string[]>(() => toArray(defaultValue));
const reduce = useReducedMotion();
const baseId = React.useId();
const toggle = (value: string) => {
setOpen((current) => {
const isOpen = current.includes(value);
if (type === "single") {
if (isOpen) return collapsible ? [] : current;
return [value];
}
return isOpen ? current.filter((entry) => entry !== value) : [...current, value];
});
};
return (
<div data-slot="accordion" className={cn("w-full", className)}>
{items.map((item) => {
const isOpen = open.includes(item.value);
const panelId = `${baseId}-${item.value}`;
return (
<div
key={item.value}
data-slot="accordion-item"
data-state={isOpen ? "open" : "closed"}
className="border-b last:border-b-0"
>
<button
type="button"
aria-expanded={isOpen}
aria-controls={panelId}
onClick={() => toggle(item.value)}
className="flex w-full items-center justify-between gap-4 py-3.5 text-left text-[13.5px] font-medium outline-none transition-colors focus-visible:text-foreground"
>
<span>{item.title}</span>
<motion.span
aria-hidden="true"
animate={{ rotate: isOpen ? 180 : 0 }}
transition={heightSpring}
className="text-muted-foreground"
>
<ChevronDown className="size-4" />
</motion.span>
</button>
<AnimatePresence initial={false}>
{isOpen && (
<motion.div
id={panelId}
role="region"
initial={
reduce
? { opacity: 0 }
: { height: 0, opacity: 0, filter: "blur(2px)" }
}
animate={
reduce
? { opacity: 1 }
: { height: "auto", opacity: 1, filter: "blur(0px)" }
}
exit={
reduce
? { opacity: 0 }
: { height: 0, opacity: 0, filter: "blur(2px)" }
}
transition={
reduce
? { duration: 0.2 }
: { height: heightSpring, opacity: fade, filter: fade }
}
className="overflow-hidden"
>
<div className="pb-4 pr-6 text-[13px] leading-6 text-muted-foreground">
{item.content}
</div>
</motion.div>
)}
</AnimatePresence>
</div>
);
})}
</div>
);
}Install
npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/react/accordion.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 {
Accordion,
AccordionItem,
AccordionTrigger,
AccordionPanel,
} from "@/components/prequelui/accordion";
export default function Demo() {
return (
<Accordion type="single" defaultValue="shipping" collapsible>
<AccordionItem value="shipping">
<AccordionTrigger>When will my order arrive?</AccordionTrigger>
<AccordionPanel>
Standard delivery takes five to seven business days.
</AccordionPanel>
</AccordionItem>
<AccordionItem value="returns">
<AccordionTrigger>What is your return policy?</AccordionTrigger>
<AccordionPanel>
Unused items can be returned within thirty days.
</AccordionPanel>
</AccordionItem>
</Accordion>
);
}import { Accordion } from "@/components/prequelui/accordion";
export function Variant() {
return (
<Accordion tempo={1.2}>
…
</Accordion>
);
}Animation
A panel opens by animating its measured height, then lets opacity and a two-pixel blur resolve the content into place. The bottom edge is masked so the last line never appears to slide under the border.
- Disclosure tween: 350 ms with a soft ease-out on height, opacity and blur.
- The chevron turns 180° on the same window; there is no separate bounce.
- Reopening during the exit continues from the painted height.
- Reduced motion opens the panel instantly and keeps a 200 ms fade.
API Reference
Every part takes exactly the props of the Accordion primitive. The animated surface adds only motion props, so the accessibility tree and keyboard behaviour stay the same.
Accordion
| Prop | Type | Default |
|---|---|---|
| type | "single" | "multiple" | "single" |
| value | string | string[] | — |
| defaultValue | string | string[] | — |
| onValueChange | (value: string | string[]) => void | — |
| collapsible | boolean | true |
| transition | Transition | component spring or tween |
| className | string | — |
AccordionTrigger
| Prop | Type | Default |
|---|---|---|
| hideChevron | boolean | false |
| disabled | boolean | false |
| className | string | — |
AccordionPanel
| Prop | Type | Default |
|---|---|---|
| duration | number | 0.35 |
| blur | number | 2 |
| keepMounted | boolean | false |
| className | string | — |