2022-03-27 18:17:26 +02:00
|
|
|
import {
|
|
|
|
|
Portal,
|
|
|
|
|
Popover,
|
|
|
|
|
PopoverTrigger,
|
|
|
|
|
PopoverBody,
|
|
|
|
|
PopoverContent,
|
|
|
|
|
Box,
|
|
|
|
|
Text,
|
|
|
|
|
Flex,
|
|
|
|
|
Spacer,
|
2022-06-11 11:49:25 +02:00
|
|
|
Image,
|
2022-07-07 14:53:36 +02:00
|
|
|
HStack,
|
2022-08-27 15:58:36 +02:00
|
|
|
} from '@chakra-ui/react';
|
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
|
|
|
import { Option, ContextMenuProps } from '../../../interfaces/context';
|
|
|
|
|
import { fetchNui } from '../../../utils/fetchNui';
|
2022-03-28 16:49:07 +02:00
|
|
|
|
|
|
|
|
const openMenu = (id: string | undefined) => {
|
2022-08-27 15:58:36 +02:00
|
|
|
fetchNui<ContextMenuProps>('openContext', id);
|
2022-03-28 16:49:07 +02:00
|
|
|
};
|
|
|
|
|
|
2022-05-28 19:15:35 +02:00
|
|
|
const clickContext = (id: string) => {
|
2022-08-27 15:58:36 +02:00
|
|
|
fetchNui('clickContext', id);
|
2022-03-28 16:49:07 +02:00
|
|
|
};
|
2022-03-27 18:17:26 +02:00
|
|
|
|
|
|
|
|
const Item: React.FC<{
|
|
|
|
|
option: [string, Option];
|
|
|
|
|
}> = ({ option }) => {
|
|
|
|
|
return (
|
2022-03-27 19:10:44 +02:00
|
|
|
<>
|
2022-08-27 15:58:36 +02:00
|
|
|
<Popover placement="right-start" trigger="hover" eventListeners={{ scroll: true }} isLazy>
|
2022-03-27 19:10:44 +02:00
|
|
|
<PopoverTrigger>
|
|
|
|
|
<Box
|
|
|
|
|
bg="gray.800"
|
|
|
|
|
borderRadius="md"
|
|
|
|
|
h="fit-content"
|
|
|
|
|
w="100%"
|
|
|
|
|
p={2}
|
|
|
|
|
mb={1}
|
|
|
|
|
fontFamily="Poppins"
|
|
|
|
|
fontSize="md"
|
|
|
|
|
transition="300ms"
|
2022-08-27 15:58:36 +02:00
|
|
|
_hover={{ bg: 'gray.700' }}
|
2022-03-27 19:10:44 +02:00
|
|
|
>
|
2022-03-28 16:49:07 +02:00
|
|
|
<Flex
|
|
|
|
|
w="100%"
|
2022-04-15 11:41:06 +02:00
|
|
|
alignItems="center"
|
2022-08-27 15:58:36 +02:00
|
|
|
onClick={() => (option[1].menu ? openMenu(option[1].menu) : clickContext(option[0]))}
|
2022-03-28 16:49:07 +02:00
|
|
|
>
|
2022-07-07 14:53:36 +02:00
|
|
|
{option[1]?.icon && (
|
|
|
|
|
<FontAwesomeIcon
|
|
|
|
|
fixedWidth
|
|
|
|
|
icon={option[1].icon}
|
|
|
|
|
fontSize={20}
|
|
|
|
|
style={{
|
|
|
|
|
marginRight: 10,
|
2022-08-27 15:58:36 +02:00
|
|
|
justifySelf: 'center',
|
2022-07-07 14:53:36 +02:00
|
|
|
color: option[1].iconColor,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2022-03-27 19:10:44 +02:00
|
|
|
<Box>
|
2022-04-15 11:41:06 +02:00
|
|
|
<Box paddingBottom={option[1].description ? 1 : 0}>
|
2022-03-27 19:10:44 +02:00
|
|
|
<Text w="100%" fontWeight="medium">
|
2022-05-08 13:00:19 +02:00
|
|
|
{option[1].title ? option[1].title : option[0]}
|
2022-03-27 19:10:44 +02:00
|
|
|
</Text>
|
2022-03-27 18:17:26 +02:00
|
|
|
</Box>
|
2022-03-27 19:10:44 +02:00
|
|
|
{option[1].description && (
|
|
|
|
|
<Box paddingBottom={1}>
|
|
|
|
|
<Text>{option[1].description}</Text>
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
2022-04-19 15:08:02 +02:00
|
|
|
{(option[1].menu || option[1].arrow) && (
|
2022-03-27 19:10:44 +02:00
|
|
|
<>
|
|
|
|
|
<Spacer />
|
2022-08-27 15:58:36 +02:00
|
|
|
<Box alignSelf="center" justifySelf="center" mr={4} fontSize="xl">
|
2022-03-27 19:10:44 +02:00
|
|
|
<FontAwesomeIcon icon="chevron-right" />
|
|
|
|
|
</Box>
|
|
|
|
|
</>
|
2022-03-27 18:17:26 +02:00
|
|
|
)}
|
2022-03-27 19:10:44 +02:00
|
|
|
</Flex>
|
|
|
|
|
<Portal>
|
2022-07-07 14:36:20 +02:00
|
|
|
{(option[1].metadata || option[1].image) && (
|
2022-03-27 19:10:44 +02:00
|
|
|
<PopoverContent
|
|
|
|
|
fontFamily="Poppins"
|
|
|
|
|
bg="gray.800"
|
|
|
|
|
outline="none"
|
|
|
|
|
border="none"
|
|
|
|
|
w="fit-content"
|
|
|
|
|
maxW="2xs"
|
2022-03-27 18:17:26 +02:00
|
|
|
>
|
2022-03-27 19:10:44 +02:00
|
|
|
<PopoverBody>
|
2022-06-11 11:49:25 +02:00
|
|
|
<>
|
|
|
|
|
{option[1].image && <Image src={option[1].image} />}
|
|
|
|
|
{Array.isArray(option[1].metadata) ? (
|
2022-08-27 15:58:36 +02:00
|
|
|
option[1].metadata.map((metadata: string | { label: string; value: any }, index: number) => (
|
|
|
|
|
<Text key={`context-metadata-${index}`}>
|
|
|
|
|
{typeof metadata === 'string' ? `${metadata}` : `${metadata.label}: ${metadata.value}`}
|
|
|
|
|
</Text>
|
|
|
|
|
))
|
2022-06-11 11:49:25 +02:00
|
|
|
) : (
|
|
|
|
|
<>
|
2022-08-27 15:58:36 +02:00
|
|
|
{typeof option[1].metadata === 'object' &&
|
|
|
|
|
Object.entries(option[1].metadata).map((metadata: { [key: string]: any }, index) => (
|
|
|
|
|
<Text key={`context-metadata-${index}`}>
|
|
|
|
|
{metadata[0]}: {metadata[1]}
|
|
|
|
|
</Text>
|
|
|
|
|
))}
|
2022-06-11 11:49:25 +02:00
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
2022-03-27 19:10:44 +02:00
|
|
|
</PopoverBody>
|
|
|
|
|
</PopoverContent>
|
|
|
|
|
)}
|
|
|
|
|
</Portal>
|
|
|
|
|
</Box>
|
|
|
|
|
</PopoverTrigger>
|
|
|
|
|
</Popover>
|
|
|
|
|
</>
|
2022-03-27 18:17:26 +02:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Item;
|