2022-08-27 15:58:36 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import { useNuiEvent } from '../../hooks/useNuiEvent';
|
2022-12-30 14:50:15 +01:00
|
|
|
import { Box, createStyles, Group } from '@mantine/core';
|
2022-08-27 15:58:36 +02:00
|
|
|
import ReactMarkdown from 'react-markdown';
|
|
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
2022-12-31 15:03:16 +01:00
|
|
|
import ScaleFade from '../../transitions/ScaleFade';
|
2023-01-29 13:29:06 +01:00
|
|
|
import remarkGfm from 'remark-gfm';
|
2023-02-15 13:00:09 +01:00
|
|
|
import type { TextUiProps, TextUiPosition } from '../../typings';
|
2022-03-18 16:59:18 +01:00
|
|
|
|
2023-02-15 13:00:09 +01:00
|
|
|
const useStyles = createStyles((theme, params: { position?: TextUiPosition }) => ({
|
2022-12-30 14:50:15 +01:00
|
|
|
wrapper: {
|
|
|
|
|
height: '100%',
|
|
|
|
|
width: '100%',
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
display: 'flex',
|
|
|
|
|
alignItems: params.position === 'top-center' ? 'baseline' : 'center',
|
|
|
|
|
justifyContent:
|
|
|
|
|
params.position === 'right-center' ? 'flex-end' : params.position === 'left-center' ? 'flex-start' : 'center',
|
|
|
|
|
},
|
|
|
|
|
container: {
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
padding: 12,
|
|
|
|
|
margin: 8,
|
|
|
|
|
backgroundColor: theme.colors.dark[6],
|
|
|
|
|
color: theme.colors.dark[0],
|
|
|
|
|
fontFamily: 'Roboto',
|
|
|
|
|
borderRadius: theme.radius.sm,
|
|
|
|
|
boxShadow: theme.shadows.sm,
|
|
|
|
|
},
|
|
|
|
|
}));
|
|
|
|
|
|
2022-03-18 16:59:18 +01:00
|
|
|
const TextUI: React.FC = () => {
|
2022-08-27 15:40:41 +02:00
|
|
|
const [data, setData] = React.useState<TextUiProps>({
|
2022-08-27 15:58:36 +02:00
|
|
|
text: '',
|
|
|
|
|
position: 'right-center',
|
2022-03-18 16:59:18 +01:00
|
|
|
});
|
|
|
|
|
const [visible, setVisible] = React.useState(false);
|
2022-12-30 14:50:15 +01:00
|
|
|
const { classes } = useStyles({ position: data.position });
|
2022-03-18 16:59:18 +01:00
|
|
|
|
2022-08-27 15:58:36 +02:00
|
|
|
useNuiEvent<TextUiProps>('textUi', (data) => {
|
|
|
|
|
if (!data.position) data.position = 'right-center'; // Default right position
|
2022-03-18 16:59:18 +01:00
|
|
|
setData(data);
|
|
|
|
|
setVisible(true);
|
|
|
|
|
});
|
|
|
|
|
|
2022-08-27 15:58:36 +02:00
|
|
|
useNuiEvent('textUiHide', () => setVisible(false));
|
2022-03-18 16:59:18 +01:00
|
|
|
|
|
|
|
|
return (
|
2022-12-30 14:50:15 +01:00
|
|
|
<>
|
2022-12-31 15:03:16 +01:00
|
|
|
<Box className={classes.wrapper}>
|
|
|
|
|
<ScaleFade visible={visible}>
|
2022-12-30 14:50:15 +01:00
|
|
|
<Box style={data.style} className={classes.container}>
|
|
|
|
|
<Group spacing={12}>
|
|
|
|
|
{data.icon && <FontAwesomeIcon icon={data.icon} fixedWidth size="lg" style={{ color: data.iconColor }} />}
|
2023-01-29 13:29:06 +01:00
|
|
|
<ReactMarkdown remarkPlugins={[remarkGfm]}>{data.text}</ReactMarkdown>
|
2022-12-30 14:50:15 +01:00
|
|
|
</Group>
|
|
|
|
|
</Box>
|
2022-12-31 15:03:16 +01:00
|
|
|
</ScaleFade>
|
|
|
|
|
</Box>
|
2022-12-30 14:50:15 +01:00
|
|
|
</>
|
2022-03-18 16:59:18 +01:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default TextUI;
|