TitleWithCloseButton.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import React from 'react';
  2. import {
  3. DialogProps,
  4. DialogTitle,
  5. IconButton,
  6. Typography,
  7. } from '@mui/material';
  8. import CloseIcon from '@mui/icons-material/Close';
  9. import { SpaceBetweenFlex } from '@ente/shared/components/Container';
  10. const DialogTitleWithCloseButton = (props) => {
  11. const { children, onClose, ...other } = props;
  12. return (
  13. <DialogTitle {...other}>
  14. <SpaceBetweenFlex>
  15. <Typography variant="h3" fontWeight={'bold'}>
  16. {children}
  17. </Typography>
  18. {onClose && (
  19. <IconButton
  20. aria-label="close"
  21. onClick={onClose}
  22. sx={{ float: 'right' }}
  23. color="secondary">
  24. <CloseIcon />
  25. </IconButton>
  26. )}
  27. </SpaceBetweenFlex>
  28. </DialogTitle>
  29. );
  30. };
  31. export default DialogTitleWithCloseButton;
  32. export const dialogCloseHandler =
  33. ({
  34. staticBackdrop,
  35. nonClosable,
  36. onClose,
  37. }: {
  38. staticBackdrop?: boolean;
  39. nonClosable?: boolean;
  40. onClose: () => void;
  41. }): DialogProps['onClose'] =>
  42. (_, reason) => {
  43. if (nonClosable) {
  44. // no-op
  45. } else if (staticBackdrop && reason === 'backdropClick') {
  46. // no-op
  47. } else {
  48. onClose();
  49. }
  50. };