refactor(web/progress): use scale fade transition for progress

This commit is contained in:
Luke
2022-12-31 15:52:39 +01:00
parent f9ff2fe6d4
commit 97dc0cabdd
2 changed files with 46 additions and 30 deletions

View File

@@ -2,6 +2,7 @@ import React from 'react';
import { RingProgress, Text, useMantineTheme, keyframes, Stack, createStyles } from '@mantine/core'; import { RingProgress, Text, useMantineTheme, keyframes, Stack, createStyles } from '@mantine/core';
import { useNuiEvent } from '../../hooks/useNuiEvent'; import { useNuiEvent } from '../../hooks/useNuiEvent';
import { fetchNui } from '../../utils/fetchNui'; import { fetchNui } from '../../utils/fetchNui';
import ScaleFade from '../../transitions/ScaleFade';
export interface CircleProgressbarProps { export interface CircleProgressbarProps {
label?: string; label?: string;
@@ -18,11 +19,11 @@ const progressCircle = keyframes({
const useStyles = createStyles((theme, params: { position: 'middle' | 'bottom'; duration: number }) => ({ const useStyles = createStyles((theme, params: { position: 'middle' | 'bottom'; duration: number }) => ({
container: { container: {
width: '100%',
height: params.position === 'middle' ? '100%' : '20%',
bottom: 0,
position: 'absolute', position: 'absolute',
top: params.position === 'middle' ? '50%' : undefined, display: 'flex',
bottom: params.position === 'bottom' ? '20%' : undefined,
left: '50%',
transform: 'translate(-50%, -50%)',
justifyContent: 'center', justifyContent: 'center',
alignItems: 'center', alignItems: 'center',
}, },
@@ -85,8 +86,8 @@ const CircleProgressbar: React.FC = () => {
return ( return (
<> <>
{visible && ( <Stack spacing={0} className={classes.container}>
<Stack spacing={0} className={classes.container} bottom="0"> <ScaleFade visible={visible}>
<RingProgress <RingProgress
size={90} size={90}
thickness={7} thickness={7}
@@ -96,8 +97,8 @@ const CircleProgressbar: React.FC = () => {
label={<Text className={classes.value}>{value}%</Text>} label={<Text className={classes.value}>{value}%</Text>}
/> />
{label && <Text className={classes.label}>{label}</Text>} {label && <Text className={classes.label}>{label}</Text>}
</Stack> </ScaleFade>
)} </Stack>
</> </>
); );
}; };

View File

@@ -2,6 +2,7 @@ import React from 'react';
import { Progress, Box, Text, createStyles } from '@mantine/core'; 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';
import ScaleFade from '../../transitions/ScaleFade';
export interface ProgressbarProps { export interface ProgressbarProps {
label: string; label: string;
@@ -12,29 +13,39 @@ const useStyles = createStyles((theme) => ({
container: { container: {
width: 350, width: 350,
height: 45, height: 45,
position: 'absolute',
bottom: '15%',
left: '50%',
transform: 'translate(-50%)',
borderRadius: theme.radius.xs, borderRadius: theme.radius.xs,
backgroundColor: 'rgba(0, 0, 0, 0.5)', backgroundColor: 'rgba(0, 0, 0, 0.5)',
}, },
wrapper: {
width: '100%',
height: '20%',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
bottom: 0,
position: 'absolute',
},
bar: { bar: {
height: '100%', height: '100%',
borderRadius: theme.radius.xs, borderRadius: theme.radius.xs,
backgroundColor: theme.colors[theme.primaryColor][theme.fn.primaryShade()], backgroundColor: theme.colors[theme.primaryColor][theme.fn.primaryShade()],
}, },
labelWrapper: {
position: 'absolute',
display: 'flex',
width: 350,
height: 45,
alignItems: 'center',
justifyContent: 'center',
},
label: { label: {
maxWidth: 350, maxWidth: 350,
padding: 8, padding: 8,
textOverflow: 'ellipsis', textOverflow: 'ellipsis',
overflow: 'hidden', overflow: 'hidden',
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
fontSize: 20, fontSize: 20,
textShadow: theme.shadows.sm,
}, },
})); }));
@@ -66,20 +77,24 @@ const Progressbar: React.FC = () => {
return ( return (
<> <>
{visible && ( <Box className={classes.wrapper}>
<Box className={classes.container}> <ScaleFade visible={visible}>
<Box <Box className={classes.container}>
className={classes.bar} <Box
onAnimationEnd={progressComplete} className={classes.bar}
sx={{ onAnimationEnd={progressComplete}
width: '0%', sx={{
animation: 'progress-bar linear', animation: 'progress-bar linear',
animationDuration: `${duration}ms`, animationDuration: `${duration}ms`,
}} }}
/> >
<Text className={classes.label}>{label}</Text> <Box className={classes.labelWrapper}>
</Box> <Text className={classes.label}>{label}</Text>
)} </Box>
</Box>
</Box>
</ScaleFade>
</Box>
</> </>
); );
}; };