"use client"; import React, { useEffect, useState } from "react"; import { AccordionItem, AccordionProps, ThemeKey } from "./types"; import { Accordion as AccordionComponent } from "@shared/components/accordion"; import { Divider } from "@shared/components/divider"; import { Text } from "@shared/components/text"; export const Accordion: React.FC = ({ items, title, anchorId, background = "white", enableHeading = false, maxWidth = true, initialExpandedItems: initialExpandedItemsProp = [], hashAutoExpand = false, descriptionMaxWidth = "max-w-[980px]", itemContainerClassName, }) => { const [expandedItems, setExpandedItems] = useState( initialExpandedItemsProp ); useEffect(() => { if (hashAutoExpand && typeof window !== "undefined") { const hash = window.location.hash; if (hash) { const expandItemId = hash.substring(hash.indexOf("#") + 1); setExpandedItems(prev => { if (prev.includes(expandItemId)) return prev; return [...prev, expandItemId]; }); } } }, [hashAutoExpand]); /* istanbul ignore next -- passed to AccordionComponent which does not forward onClick */ const handleToggle = (itemAnchorId: string) => { setExpandedItems(prev => prev.includes(itemAnchorId) ? prev.filter(id => id !== itemAnchorId) : [...prev, itemAnchorId] ); }; const bgColorClasses: Record = { blue: "bg-[#07B2E2]", green: "bg-[#26B170]", yellow: "bg-[#F5FF1E]", purple: "bg-[#931D69]", white: "bg-white", navy: "bg-[#00002D]", cream500: "bg-[#FFFEEF]", }; return (
{title}
{items?.map((item: AccordionItem, index: number) => { const itemKey = item.anchorId || `item-${index}`; const isOpen = item.anchorId ? expandedItems.includes(item.anchorId) : undefined; return (
handleToggle(item.anchorId!), })} >
{item.description}
{index < items.length - 1 && ( )}
); })}
); }; export default Accordion;