/
Progress.tsx
42 lines (37 loc) · 1.33 KB
/
Progress.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import * as React from 'react';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import LinearProgress from '@mui/material/LinearProgress';
import { IProgressSlot } from '../../../slots/ProgressSlot';
const percent = (v: number, m: number) => Math.min(100, Math.round((Math.max(Number(v), 0) / m) * 100));
/**
* Represents a progress component.
*
* @param props - The properties for the Progress component.
* @param props.maxPercent - The maximum percentage value for the progress.
* @param props.showPercentLabel - Flag indicating whether to show the percentage label.
* @param props.value - The current value of the progress.
* @returns - The Progress component.
*/
export const Progress = ({
maxPercent = 1.0,
showPercentLabel,
value,
}: IProgressSlot) => (
<Box display="flex" alignItems="center">
<Box width="100%" mr={1}>
<LinearProgress
variant="determinate"
value={percent(Number(value), Number(maxPercent))}
/>
</Box>
{showPercentLabel && (
<Box minWidth={35}>
<Typography variant="body2" color="textSecondary">
{`${percent(Number(value), Number(maxPercent))}%`}
</Typography>
</Box>
)}
</Box>
);
export default Progress;