2import React, { ReactNode } from 'react';
3import { AnimatePresence, motion } from 'framer-motion';
4import { ChevronDown } from 'lucide-react';
5import { cn } from '@/lib/utils';
7const AccordionContext = React.createContext({});
8const useAccordion = () => React.useContext(AccordionContext);
10export function AccordionContainer({
18 <div className={cn('grid grid-cols-2 gap-1', className)}>{children}</div>
21export function AccordionWrapper({ children }) {
22 return <div>{children}</div>;
25export function Accordion({
32 defaultValue?: string | undefined | string[];
34 const [activeIndex, setActiveIndex] = React.useState(
35 multiple ? (defaultValue ? [defaultValue] : []) : [defaultValue]
38 function onChangeIndex(value) {
39 setActiveIndex((currentActiveIndex) => {
41 return value === currentActiveIndex ? null : value;
44 if (currentActiveIndex.includes(value)) {
45 return currentActiveIndex.filter((i) => i !== value);
48 return [...currentActiveIndex, value];
52 return React.Children.map(children, (child) => {
53 const value = child.props.value;
54 const isActive = multiple
55 ? Array.isArray(activeIndex) && activeIndex.includes(value)
56 : Array.isArray(activeIndex)
57 ? activeIndex[0].includes(value)
61 <AccordionContext.Provider value={{ isActive, value, onChangeIndex }}>
63 </AccordionContext.Provider>
68export function AccordionItem({ children, value }) {
69 const { isActive } = useAccordion();
73 className={`rounded-lg overflow-hidden mb-2 ${
75 ? 'active border-2 dark:border-[#656fe2] border-[#F2F2F2] dark:bg-[#E0ECFB] bg-[#F2F2F2]'
76 : 'bg-transparent border-2 dark:hover:border-[#656fe2]'
86export function AccordionHeader({
93 const { isActive, value, onChangeIndex } = useAccordion();
97 className={`p-4 cursor-pointer transition-all font-semibold dark:text-white text-black dark:hover:bg-[#1e2a78] hover:bg-[#F2F2F2] dark:hover:text-white hover:text-black flex justify-between items-center ${
99 ? 'active dark:bg-[#1e2a78] bg-[#F2F2F2] '
100 : 'dark:bg-[#11112b] bg-white'
103 onClick={() => onChangeIndex(value)}
109 isActive ? 'rotate-45 ' : 'rotate-0 '
118 isActive ? 'rotate-180 ' : 'rotate-0 '
127export function AccordionPanel({ children }) {
128 const { isActive } = useAccordion();
131 <AnimatePresence initial={true}>
134 initial={{ height: 0, overflow: 'hidden' }}
135 animate={{ height: 'auto', overflow: 'hidden' }}
137 transition={{ type: 'spring', duration: 0.3, bounce: 0 }}
138 className={`dark:bg-white bg-[#F2F2F2]
142 initial={{ clipPath: 'polygon(0 0, 100% 0, 100% 0, 0 0)' }}
143 animate={{ clipPath: 'polygon(0 0, 100% 0, 100% 100%, 0% 100%)' }}
145 clipPath: 'polygon(0 0, 100% 0, 100% 0, 0 0)',
152 className={`p-3 bg-transparent text-black `}