DialogTemplate.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. },
  16. }));
  17. const DialogTemplate: FC<DialogContainerProps> = ({
  18. title,
  19. cancelLabel,
  20. handleClose,
  21. handleCancel,
  22. confirmLabel,
  23. handleConfirm,
  24. confirmDisabled,
  25. children,
  26. showActions = true,
  27. showCancel = true,
  28. showCloseIcon = true,
  29. }) => {
  30. const { t } = useTranslation('btn');
  31. const cancel = cancelLabel || t('cancel');
  32. const confirm = confirmLabel || t('confirm');
  33. const classes = useStyles();
  34. const onCancel = handleCancel || handleClose;
  35. return (
  36. <>
  37. <CustomDialogTitle onClose={handleClose} showCloseIcon={showCloseIcon}>
  38. {title}
  39. </CustomDialogTitle>
  40. <DialogContent>{children}</DialogContent>
  41. {showActions && (
  42. <DialogActions className={classes.actions}>
  43. {showCancel && (
  44. <CustomButton onClick={onCancel} color="default" name="cancel">
  45. {cancel}
  46. </CustomButton>
  47. )}
  48. <CustomButton
  49. variant="contained"
  50. onClick={handleConfirm}
  51. color="primary"
  52. disabled={confirmDisabled}
  53. name="confirm"
  54. >
  55. {confirm}
  56. </CustomButton>
  57. </DialogActions>
  58. )}
  59. </>
  60. );
  61. };
  62. export default DialogTemplate;