123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import React from 'react';
- import constants from 'utils/strings/constants';
- import {
- Breakpoint,
- Button,
- DialogActions,
- DialogContent,
- DialogProps,
- Typography,
- } from '@mui/material';
- import DialogTitleWithCloseButton, {
- dialogCloseHandler,
- } from './TitleWithCloseButton';
- import DialogBoxBase from './base';
- import { DialogBoxAttributes } from 'types/dialogBox';
- import DialogIcon from './DialogIcon';
- type IProps = React.PropsWithChildren<
- Omit<DialogProps, 'onClose' | 'maxSize'> & {
- onClose: () => void;
- attributes: DialogBoxAttributes;
- size?: Breakpoint;
- titleCloseButton?: boolean;
- }
- >;
- export default function DialogBox({
- attributes,
- children,
- open,
- size,
- onClose,
- titleCloseButton,
- ...props
- }: IProps) {
- if (!attributes) {
- return <></>;
- }
- const handleClose = dialogCloseHandler({
- staticBackdrop: attributes.staticBackdrop,
- nonClosable: attributes.nonClosable,
- onClose: onClose,
- });
- return (
- <DialogBoxBase
- open={open}
- maxWidth={size}
- onClose={handleClose}
- {...props}>
- {attributes.icon && <DialogIcon icon={attributes.icon} />}
- {attributes.title && (
- <DialogTitleWithCloseButton
- onClose={
- titleCloseButton &&
- !attributes.nonClosable &&
- handleClose
- }>
- {attributes.title}
- </DialogTitleWithCloseButton>
- )}
- {(children || attributes?.content) && (
- <DialogContent>
- {children || (
- <Typography color="text.secondary">
- {attributes.content}
- </Typography>
- )}
- </DialogContent>
- )}
- {(attributes.close || attributes.proceed) && (
- <DialogActions>
- <>
- {attributes.close && (
- <Button
- size="large"
- color={attributes.close?.variant ?? 'secondary'}
- onClick={() => {
- attributes.close.action &&
- attributes.close?.action();
- onClose();
- }}>
- {attributes.close?.text ?? constants.OK}
- </Button>
- )}
- {attributes.proceed && (
- <Button
- size="large"
- color={attributes.proceed?.variant}
- onClick={() => {
- attributes.proceed.action();
- onClose();
- }}
- disabled={attributes.proceed.disabled}>
- {attributes.proceed.text}
- </Button>
- )}
- </>
- </DialogActions>
- )}
- </DialogBoxBase>
- );
- }
|