import { Check as MUICheckIcon, Close as MUICloseIcon, } from '@mui/icons-material'; import { cloneElement, createElement, FC, ReactElement } from 'react'; import { BLUE, PURPLE } from '../lib/consts/DEFAULT_THEME'; import FlexBox from './FlexBox'; import { BodyText, SmallText } from './Text'; type StateTypeMap = Pick; type StateMap = Map< StateTypeMap[TypeName], ReactElement >; type LabelMap = Record<'small' | 'medium', FC>; type StateOptionalProps = { size?: keyof LabelMap; stateMap?: StateMap; }; type StateProps = StateOptionalProps & { label: string; state: StateTypeMap[TypeName]; }; const MAP_TO_TEXT_ELEMENT: LabelMap = { small: SmallText, medium: BodyText, }; const STATE_DEFAULT_PROPS: Required> = { size: 'small', stateMap: new Map([ [false, ], [true, ], ]), }; const State = ({ label, size = STATE_DEFAULT_PROPS.size, state, stateMap = STATE_DEFAULT_PROPS.stateMap, }: StateProps): ReturnType>> => { const stateIcon = stateMap.get(state); return ( {stateIcon && cloneElement(stateIcon, { fontSize: size })} {createElement(MAP_TO_TEXT_ELEMENT[size], {}, label)} ); }; State.defaultProps = STATE_DEFAULT_PROPS; export default State;