LinearProgressWithLabel.tsx 950 B

12345678910111213141516171819202122
  1. import { Box, LinearProgress, LinearProgressProps, Typography } from '@material-ui/core';
  2. export function normalise(value: number, min: number, max: number) {
  3. return (Number(value) - Number(min)) * 100 / (Number(max) - Number(min));
  4. }
  5. export function LinearProgressWithLabel(props: LinearProgressProps & { value: number; min: number; max: number; }) {
  6. return props.value > 0 ? (
  7. <div style={{ width: '98%' }}>
  8. <Box display="flex" alignItems="center">
  9. <Box width="100%" mr={1}>
  10. <LinearProgress variant="determinate" value={normalise(props.value, props.min, props.max)} />
  11. </Box>
  12. <Box minWidth={35} style={{ whiteSpace: "nowrap" }}>
  13. <Typography variant="body2" color="textSecondary">
  14. {`${Math.round(normalise(props.value, props.min, props.max))}% (${props.value}/${props.max})`}
  15. </Typography>
  16. </Box>
  17. </Box>
  18. </div>
  19. ) : null;
  20. }