ActionBar.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { FC } from 'react';
  2. import { IconButton, makeStyles, Theme, createStyles } from '@material-ui/core';
  3. import Icons from '../icons/Icons';
  4. import { ActionBarType } from './Types';
  5. import CustomToolTip from '../customToolTip/CustomToolTip';
  6. const useStyles = makeStyles((theme: Theme) =>
  7. createStyles({
  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. })
  33. );
  34. const ActionBar: FC<ActionBarType> = props => {
  35. const classes = useStyles();
  36. const { configs, row, isHoverType = false } = props;
  37. return (
  38. <>
  39. {configs.map(v => {
  40. const label = v.getLabel ? v.getLabel(row) : v.label;
  41. return (
  42. <span
  43. className={`${classes.root} ${v.className} ${
  44. isHoverType ? classes.hoverType : ''
  45. }`}
  46. key={label}
  47. >
  48. <CustomToolTip title={label || ''} placement="bottom">
  49. <IconButton
  50. aria-label={label || ''}
  51. onClickCapture={e => {
  52. e.stopPropagation();
  53. v.onClick(e, row);
  54. }}
  55. disabled={v.disabled ? v.disabled(row) : false}
  56. classes={{
  57. disabled: classes.disabled,
  58. }}
  59. >
  60. {v.showIconMethod === 'renderFn'
  61. ? v.renderIconFn && v.renderIconFn(row)
  62. : Icons[v.icon]()}
  63. </IconButton>
  64. </CustomToolTip>
  65. </span>
  66. );
  67. })}
  68. </>
  69. );
  70. };
  71. export default ActionBar;