mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
refactor(web/progress): progress bar mantine rewrite
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Text, Flex, Box } from '@chakra-ui/react';
|
import { Progress, Box, Text, createStyles } from '@mantine/core';
|
||||||
import { useNuiEvent } from '../../hooks/useNuiEvent';
|
import { useNuiEvent } from '../../hooks/useNuiEvent';
|
||||||
import { fetchNui } from '../../utils/fetchNui';
|
import { fetchNui } from '../../utils/fetchNui';
|
||||||
|
|
||||||
@@ -8,7 +8,38 @@ export interface ProgressbarProps {
|
|||||||
duration: number;
|
duration: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const useStyles = createStyles((theme) => ({
|
||||||
|
container: {
|
||||||
|
width: 350,
|
||||||
|
height: 45,
|
||||||
|
position: 'absolute',
|
||||||
|
bottom: '15%',
|
||||||
|
left: '50%',
|
||||||
|
transform: 'translate(-50%)',
|
||||||
|
borderRadius: theme.radius.xs,
|
||||||
|
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
||||||
|
},
|
||||||
|
bar: {
|
||||||
|
height: '100%',
|
||||||
|
borderRadius: theme.radius.xs,
|
||||||
|
backgroundColor: theme.colors[theme.primaryColor][theme.fn.primaryShade()],
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
maxWidth: 350,
|
||||||
|
padding: 8,
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
overflow: 'hidden',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
position: 'absolute',
|
||||||
|
top: '50%',
|
||||||
|
left: '50%',
|
||||||
|
transform: 'translate(-50%, -50%)',
|
||||||
|
fontSize: 20,
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
const Progressbar: React.FC = () => {
|
const Progressbar: React.FC = () => {
|
||||||
|
const { classes } = useStyles();
|
||||||
const [visible, setVisible] = React.useState(false);
|
const [visible, setVisible] = React.useState(false);
|
||||||
const [label, setLabel] = React.useState('');
|
const [label, setLabel] = React.useState('');
|
||||||
const [duration, setDuration] = React.useState(0);
|
const [duration, setDuration] = React.useState(0);
|
||||||
@@ -34,55 +65,20 @@ const Progressbar: React.FC = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex h="30%" w="100%" position="absolute" bottom="0" justifyContent="center" alignItems="center">
|
<>
|
||||||
<Box width={350}>
|
<Box className={classes.container}>
|
||||||
{visible && (
|
<Box
|
||||||
<Box
|
className={classes.bar}
|
||||||
height={45}
|
onAnimationEnd={progressComplete}
|
||||||
bg="rgba(0, 0, 0, 0.6)"
|
sx={{
|
||||||
textAlign="center"
|
width: '0%',
|
||||||
borderRadius="sm"
|
animation: 'progress-bar linear',
|
||||||
boxShadow="lg"
|
animationDuration: `${duration}ms`,
|
||||||
overflow="hidden"
|
}}
|
||||||
>
|
/>
|
||||||
<Box
|
<Text className={classes.label}>{label}</Text>
|
||||||
height={45}
|
|
||||||
onAnimationEnd={progressComplete}
|
|
||||||
sx={
|
|
||||||
!cancelled
|
|
||||||
? {
|
|
||||||
width: '0%',
|
|
||||||
backgroundColor: 'green.400',
|
|
||||||
animation: 'progress-bar linear',
|
|
||||||
animationDuration: `${duration}ms`,
|
|
||||||
}
|
|
||||||
: {
|
|
||||||
// Currently unused
|
|
||||||
width: '100%',
|
|
||||||
animationPlayState: 'paused',
|
|
||||||
backgroundColor: 'rgb(198, 40, 40)',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
<Text
|
|
||||||
maxWidth={350}
|
|
||||||
fontFamily="Inter"
|
|
||||||
textOverflow="ellipsis"
|
|
||||||
overflow="hidden"
|
|
||||||
whiteSpace="nowrap"
|
|
||||||
fontSize={22}
|
|
||||||
fontWeight="light"
|
|
||||||
position="absolute"
|
|
||||||
top="50%"
|
|
||||||
left="50%"
|
|
||||||
transform="translate(-50%, -50%)"
|
|
||||||
>
|
|
||||||
{label}
|
|
||||||
</Text>
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
</Box>
|
</Box>
|
||||||
</Flex>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user