2022-03-18 16:59:18 +01:00
|
|
|
import React from "react";
|
2022-04-01 21:41:53 +02:00
|
|
|
import { useNuiEvent } from "../../hooks/useNuiEvent";
|
2022-04-01 21:23:45 +02:00
|
|
|
import { Box, Flex, ScaleFade } from "@chakra-ui/react";
|
2022-04-01 21:41:53 +02:00
|
|
|
import { debugData } from "../../utils/debugData";
|
2022-03-26 11:02:38 +01:00
|
|
|
import ReactMarkdown from "react-markdown";
|
2022-04-01 22:04:14 +02:00
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
|
|
|
import { IconProp } from "@fortawesome/fontawesome-svg-core";
|
2022-03-18 16:59:18 +01:00
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
|
text: string;
|
|
|
|
|
position?: "right-center" | "left-center" | "top-center";
|
2022-04-01 22:04:14 +02:00
|
|
|
icon?: IconProp;
|
|
|
|
|
iconColor?: string;
|
2022-03-18 16:59:18 +01:00
|
|
|
style?: React.CSSProperties;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
debugData([
|
|
|
|
|
{
|
|
|
|
|
action: "textUi",
|
|
|
|
|
data: {
|
2022-05-06 15:33:11 +10:00
|
|
|
text: "[E] - Access locker inventory \n [G] - Do something else",
|
2022-03-18 16:59:18 +01:00
|
|
|
position: "right-center",
|
2022-04-01 22:04:14 +02:00
|
|
|
icon: "door-open",
|
2022-03-18 16:59:18 +01:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const TextUI: React.FC = () => {
|
|
|
|
|
const [data, setData] = React.useState<Props>({
|
|
|
|
|
text: "",
|
|
|
|
|
position: "right-center",
|
|
|
|
|
});
|
|
|
|
|
const [visible, setVisible] = React.useState(false);
|
|
|
|
|
|
|
|
|
|
useNuiEvent<Props>("textUi", (data) => {
|
2022-04-11 15:59:18 +02:00
|
|
|
if (!data.position) data.position = "right-center"; // Default right position
|
2022-03-18 16:59:18 +01:00
|
|
|
setData(data);
|
|
|
|
|
setVisible(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
useNuiEvent("textUiHide", () => setVisible(false));
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Flex
|
|
|
|
|
w="100%"
|
|
|
|
|
h="100%"
|
|
|
|
|
p={3}
|
2022-03-25 23:56:50 +01:00
|
|
|
position="absolute"
|
2022-03-18 16:59:18 +01:00
|
|
|
alignItems={data.position === "top-center" ? "baseline" : "center"}
|
|
|
|
|
justifyContent={
|
|
|
|
|
data.position === "right-center"
|
|
|
|
|
? "flex-end"
|
|
|
|
|
: data.position === "left-center"
|
|
|
|
|
? "flex-start"
|
|
|
|
|
: "center"
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<ScaleFade in={visible} unmountOnExit>
|
2022-03-20 19:58:52 +01:00
|
|
|
<Box
|
|
|
|
|
bg="gray.700"
|
2022-05-06 15:33:11 +10:00
|
|
|
boxShadow="md"
|
2022-03-20 19:58:52 +01:00
|
|
|
p={3}
|
2022-04-01 22:04:14 +02:00
|
|
|
fontFamily="Poppins"
|
2022-05-06 15:33:11 +10:00
|
|
|
fontSize="0.95em"
|
2022-03-20 19:58:52 +01:00
|
|
|
style={data.style}
|
2022-05-06 15:33:11 +10:00
|
|
|
borderRadius="sm"
|
2022-03-26 11:02:38 +01:00
|
|
|
maxW="xs"
|
2022-03-20 19:58:52 +01:00
|
|
|
>
|
2022-04-01 22:04:14 +02:00
|
|
|
<Flex justifyContent="center" alignItems="center">
|
|
|
|
|
{data.icon && (
|
|
|
|
|
<FontAwesomeIcon
|
2022-04-16 12:08:55 +02:00
|
|
|
fixedWidth
|
2022-04-01 22:04:14 +02:00
|
|
|
icon={data.icon}
|
|
|
|
|
color={data.iconColor}
|
2022-05-06 15:33:11 +10:00
|
|
|
fontSize="1.3em"
|
2022-04-16 12:08:55 +02:00
|
|
|
style={{ paddingRight: 8 }}
|
2022-04-01 22:04:14 +02:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
<ReactMarkdown>{data.text}</ReactMarkdown>
|
|
|
|
|
</Flex>
|
2022-03-18 16:59:18 +01:00
|
|
|
</Box>
|
|
|
|
|
</ScaleFade>
|
|
|
|
|
</Flex>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default TextUI;
|