您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

VisitorsCountLabel.tsx 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import React from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import { useSelector } from 'react-redux';
  4. import { makeStyles } from 'tss-react/mui';
  5. import { IReduxState } from '../../../app/types';
  6. import { IconUsers } from '../../../base/icons/svg';
  7. import Label from '../../../base/label/components/web/Label';
  8. // eslint-disable-next-line lines-around-comment
  9. // @ts-ignore
  10. import { Tooltip } from '../../../base/tooltip';
  11. const useStyles = makeStyles()(theme => {
  12. return {
  13. label: {
  14. backgroundColor: theme.palette.warning02,
  15. color: theme.palette.uiBackground
  16. }
  17. };
  18. });
  19. const VisitorsCountLabel = () => {
  20. const { classes: styles, theme } = useStyles();
  21. const visitorsMode = useSelector((state: IReduxState) => state['features/visitors'].enabled);
  22. const visitorsCount = useSelector((state: IReduxState) =>
  23. state['features/visitors'].count || 0);
  24. const { t } = useTranslation();
  25. let visitorsCountLabel = String(visitorsCount);
  26. // over 100 we show numbers lik 0.2 K or 9.5 K.
  27. if (visitorsCount > 100) {
  28. visitorsCountLabel = `${Math.round(visitorsCount / 100) / 10} K`;
  29. }
  30. return visitorsMode && (<Tooltip
  31. content = { t('visitorsLabel', { count: visitorsCount }) }
  32. position = { 'bottom' }>
  33. <Label
  34. className = { styles.label }
  35. icon = { IconUsers }
  36. iconColor = { theme.palette.icon04 }
  37. id = 'visitorsCountLabel'
  38. text = { `${visitorsCountLabel}` } />
  39. </Tooltip>);
  40. };
  41. export default VisitorsCountLabel;