import { Box, linearProgressClasses } from '@mui/material'; import { FC, ReactElement, useMemo } from 'react'; import { GREY } from '../../lib/consts/DEFAULT_THEME'; import BorderLinearProgress from './BorderLinearProgress'; import Underline from './Underline'; const StackBar: FC = (props) => { const { value } = props; const values = useMemo>( () => ('value' in value ? { default: value as StackBarValue } : value), [value], ); const entries = useMemo<[string, StackBarValue][]>( () => Object.entries(values).reverse(), [values], ); const bars = useMemo( () => entries.map( ([id, { colour = GREY, value: val }], index) => { const backgroundColor = typeof colour === 'string' ? colour : Object.entries(colour).findLast( ([mark]) => val >= Number(mark), )?.[1] ?? GREY; let position: 'absolute' | 'relative' = 'relative'; let top: 0 | undefined; let width: string | undefined; if (index) { position = 'absolute'; top = 0; width = '100%'; } return ( ); }, ), [entries], ); return ( {bars} ); }; export default StackBar;