import Accordion from 'react-bootstrap/Accordion' import AccordionContext from 'react-bootstrap/AccordionContext' import { useAccordionButton } from 'react-bootstrap/AccordionButton' import ArrowRight from '@/svgs/arrow-right-s-fill.svg' import ArrowDown from '@/svgs/arrow-down-s-fill.svg' import { useContext, useEffect, useState } from 'react' const KEY_ID = '0' function ContextAwareToggle ({ children, headerColor = 'var(--theme-grey)', eventKey, show }) { const { activeEventKey } = useContext(AccordionContext) const decoratedOnClick = useAccordionButton(eventKey) useEffect(() => { // if we want to show the accordian and it's not open, open it if (show && activeEventKey !== eventKey) { decoratedOnClick() } }, [show]) const isCurrentEventKey = activeEventKey === eventKey return (
{isCurrentEventKey ? : } {children}
) } export default function AccordianItem ({ header, body, headerColor = 'var(--theme-grey)', show }) { const [activeKey, setActiveKey] = useState() useEffect(() => { setActiveKey(show ? KEY_ID : null) }, [show]) const handleOnSelect = () => { setActiveKey(activeKey === KEY_ID ? null : KEY_ID) } return (
{header}
{body}
) } export function AccordianCard ({ header, children, show }) { return ( {header} {children} ) }