ActionBar.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { FC } from 'react';
  2. import { IconButton, Theme, Button, Typography } from '@mui/material';
  3. import { makeStyles } from '@mui/styles';
  4. import Icons from '../icons/Icons';
  5. import { ActionBarType } from './Types';
  6. import CustomToolTip from '../customToolTip/CustomToolTip';
  7. const useStyles = makeStyles((theme: Theme) => ({
  8. root: {
  9. position: 'relative',
  10. display: 'inline-block',
  11. marginRight: theme.spacing(1),
  12. },
  13. tip: {
  14. position: 'absolute',
  15. left: 0,
  16. bottom: '-10px',
  17. fontSize: '10px',
  18. textTransform: 'capitalize',
  19. textAlign: 'center',
  20. width: '100%',
  21. },
  22. disabled: {
  23. color: theme.palette.common.black,
  24. opacity: 0.15,
  25. },
  26. hoverType: {
  27. marginRight: 0,
  28. '& button': {
  29. color: '#fff',
  30. },
  31. },
  32. link: {
  33. textDecoration: 'underline',
  34. color: theme.palette.common.black,
  35. },
  36. }));
  37. const ActionBar: FC<ActionBarType> = props => {
  38. const classes = useStyles();
  39. const { configs, row, isHoverType = false } = props;
  40. return (
  41. <>
  42. {configs.map((v, i) => {
  43. const label = v.getLabel ? v.getLabel(row) : v.label;
  44. return (
  45. <span
  46. className={`${classes.root} ${v.className} ${
  47. isHoverType ? classes.hoverType : ''
  48. }`}
  49. key={i}
  50. >
  51. <CustomToolTip title={label || ''} placement="bottom">
  52. {v.icon ? (
  53. <IconButton
  54. aria-label={label || ''}
  55. onClickCapture={e => {
  56. e.stopPropagation();
  57. v.onClick(e, row);
  58. }}
  59. disabled={v.disabled ? v.disabled(row) : false}
  60. classes={{
  61. disabled: classes.disabled,
  62. }}
  63. size="large"
  64. >
  65. {v.showIconMethod === 'renderFn'
  66. ? v.renderIconFn && v.renderIconFn(row)
  67. : Icons[v.icon]()}
  68. </IconButton>
  69. ) : v.linkButton ? (
  70. <Typography
  71. component="a"
  72. href="#/users"
  73. className={classes.link}
  74. onClick={e => {
  75. e.stopPropagation();
  76. v.onClick(e, row);
  77. }}
  78. >
  79. {v.text}
  80. </Typography>
  81. ) : (
  82. <Button
  83. aria-label={label || ''}
  84. onClickCapture={e => {
  85. e.stopPropagation();
  86. v.onClick(e, row);
  87. }}
  88. size="small"
  89. disabled={v.disabled ? v.disabled(row) : false}
  90. classes={{
  91. disabled: classes.disabled,
  92. }}
  93. >
  94. {v.text}
  95. </Button>
  96. )}
  97. </CustomToolTip>
  98. </span>
  99. );
  100. })}
  101. </>
  102. );
  103. };
  104. export default ActionBar;