Status.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import { FC, useMemo } from 'react';
  2. import { StatusType, StatusEnum } from './Types';
  3. import { useTranslation } from 'react-i18next';
  4. import { makeStyles, Theme, createStyles, Typography } from '@material-ui/core';
  5. const useStyles = makeStyles((theme: Theme) =>
  6. createStyles({
  7. root: {
  8. display: 'flex',
  9. alignItems: 'center',
  10. },
  11. label: {
  12. color: '#82838e',
  13. textTransform: 'capitalize',
  14. },
  15. circle: {
  16. backgroundColor: (props: any) => props.color,
  17. borderRadius: '50%',
  18. width: '10px',
  19. height: '10px',
  20. marginRight: theme.spacing(0.5),
  21. },
  22. flash: {
  23. animation: '$bgColorChange 1.5s infinite',
  24. },
  25. '@keyframes bgColorChange': {
  26. '0%': {
  27. backgroundColor: (props: any) => props.color,
  28. },
  29. '50%': {
  30. backgroundColor: 'transparent',
  31. },
  32. '100%': {
  33. backgroundColor: (props: any) => props.color,
  34. },
  35. },
  36. })
  37. );
  38. const Status: FC<StatusType> = props => {
  39. const { status } = props;
  40. const { t } = useTranslation();
  41. const statusTrans: { [key in string]: string } = t('status');
  42. const { label, color } = useMemo(() => {
  43. switch (status) {
  44. case StatusEnum.unloaded:
  45. return {
  46. label: statusTrans.unloaded,
  47. color: '#06aff2',
  48. };
  49. case StatusEnum.loaded:
  50. return {
  51. label: statusTrans.loaded,
  52. color: '#06f3af',
  53. };
  54. case StatusEnum.error:
  55. return {
  56. label: statusTrans.error,
  57. color: '#f25c06',
  58. };
  59. default:
  60. return {
  61. label: statusTrans.error,
  62. color: '#f25c06',
  63. };
  64. }
  65. }, [status, statusTrans]);
  66. const classes = useStyles({ color });
  67. return (
  68. <div className={classes.root}>
  69. {status === StatusEnum.loaded && <div className={classes.circle}></div>}
  70. <Typography variant="body2" className={classes.label}>
  71. {label}
  72. </Typography>
  73. </div>
  74. );
  75. };
  76. export default Status;