import { Box, Group, Stack, Text, Progress, Image } from '@mantine/core'; import React, { forwardRef } from 'react'; import CustomCheckbox from './CustomCheckbox'; import type { MenuItem } from '../../../typings'; import { createStyles } from '@mantine/core'; import { isIconUrl } from '../../../utils/isIconUrl'; import { IconProp } from '@fortawesome/fontawesome-svg-core'; import LibIcon from '../../../components/LibIcon'; interface Props { item: MenuItem; index: number; scrollIndex: number; checked: boolean; } const useStyles = createStyles((theme, params: { iconColor?: string }) => ({ buttonContainer: { backgroundColor: theme.colors.dark[6], borderRadius: theme.radius.md, padding: 2, height: 60, scrollMargin: 8, '&:focus': { backgroundColor: theme.colors.dark[4], outline: 'none', }, }, iconImage: { maxWidth: 32, }, buttonWrapper: { paddingLeft: 5, paddingRight: 12, height: '100%', }, iconContainer: { display: 'flex', alignItems: 'center', width: 32, height: 32, }, icon: { fontSize: 24, color: params.iconColor || theme.colors.dark[2], }, label: { color: theme.colors.dark[2], textTransform: 'uppercase', fontSize: 12, verticalAlign: 'middle', }, chevronIcon: { fontSize: 14, color: theme.colors.dark[2], }, scrollIndexValue: { color: theme.colors.dark[2], textTransform: 'uppercase', fontSize: 14, }, progressStack: { width: '100%', marginRight: 5, }, progressLabel: { verticalAlign: 'middle', marginBottom: 3, }, })); const ListItem = forwardRef, Props>(({ item, index, scrollIndex, checked }, ref) => { const { classes } = useStyles({ iconColor: item.iconColor }); return ( { if (ref) // @ts-ignore i cba return (ref.current = [...ref.current, element]); }} > {item.icon && ( {typeof item.icon === 'string' && isIconUrl(item.icon) ? ( Missing image ) : ( )} )} {Array.isArray(item.values) ? ( {item.label} {typeof item.values[scrollIndex] === 'object' ? // @ts-ignore for some reason even checking the type TS still thinks it's a string item.values[scrollIndex].label : item.values[scrollIndex]} {scrollIndex + 1}/{item.values.length} ) : item.checked !== undefined ? ( {item.label} ) : item.progress !== undefined ? ( {item.label} ({ root: { backgroundColor: theme.colors.dark[3] } })} /> ) : ( {item.label} )} ); }); export default React.memo(ListItem);