mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 23:46:03 +01:00
refactor(web/textui): textui mantine rewrite
This commit is contained in:
@@ -1,24 +1,49 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useNuiEvent } from '../../hooks/useNuiEvent';
|
import { useNuiEvent } from '../../hooks/useNuiEvent';
|
||||||
import { Box, Flex, ScaleFade } from '@chakra-ui/react';
|
import { Box, createStyles, Group } from '@mantine/core';
|
||||||
import ReactMarkdown from 'react-markdown';
|
import ReactMarkdown from 'react-markdown';
|
||||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||||
import { IconProp } from '@fortawesome/fontawesome-svg-core';
|
import { IconProp } from '@fortawesome/fontawesome-svg-core';
|
||||||
|
|
||||||
|
type Position = 'right-center' | 'left-center' | 'top-center';
|
||||||
|
|
||||||
export interface TextUiProps {
|
export interface TextUiProps {
|
||||||
text: string;
|
text: string;
|
||||||
position?: 'right-center' | 'left-center' | 'top-center';
|
position?: Position;
|
||||||
icon?: IconProp;
|
icon?: IconProp;
|
||||||
iconColor?: string;
|
iconColor?: string;
|
||||||
style?: React.CSSProperties;
|
style?: React.CSSProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const useStyles = createStyles((theme, params: { position?: Position }) => ({
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
const TextUI: React.FC = () => {
|
const TextUI: React.FC = () => {
|
||||||
const [data, setData] = React.useState<TextUiProps>({
|
const [data, setData] = React.useState<TextUiProps>({
|
||||||
text: '',
|
text: '',
|
||||||
position: 'right-center',
|
position: 'right-center',
|
||||||
});
|
});
|
||||||
const [visible, setVisible] = React.useState(false);
|
const [visible, setVisible] = React.useState(false);
|
||||||
|
const { classes } = useStyles({ position: data.position });
|
||||||
|
|
||||||
useNuiEvent<TextUiProps>('textUi', (data) => {
|
useNuiEvent<TextUiProps>('textUi', (data) => {
|
||||||
if (!data.position) data.position = 'right-center'; // Default right position
|
if (!data.position) data.position = 'right-center'; // Default right position
|
||||||
@@ -29,42 +54,18 @@ const TextUI: React.FC = () => {
|
|||||||
useNuiEvent('textUiHide', () => setVisible(false));
|
useNuiEvent('textUiHide', () => setVisible(false));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex
|
<>
|
||||||
w="100%"
|
{visible && (
|
||||||
h="100%"
|
<Box className={classes.wrapper}>
|
||||||
p={3}
|
<Box style={data.style} className={classes.container}>
|
||||||
position="absolute"
|
<Group spacing={12}>
|
||||||
alignItems={data.position === 'top-center' ? 'baseline' : 'center'}
|
{data.icon && <FontAwesomeIcon icon={data.icon} fixedWidth size="lg" style={{ color: data.iconColor }} />}
|
||||||
justifyContent={
|
<ReactMarkdown>{data.text}</ReactMarkdown>
|
||||||
data.position === 'right-center' ? 'flex-end' : data.position === 'left-center' ? 'flex-start' : 'center'
|
</Group>
|
||||||
}
|
</Box>
|
||||||
>
|
|
||||||
<ScaleFade in={visible} unmountOnExit>
|
|
||||||
<Box
|
|
||||||
bg="gray.700"
|
|
||||||
boxShadow="md"
|
|
||||||
p={3}
|
|
||||||
fontFamily="Poppins"
|
|
||||||
fontSize="0.95em"
|
|
||||||
style={data.style}
|
|
||||||
borderRadius="sm"
|
|
||||||
maxW="xs"
|
|
||||||
>
|
|
||||||
<Flex justifyContent="center" alignItems="center">
|
|
||||||
{data.icon && (
|
|
||||||
<FontAwesomeIcon
|
|
||||||
fixedWidth
|
|
||||||
icon={data.icon}
|
|
||||||
color={data.iconColor}
|
|
||||||
fontSize="1.3em"
|
|
||||||
style={{ paddingRight: 8 }}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<ReactMarkdown>{data.text}</ReactMarkdown>
|
|
||||||
</Flex>
|
|
||||||
</Box>
|
</Box>
|
||||||
</ScaleFade>
|
)}
|
||||||
</Flex>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,11 @@ ReactDOM.createRoot(root!).render(
|
|||||||
<MantineProvider
|
<MantineProvider
|
||||||
withNormalizeCSS
|
withNormalizeCSS
|
||||||
withGlobalStyles
|
withGlobalStyles
|
||||||
theme={{ colorScheme: 'dark', fontFamily: 'Roboto', shadows: { sm: '1px 1px 3px rgba(0, 0, 0, 0.5)' } }}
|
theme={{
|
||||||
|
colorScheme: 'dark',
|
||||||
|
fontFamily: 'Roboto',
|
||||||
|
shadows: { sm: '1px 1px 3px rgba(0, 0, 0, 0.5)' },
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<ChakraProvider theme={theme}>
|
<ChakraProvider theme={theme}>
|
||||||
<App />
|
<App />
|
||||||
|
|||||||
Reference in New Issue
Block a user