TimeRangeTabs.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { makeStyles, Theme } from '@material-ui/core';
  2. import { Dispatch, Fragment, SetStateAction } from 'react';
  3. import { timeRangeOptions } from './consts';
  4. import { ITimeRangeOption } from './Types';
  5. import clsx from 'clsx';
  6. const getStyles = makeStyles((theme: Theme) => ({
  7. root: {
  8. fontSize: '14px',
  9. display: 'flex',
  10. alignItems: 'flex-end',
  11. color: '#999',
  12. fontWeight: 500,
  13. },
  14. divider: {
  15. margin: '0 4px',
  16. },
  17. label: {
  18. cursor: 'pointer',
  19. '&:hover': {
  20. fontSize: '16px',
  21. },
  22. },
  23. active: {
  24. fontWeight: 600,
  25. fontSize: '16px',
  26. color: '#222',
  27. },
  28. }));
  29. const TimeRangeTabs = ({
  30. timeRange,
  31. setTimeRange,
  32. }: {
  33. timeRange: ITimeRangeOption;
  34. setTimeRange: Dispatch<SetStateAction<ITimeRangeOption>>;
  35. }) => {
  36. const classes = getStyles();
  37. return (
  38. <div className={classes.root}>
  39. {timeRangeOptions.map((timeRangeOption, i: number) => (
  40. <Fragment key={timeRangeOption.label}>
  41. {i > 0 && <div className={classes.divider}>{'/'}</div>}
  42. <div
  43. className={clsx(
  44. classes.label,
  45. timeRangeOption.value === timeRange.value && classes.active
  46. )}
  47. onClick={() => setTimeRange(timeRangeOption)}
  48. >
  49. {timeRangeOption.label}
  50. </div>
  51. </Fragment>
  52. ))}
  53. </div>
  54. );
  55. };
  56. export default TimeRangeTabs;