index.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import React from 'react';
  2. import constants from 'utils/strings/constants';
  3. import {
  4. Breakpoint,
  5. Button,
  6. DialogActions,
  7. DialogContent,
  8. DialogProps,
  9. Typography,
  10. } from '@mui/material';
  11. import DialogTitleWithCloseButton, {
  12. dialogCloseHandler,
  13. } from './TitleWithCloseButton';
  14. import DialogBoxBase from './base';
  15. import { DialogBoxAttributes } from 'types/dialogBox';
  16. import DialogIcon from './DialogIcon';
  17. type IProps = React.PropsWithChildren<
  18. Omit<DialogProps, 'onClose' | 'maxSize'> & {
  19. onClose: () => void;
  20. attributes: DialogBoxAttributes;
  21. size?: Breakpoint;
  22. titleCloseButton?: boolean;
  23. }
  24. >;
  25. export default function DialogBox({
  26. attributes,
  27. children,
  28. open,
  29. size,
  30. onClose,
  31. titleCloseButton,
  32. ...props
  33. }: IProps) {
  34. if (!attributes) {
  35. return <></>;
  36. }
  37. const handleClose = dialogCloseHandler({
  38. staticBackdrop: attributes.staticBackdrop,
  39. nonClosable: attributes.nonClosable,
  40. onClose: onClose,
  41. });
  42. return (
  43. <DialogBoxBase
  44. open={open}
  45. maxWidth={size}
  46. onClose={handleClose}
  47. {...props}>
  48. {attributes.icon && <DialogIcon icon={attributes.icon} />}
  49. {attributes.title && (
  50. <DialogTitleWithCloseButton
  51. onClose={
  52. titleCloseButton &&
  53. !attributes.nonClosable &&
  54. handleClose
  55. }>
  56. {attributes.title}
  57. </DialogTitleWithCloseButton>
  58. )}
  59. {(children || attributes?.content) && (
  60. <DialogContent>
  61. {children || (
  62. <Typography color="text.secondary">
  63. {attributes.content}
  64. </Typography>
  65. )}
  66. </DialogContent>
  67. )}
  68. {(attributes.close || attributes.proceed) && (
  69. <DialogActions>
  70. <>
  71. {attributes.close && (
  72. <Button
  73. size="large"
  74. color={attributes.close?.variant ?? 'secondary'}
  75. onClick={() => {
  76. attributes.close.action &&
  77. attributes.close?.action();
  78. onClose();
  79. }}>
  80. {attributes.close?.text ?? constants.OK}
  81. </Button>
  82. )}
  83. {attributes.proceed && (
  84. <Button
  85. size="large"
  86. color={attributes.proceed?.variant}
  87. onClick={() => {
  88. attributes.proceed.action();
  89. onClose();
  90. }}
  91. disabled={attributes.proceed.disabled}>
  92. {attributes.proceed.text}
  93. </Button>
  94. )}
  95. </>
  96. </DialogActions>
  97. )}
  98. </DialogBoxBase>
  99. );
  100. }