CustomLinearProgress.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {
  2. makeStyles,
  3. withStyles,
  4. Theme,
  5. LinearProgress,
  6. Tooltip,
  7. Typography,
  8. } from '@material-ui/core';
  9. import { FC } from 'react';
  10. import { CustomLinearProgressProps } from './Types';
  11. const getProgressStyles = makeStyles((theme: Theme) => ({
  12. wrapper: {
  13. display: 'flex',
  14. alignItems: 'center',
  15. },
  16. percent: {
  17. minWidth: '35px',
  18. marginLeft: theme.spacing(1),
  19. color: theme.palette.milvusDark.main,
  20. },
  21. }));
  22. const BorderLinearProgress = withStyles((theme: Theme) => ({
  23. root: {
  24. height: 10,
  25. borderRadius: 8,
  26. border: '1px solid #e9e9ed',
  27. minWidth: 85,
  28. },
  29. colorPrimary: {
  30. backgroundColor: '#fff',
  31. },
  32. bar: {
  33. borderRadius: 5,
  34. backgroundColor: theme.palette.primary.main,
  35. },
  36. }))(LinearProgress);
  37. const CustomLinearProgress: FC<CustomLinearProgressProps> = ({
  38. value,
  39. tooltip = '',
  40. wrapperClass = '',
  41. }) => {
  42. const classes = getProgressStyles();
  43. return (
  44. <div className={`${classes.wrapper} ${wrapperClass}`}>
  45. {tooltip !== '' ? (
  46. <Tooltip title={tooltip} aria-label={tooltip} arrow>
  47. <BorderLinearProgress variant="determinate" value={value} />
  48. </Tooltip>
  49. ) : (
  50. <BorderLinearProgress variant="determinate" value={value} />
  51. )}
  52. <Typography
  53. variant="body1"
  54. className={classes.percent}
  55. >{`${value}%`}</Typography>
  56. </div>
  57. );
  58. };
  59. export default CustomLinearProgress;