UNPKG

@olleemilsson/flowbite-react

Version:

<div align="center"> <h1>:construction: flowbite-react (unreleased) :construction:</h1> <p> <a href="https://flowbite-react.com"> <img alt="Flowbite - Tailwind CSS components" width="350" src=".github/assets/flowbite-react-github.png"> <

24 lines (23 loc) 1.38 kB
import { jsx as _jsx } from "react/jsx-runtime"; import classNames from 'classnames'; import { Children, cloneElement, useMemo, useState } from 'react'; import { HiChevronDown } from 'react-icons/hi'; import { useTheme } from '../Flowbite/ThemeContext'; import { AccordionContent } from './AccordionContent'; import { AccordionPanel } from './AccordionPanel'; import { AccordionTitle } from './AccordionTitle'; const AccordionComponent = ({ alwaysOpen = false, arrowIcon = HiChevronDown, children, flush = false, className, ...props }) => { const [isOpen, setOpen] = useState(0); const panels = useMemo(() => Children.map(children, (child, i) => cloneElement(child, { alwaysOpen, arrowIcon, flush, isOpen: isOpen === i, setOpen: () => setOpen(i) })), [alwaysOpen, arrowIcon, children, flush, isOpen]); const theme = useTheme().theme.accordion; return (_jsx("div", { className: classNames(theme.base, theme.flush[flush ? 'on' : 'off'], className), "data-testid": "flowbite-accordion", ...props, children: panels })); }; AccordionComponent.displayName = 'Accordion'; AccordionPanel.displayName = 'Accordion.Panel'; AccordionTitle.displayName = 'Accordion.Title'; AccordionContent.displayName = 'Accordion.Content'; export const Accordion = Object.assign(AccordionComponent, { Panel: AccordionPanel, Title: AccordionTitle, Content: AccordionContent, });