import { ReactElement } from 'react'; import applyModuleDensityStyle from './applyModuleDensity'; import Badge from '../Badge'; import Box from '../Box'; import Flex from '../Flex'; import Icon from '../Icon'; import IconCompact from '../IconCompact'; import icons from '../icons/index'; import Text from '../Text'; export type BadgeType = { text: string; type?: | 'info' | 'error' | 'warning' | 'success' | 'neutral' | 'recommendation' | 'darkWash' | 'lightWash'; }; export default function AccordionTitle(props: { badge?: BadgeType; dataTestId?: string; icon?: keyof typeof icons; iconAccessibilityLabel?: string; iconButton?: ReactElement; title: string; type?: 'error' | 'info'; size?: 'sm' | 'md' | 'lg'; }) { const { dataTestId } = props; const dataTestIdIcon = dataTestId && `${dataTestId}-icon`; const dataTestIdText = dataTestId && `${dataTestId}-text`; const dataTestIdBadge = dataTestId && `${dataTestId}-badge`; const { iconAccessibilityLabel = '', title, type = 'info', size = 'lg' } = props; // @ts-expect-error - TS7053 - Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ badge?: BadgeType | undefined; icon?: "replace" | "search" | "link" | "text" | "dash" | "3D" | "3D-move" | "360" | "accessibility" | "ad" | "ad-group" | "add" | "add-circle" | ... 321 more ... | undefined; ... 4 more ...; size?: "sm" | ... 2 more ... | undefined; }'. const decoration = ['icon', 'badge', 'iconButton'].find((prop) => !!props[prop]); const hasError = type === 'error'; const hasIcon = hasError || decoration === 'icon'; const textAndIconColor = hasError ? 'error' : 'default'; const { titleGap } = applyModuleDensityStyle(size); return ( {hasIcon && ( {hasError || props.icon === 'lock' ? ( ) : ( )} )} {title && ( {title} )} {decoration === 'badge' && props.badge && ( )} {decoration === 'iconButton' && {props.iconButton}} ); }