import { useState } from 'react' import { ChevronDownIcon, ChevronRightIcon } from '@heroicons/react/24/outline' import classNames from '@/utils/classnames' export type IItem = { key: string name: string } type ICollapse = { title: string | undefined items: IItem[] renderItem: (item: IItem) => React.ReactNode onSelect?: (item: IItem) => void wrapperClassName?: string } const Collapse = ({ title, items, renderItem, onSelect, wrapperClassName, }: ICollapse) => { const [open, setOpen] = useState(false) const toggle = () => setOpen(!open) return (
{title} { open ? : }
{ open && (
{ items.map(item => (
onSelect && onSelect(item)}> {renderItem(item)}
)) }
) }
) } export default Collapse