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-03-27 18:17:26 +02:00
|
|
|
} from "@chakra-ui/react";
|
|
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
2022-05-03 15:08:28 +02:00
|
|
|
import { Option, ContextMenuProps } from "../../interfaces/context";
|
2022-04-01 21:41:53 +02:00
|
|
|
import { fetchNui } from "../../utils/fetchNui";
|
2022-03-28 16:49:07 +02:00
|
|
|
|
|
|
|
|
const openMenu = (id: string | undefined) => {
|
|
|
|
|
fetchNui<ContextMenuProps>("openContext", id);
|
|
|
|
|
};
|
|
|
|
|
|
2022-05-28 19:15:35 +02:00
|
|
|
const clickContext = (id: string) => {
|
|
|
|
|
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
|
|
|
<>
|
|
|
|
|
<Popover
|
|
|
|
|
placement="right-start"
|
|
|
|
|
trigger="hover"
|
|
|
|
|
eventListeners={{ scroll: true }}
|
|
|
|
|
isLazy
|
|
|
|
|
>
|
|
|
|
|
<PopoverTrigger>
|
|
|
|
|
<Box
|
|
|
|
|
bg="gray.800"
|
|
|
|
|
borderRadius="md"
|
|
|
|
|
h="fit-content"
|
|
|
|
|
w="100%"
|
|
|
|
|
p={2}
|
|
|
|
|
mb={1}
|
|
|
|
|
fontFamily="Poppins"
|
|
|
|
|
fontSize="md"
|
|
|
|
|
transition="300ms"
|
|
|
|
|
_hover={{ bg: "gray.700" }}
|
|
|
|
|
>
|
2022-03-28 16:49:07 +02:00
|
|
|
<Flex
|
|
|
|
|
w="100%"
|
2022-04-15 11:41:06 +02:00
|
|
|
alignItems="center"
|
2022-03-28 16:49:07 +02:00
|
|
|
onClick={() =>
|
2022-04-01 21:22:14 +02:00
|
|
|
option[1].menu
|
|
|
|
|
? openMenu(option[1].menu)
|
2022-05-28 19:15:35 +02:00
|
|
|
: clickContext(option[0])
|
2022-03-28 16:49:07 +02:00
|
|
|
}
|
|
|
|
|
>
|
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 />
|
|
|
|
|
<Box
|
|
|
|
|
alignSelf="center"
|
|
|
|
|
justifySelf="center"
|
|
|
|
|
mr={4}
|
|
|
|
|
fontSize="xl"
|
|
|
|
|
>
|
|
|
|
|
<FontAwesomeIcon icon="chevron-right" />
|
|
|
|
|
</Box>
|
|
|
|
|
</>
|
2022-03-27 18:17:26 +02:00
|
|
|
)}
|
2022-03-27 19:10:44 +02:00
|
|
|
</Flex>
|
|
|
|
|
<Portal>
|
|
|
|
|
{option[1].metadata && (
|
|
|
|
|
<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) ? (
|
|
|
|
|
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-03-27 18:17:26 +02:00
|
|
|
)
|
2022-06-11 11:49:25 +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-03-27 19:10:44 +02:00
|
|
|
</PopoverBody>
|
|
|
|
|
</PopoverContent>
|
|
|
|
|
)}
|
|
|
|
|
</Portal>
|
|
|
|
|
</Box>
|
|
|
|
|
</PopoverTrigger>
|
|
|
|
|
</Popover>
|
|
|
|
|
</>
|
2022-03-27 18:17:26 +02:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Item;
|