import { ReactElement, ReactNode } from 'react'; import applyModuleDensityStyle from './applyModuleDensity'; import ModuleTitle from './Title'; import Box from '../Box'; import Flex from '../Flex'; import Icon from '../Icon'; import icons from '../icons/index'; import TapArea from '../TapArea'; import Text from '../Text'; export type BadgeType = { text: string; type?: | 'info' | 'error' | 'warning' | 'success' | 'neutral' | 'recommendation' | 'darkWash' | 'lightWash'; }; export default function AccordionExpandableItem({ accessibilityCollapseLabel, accessibilityExpandLabel, badge, children, icon, iconAccessibilityLabel, iconButton, id, isCollapsed, onExpand, summary, title, size = 'lg', type = 'info', }: { accessibilityCollapseLabel: string; accessibilityExpandLabel: string; badge?: BadgeType; children?: ReactNode; icon?: keyof typeof icons; iconAccessibilityLabel?: string; iconButton?: ReactElement; id: string; isCollapsed: boolean; onExpand: (arg1: boolean) => void; summary?: ReadonlyArray; size?: 'sm' | 'md' | 'lg'; title: string; type?: 'error' | 'info'; }) { const { padding, gap, summaryListGap } = applyModuleDensityStyle(size); return ( { if (event?.target instanceof Element && event.target.closest('button') !== null) { return; } onExpand(!isCollapsed); }} > {summary && isCollapsed && ( {summary.map((item, i) => ( // eslint-disable-next-line react/no-array-index-key {item} ))} )} {/* Adding a max height because the line height is 24, and we don't want the icon container to expand */} {Boolean(children) && ( )} {/* Flex.Item necessary to prevent gap from being applied to each child */} {!isCollapsed && {children}} ); }