Navigation
Fold Accordion
An accordion whose panels unfold like a sheet of paper.
Installation
npx shadcn@latest add https://relic-ui.vercel.app/r/fold-accordion.jsonOr straight from GitHub: npx shadcn@latest add relicui/relic-ui/fold-accordion
Manual installation
1. Install the dependencies:
npm install motion2. Copy this code into components/ui/fold-accordion.tsx:
"use client"
/**
* Relic UI · Fold Accordion
* https://relic-ui.vercel.app/docs/fold-accordion
*
* Copyright (c) 2026 Shubham Tambe
* Open source under the MIT License: https://relic-ui.vercel.app/license
*/
import { useId, useRef, useState } from "react"
import { AnimatePresence, motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"
export type FoldAccordionItem = {
value: string
title: React.ReactNode
content: React.ReactNode
}
const VARIANTS = {
bordered: { root: "divide-y overflow-hidden rounded-xl border", item: "" },
separated: { root: "flex flex-col gap-2", item: "overflow-hidden rounded-xl border" },
plain: { root: "divide-y", item: "" },
} as const
const SPRINGINESS = {
subtle: { type: "spring", stiffness: 260, damping: 30 },
paper: { type: "spring", stiffness: 150, damping: 17, mass: 0.9 },
bouncy: { type: "spring", stiffness: 170, damping: 10 },
} as const
const HEIGHT = { duration: 0.45, ease: [0.22, 1, 0.36, 1] } as const
const FOLD = { duration: 0.28, ease: [0.4, 0, 1, 1] } as const
const INSTANT = { duration: 0 } as const
export interface FoldAccordionProps
extends Omit<React.ComponentProps<"div">, "defaultValue" | "onChange"> {
items: FoldAccordionItem[]
/** Allow more than one panel open at a time. */
multiple?: boolean
/** Open panels (controlled). */
value?: string[]
/** Panels open at first (uncontrolled). */
defaultValue?: string[]
onValueChange?: (value: string[]) => void
/** Look of the accordion. */
variant?: keyof typeof VARIANTS
/** How the sheet settles as it unfolds. */
springiness?: keyof typeof SPRINGINESS
/** How far (in degrees) a closed panel is folded back. */
foldAngle?: number
/** Show the soft shadow along the fold as a panel opens. */
showCrease?: boolean
/** The open/close indicator on each header. */
icon?: "chevron" | "plus" | "none"
/** Which side of the header the icon sits on. */
iconPosition?: "left" | "right"
}
export function FoldAccordion({
items,
multiple = false,
value: valueProp,
defaultValue,
onValueChange,
variant = "bordered",
springiness = "paper",
foldAngle = 92,
showCrease = true,
icon = "chevron",
iconPosition = "right",
className,
...props
}: FoldAccordionProps) {
const baseId = useId()
const rootRef = useRef<HTMLDivElement>(null)
const reduceMotion = useReducedMotion()
const [internalValue, setInternalValue] = useState<string[]>(
defaultValue ?? []
)
const open = valueProp ?? internalValue
function toggle(itemValue: string) {
const isOpen = open.includes(itemValue)
const next = isOpen
? open.filter((v) => v !== itemValue)
: multiple
? [...open, itemValue]
: [itemValue]
if (valueProp === undefined) setInternalValue(next)
onValueChange?.(next)
}
// Up / Down / Home / End move between headers (WAI-ARIA accordion pattern).
function handleKeyDown(e: React.KeyboardEvent<HTMLButtonElement>) {
const triggers = Array.from(
rootRef.current?.querySelectorAll<HTMLButtonElement>(
'[data-slot="fold-accordion-trigger"]'
) ?? []
)
const index = triggers.indexOf(e.currentTarget)
const last = triggers.length - 1
const next =
e.key === "ArrowDown"
? index === last ? 0 : index + 1
: e.key === "ArrowUp"
? index === 0 ? last : index - 1
: e.key === "Home"
? 0
: e.key === "End"
? last
: -1
if (next === -1) return
e.preventDefault()
triggers[next]?.focus()
}
const folded = { rotateX: -foldAngle, opacity: 0 }
return (
<div
ref={rootRef}
data-slot="fold-accordion"
data-variant={variant}
className={cn("w-full", VARIANTS[variant].root, className)}
{...props}
>
{items.map((item, index) => {
const isOpen = open.includes(item.value)
const triggerId = `${baseId}-trigger-${index}`
const panelId = `${baseId}-panel-${index}`
return (
<div
key={item.value}
data-state={isOpen ? "open" : "closed"}
className={VARIANTS[variant].item}
>
<h3 className="flex">
<button
id={triggerId}
type="button"
data-slot="fold-accordion-trigger"
aria-expanded={isOpen}
aria-controls={panelId}
onClick={() => toggle(item.value)}
onKeyDown={handleKeyDown}
className={cn(
"flex flex-1 items-center justify-between gap-4 py-4 text-left text-sm font-medium transition-colors",
"outline-none hover:bg-muted/40 focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:ring-inset",
variant === "plain" ? "px-1" : "px-4"
)}
>
{iconPosition === "left" && (
<TriggerIcon icon={icon} open={isOpen} />
)}
<span className="flex-1">{item.title}</span>
{iconPosition === "right" && (
<TriggerIcon icon={icon} open={isOpen} />
)}
</button>
</h3>
<AnimatePresence initial={false}>
{isOpen && (
<motion.div
key="panel"
id={panelId}
role="region"
aria-labelledby={triggerId}
className="overflow-hidden"
style={{ perspective: 900 }}
initial={{ height: 0 }}
animate={{ height: "auto" }}
exit={{ height: 0, transition: reduceMotion ? INSTANT : FOLD }}
transition={reduceMotion ? INSTANT : HEIGHT}
>
{/* The sheet is hinged at its top edge and swings down into place, like unfolding paper. */}
<motion.div
className={cn(
"relative pb-4 text-sm text-muted-foreground",
variant === "plain" ? "px-1" : "px-4"
)}
style={{ transformOrigin: "top center" }}
initial={reduceMotion ? false : folded}
animate={{ rotateX: 0, opacity: 1 }}
exit={
reduceMotion
? { opacity: 0, transition: INSTANT }
: { ...folded, transition: FOLD }
}
transition={SPRINGINESS[springiness]}
>
{item.content}
{/* Crease shadow that fades as the sheet flattens out. */}
{showCrease && <motion.span
aria-hidden
className="pointer-events-none absolute inset-0 bg-gradient-to-b from-foreground/15 via-foreground/5 to-transparent"
initial={reduceMotion ? false : { opacity: 1 }}
animate={{ opacity: 0 }}
exit={{ opacity: 1, transition: FOLD }}
transition={{ duration: 0.6, ease: "easeOut" }}
/>}
</motion.div>
</motion.div>
)}
</AnimatePresence>
</div>
)
})}
</div>
)
}
/** The open/close indicator: a chevron that flips, or a plus that turns into a minus. */
function TriggerIcon({
icon,
open,
}: {
icon: "chevron" | "plus" | "none"
open: boolean
}) {
if (icon === "none") return null
return (
<svg
aria-hidden
viewBox="0 0 16 16"
fill="none"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
className={cn(
"size-4 shrink-0 text-muted-foreground transition-transform duration-300",
icon === "chevron" && open && "rotate-180"
)}
>
{icon === "chevron" ? (
<path d="M4 6l4 4 4-4" />
) : (
<>
<path d="M3.5 8h9" />
<path
d="M8 3.5v9"
className={cn(
"origin-center transition-transform duration-300 [transform-box:fill-box]",
open && "scale-y-0"
)}
/>
</>
)}
</svg>
)
}Usage
import { FoldAccordion } from "@/components/ui/fold-accordion"
const items = [
{
value: "what",
title: "What is Relic UI?",
content:
"A collection of animated React components you add straight into your project with the shadcn CLI.",
},
{
value: "theme",
title: "Does it work with my theme?",
content:
"Yes. Every component uses shadcn/ui color tokens, so it follows your colors in light and dark mode.",
},
{
value: "motion",
title: "What about reduced motion?",
content:
"Animations switch off for users who ask for reduced motion, and the panels simply open and close.",
},
]
export default function FoldAccordionDemo() {
return (
<div className="w-full max-w-md">
<FoldAccordion items={items} defaultValue={["what"]} />
</div>
)
}Customize
Try the options below, then copy the code.
<FoldAccordion
items={items}
/>Props
| Prop | Type | Default |
|---|---|---|
variantLook of the accordion. | "bordered" | "separated" | "plain" | "bordered" |
springinessHow the sheet settles as it unfolds. | "subtle" | "paper" | "bouncy" | "paper" |
foldAngleHow far, in degrees, a closed panel is folded back. | number | 92 |
showCreaseShow the soft shadow along the fold as a panel opens. | boolean | true |
iconThe open/close indicator: a chevron that flips, or a plus that turns into a minus. | "chevron" | "plus" | "none" | "chevron" |
iconPositionWhich side of the header the icon sits on. | "left" | "right" | "right" |
itemsThe sections to show. | { value: string; title: React.ReactNode; content: React.ReactNode }[] | — |
multipleAllow more than one panel open at a time. | boolean | false |
valueOpen panels, when you control the state yourself. | string[] | — |
defaultValuePanels open at first, when the component manages state. | string[] | [] |
onValueChangeCalled when a panel opens or closes. | (value: string[]) => void | — |
...propsAll native div props. | React.ComponentProps<"div"> | — |
Accessibility
- Each header is a real button inside a heading, with aria-expanded and aria-controls.
- Panels are labelled regions linked to their header.
- Up and Down arrows move between headers; Home and End jump to the first and last.
- With reduced motion on, panels open and close instantly without the fold.