diff --git a/packages/libs/react-ui/src/components/Accordion/AccordionSections.tsx b/packages/libs/react-ui/src/components/Accordion/AccordionSections.tsx deleted file mode 100644 index 03a977c4ad5..00000000000 --- a/packages/libs/react-ui/src/components/Accordion/AccordionSections.tsx +++ /dev/null @@ -1,97 +0,0 @@ -import { - accordionContentWrapperClass, - accordionSectionClass, - accordionTitleClass, - accordionTitleVariants, -} from './Accordion.css'; -import useLinked from './useLinked'; -import { IAccordionSectionProps } from '.'; - -import classNames from 'classnames'; -import type { FC, FunctionComponentElement } from 'react'; -import React, { useCallback, useEffect } from 'react'; - -export interface IAccordionSectionsProps { - children?: FunctionComponentElement[]; - linked?: boolean; - openSection?: number; -} - -export const AccordionSections: FC = ({ - children, - linked = false, - openSection, -}) => { - const { usingLinked, setUsingLinked, openSections, setOpenSections } = - useLinked(openSection); - - useEffect(() => { - setUsingLinked(linked); - if (linked && openSections.length > 1) { - const lastOpen = openSections.pop() || -1; - setOpenSections([lastOpen]); - } - }, [linked]); - - const handleToggleSection = useCallback( - ( - index: number, - { onOpen, onClose }: Pick, - ): void => { - const isOpen = openSections.includes(index); - if (isOpen) { - setOpenSections(openSections.filter((i) => i !== index)); - onClose?.(); - } else { - setOpenSections(usingLinked ? [index] : [...openSections, index]); - onOpen?.(); - } - }, - [openSections, usingLinked], - ); - - return ( -
- {React.Children.map(children, (section, sectionIndex) => ( -
-
- handleToggleSection(sectionIndex, { - onOpen: section?.props.onOpen, - onClose: section?.props.onClose, - }) - } - className={classNames( - accordionTitleClass, - accordionTitleVariants[ - openSections.includes(sectionIndex) ? 'opened' : 'closed' - ], - )} - > - {React.cloneElement( - section as React.ReactElement< - HTMLElement | IAccordionSectionProps, - | string - | React.JSXElementConstructor< - JSX.Element & IAccordionSectionProps - > - >, - { - isOpen: openSections.includes(sectionIndex), - }, - )} -
- {openSections.includes(sectionIndex) && section && ( -
- {section.props.children} -
- )} -
- ))} -
- ); -};