Please use Desktop to view and interact with components
Components300mseaseInOut
Animated Accordion
Accordion with smooth expand/collapse and rotate arrow
accordioncollapseexpandfaqshadcn
Useto navigate between components
Preview
This component requires shadcn/ui
This component uses shadcn/ui components. Make sure you have shadcn/ui set up in your project.
- Install shadcn/ui:
npx shadcn-ui@latest init - Install required components based on the imports in the code (e.g.,
npx shadcn-ui@latest add button) - Ensure your
tailwind.config.tsandglobals.cssare configured as per shadcn/ui documentation
Code
TypeScript + React
'use client'
import { useState } from 'react'
import { motion, AnimatePresence } from 'framer-motion'
import { ChevronDown } from 'lucide-react'
const items = [
{
title: 'What is your return policy?',
content: 'We offer a 30-day money-back guarantee on all our products. If you\'re not satisfied, contact our support team for a full refund.',
},
{
title: 'How long does shipping take?',
content: 'Standard shipping takes 5-7 business days. Express shipping is available for 2-3 day delivery.',
},
{
title: 'Do you ship internationally?',
content: 'Yes, we ship to over 50 countries worldwide. International shipping times vary by location.',
},
]
export function AnimatedAccordion() {
const [openIndex, setOpenIndex] = useState<number | null>(null)
return (
<div className="w-full max-w-2xl space-y-2">
{items.map((item, index) => (
<div
key={index}
className="overflow-hidden rounded-xl border bg-[var(--card-bg)]"
>
<motion.button
onClick={() => setOpenIndex(openIndex === index ? null : index)}
className="flex w-full items-center justify-between p-4 text-left text-sm font-medium"
whileHover={{ backgroundColor: 'rgba(var(--accent-rgb), 0.05)' }}
>
<span>{item.title}</span>
<motion.div
animate={{ rotate: openIndex === index ? 180 : 0 }}
transition={{ duration: 0.3 }}
>
<ChevronDown className="h-5 w-5" />
</motion.div>
</motion.button>
<AnimatePresence initial={false}>
{openIndex === index && (
<motion.div
initial={{ height: 0, opacity: 0 }}
animate={{ height: 'auto', opacity: 1 }}
exit={{ height: 0, opacity: 0 }}
transition={{ duration: 0.3, ease: 'easeInOut' }}
>
<div className="border-t p-4 text-sm text-[var(--foreground)]/70">
{item.content}
</div>
</motion.div>
)}
</AnimatePresence>
</div>
))}
</div>
)
}
How to Use
- 1Install Framer Motion:
npm install framer-motion - 2Set up shadcn/ui: Install shadcn/ui components used in this code. Check the imports in the code above and install the required components (e.g.,
npx shadcn-ui@latest add button card) - 3Copy the code from above
- 4Paste it into your project and customize as needed
- 5Colors are customizable via Tailwind CSS classes. The default theme uses dark mode colors defined in your globals.css file