DialogTemplate.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { FC } from 'react';
  2. import { useTranslation } from 'react-i18next';
  3. import {
  4. DialogContent,
  5. DialogActions,
  6. makeStyles,
  7. Theme,
  8. } from '@material-ui/core';
  9. import { DialogContainerProps } from './Types';
  10. import CustomDialogTitle from './CustomDialogTitle';
  11. import CustomButton from '../customButton/CustomButton';
  12. const useStyles = makeStyles((theme: Theme) => ({
  13. actions: {
  14. paddingTop: theme.spacing(2),
  15. justifyContent: 'space-between',
  16. },
  17. }));
  18. const DialogTemplate: FC<DialogContainerProps> = ({
  19. title,
  20. cancelLabel,
  21. handleClose,
  22. handleCancel,
  23. confirmLabel,
  24. handleConfirm,
  25. confirmDisabled,
  26. children,
  27. showActions = true,
  28. showCancel = true,
  29. showCloseIcon = true,
  30. leftActions,
  31. }) => {
  32. const { t } = useTranslation('btn');
  33. const cancel = cancelLabel || t('cancel');
  34. const confirm = confirmLabel || t('confirm');
  35. const classes = useStyles();
  36. const onCancel = handleCancel || handleClose;
  37. return (
  38. <>
  39. <CustomDialogTitle onClose={handleClose} showCloseIcon={showCloseIcon}>
  40. {title}
  41. </CustomDialogTitle>
  42. <DialogContent>{children}</DialogContent>
  43. {showActions && (
  44. <DialogActions className={classes.actions}>
  45. <div>{leftActions}</div>
  46. <div>
  47. {showCancel && (
  48. <CustomButton onClick={onCancel} color="default" name="cancel">
  49. {cancel}
  50. </CustomButton>
  51. )}
  52. <CustomButton
  53. variant="contained"
  54. onClick={handleConfirm}
  55. color="primary"
  56. disabled={confirmDisabled}
  57. name="confirm"
  58. >
  59. {confirm}
  60. </CustomButton>
  61. </div>
  62. </DialogActions>
  63. )}
  64. </>
  65. );
  66. };
  67. export default DialogTemplate;