Files
ox_lib/web/src/features/menu/list/ListItem.tsx

79 lines
2.9 KiB
TypeScript
Raw Normal View History

import { Box, Flex, Stack, Text, Progress } from '@chakra-ui/react';
2022-08-27 15:58:36 +02:00
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import React, { forwardRef } from 'react';
import CustomCheckbox from './CustomCheckbox';
2022-08-27 15:58:36 +02:00
import type { MenuItem } from './index';
interface Props {
2022-07-29 17:58:13 +02:00
item: MenuItem;
index: number;
2022-07-28 16:40:48 +02:00
scrollIndex: number;
checked: boolean;
}
const ListItem = forwardRef<Array<HTMLDivElement | null>, Props>(({ item, index, scrollIndex, checked }, ref) => {
return (
<Box
bg="#25262B"
borderRadius="md"
tabIndex={index}
scrollMargin={2}
p={2}
height="60px"
key={`item-${index}`}
2022-08-27 15:58:36 +02:00
_focus={{ bg: '#373A40', outline: 'none' }}
ref={(element) => {
if (ref)
// @ts-ignore i cba
return (ref.current = [...ref.current, element]);
}}
>
<Flex alignItems="center" height="100%" gap="15px">
2022-07-29 17:58:13 +02:00
{item.icon && (
<Box display="flex" alignItems="center">
<FontAwesomeIcon icon={item.icon} fontSize={24} color={item.iconColor || '#909296'} fixedWidth />
</Box>
2022-07-29 17:58:13 +02:00
)}
{Array.isArray(item.values) ? (
<Flex alignItems="center" justifyContent="space-between" w="100%">
<Stack spacing={1} justifyContent="space-between">
2022-07-29 17:58:13 +02:00
<Text color="#909296" textTransform="uppercase" fontSize={12} verticalAlign="middle">
{item.label}
</Text>
<Text>
{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]}
</Text>
2022-07-29 17:58:13 +02:00
</Stack>
<Stack direction="row" spacing="sm" pr={3} justifyContent="center" alignItems="center">
2022-07-29 17:58:13 +02:00
<FontAwesomeIcon icon="chevron-left" fontSize={16} color="#909296" />
<Text color="#909296" textTransform="uppercase" fontSize={14}>
{scrollIndex + 1}/{item.values.length}
</Text>
2022-07-29 17:58:13 +02:00
<FontAwesomeIcon icon="chevron-right" fontSize={16} color="#909296" />
</Stack>
</Flex>
) : item.checked !== undefined ? (
<Flex alignItems="center" justifyContent="space-between" w="100%">
<Text>{item.label}</Text>
<CustomCheckbox checked={checked}></CustomCheckbox>
</Flex>
) : item.progress !== undefined ? (
<Flex flexDirection="column" w="100%" marginRight="5px">
<Text verticalAlign="middle" marginBottom="3px">
{item.label}
</Text>
<Progress value={item.progress} size="sm" colorScheme={item.colorScheme || 'gray'} borderRadius="md" />
</Flex>
2022-07-29 17:58:13 +02:00
) : (
<Text>{item.label}</Text>
2022-07-29 17:58:13 +02:00
)}
</Flex>
</Box>
);
});
export default React.memo(ListItem);