ProgressCard.tsx 921 B

12345678910111213141516171819202122232425262728
  1. import { FC } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import BaseCard from './BaseCard';
  4. import Progress from './Progress';
  5. import { getByteString } from '../../utils/Format';
  6. import { ProgressCardProps } from './Types';
  7. const color1 = '#06F3AF';
  8. const color2 = '#635DCE';
  9. const ProgressCard: FC<ProgressCardProps> = (props) => {
  10. const { title, total, usage } = props;
  11. const { t } = useTranslation('systemView');
  12. const { t: commonTrans } = useTranslation();
  13. const capacityTrans: { [key in string]: string } = commonTrans('capacity');
  14. const color = title === t('diskTitle') ? color1 : color2;
  15. const percent = (usage && total) ? (usage / total) : 0;
  16. return (
  17. <BaseCard title={title} content={`${getByteString(usage, total, capacityTrans)} (${Math.floor(percent * 100)}%)`}>
  18. <Progress percent={percent} color={color} />
  19. </BaseCard>
  20. );
  21. };
  22. export default ProgressCard;