TitleWithCloseButton.tsx 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { SpaceBetweenFlex } from "@ente/shared/components/Container";
  2. import CloseIcon from "@mui/icons-material/Close";
  3. import {
  4. DialogTitle,
  5. IconButton,
  6. Typography,
  7. type DialogProps,
  8. } from "@mui/material";
  9. const DialogTitleWithCloseButton = (props) => {
  10. const { children, onClose, ...other } = props;
  11. return (
  12. <DialogTitle {...other}>
  13. <SpaceBetweenFlex>
  14. <Typography variant="h3" fontWeight={"bold"}>
  15. {children}
  16. </Typography>
  17. {onClose && (
  18. <IconButton
  19. aria-label="close"
  20. onClick={onClose}
  21. sx={{ float: "right" }}
  22. color="secondary"
  23. >
  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. };