TitleWithCloseButton.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. import React from "react";
  10. interface DialogTitleWithCloseButtonProps {
  11. onClose: () => void;
  12. }
  13. const DialogTitleWithCloseButton: React.FC<
  14. React.PropsWithChildren<DialogTitleWithCloseButtonProps>
  15. > = ({ children, onClose }) => {
  16. return (
  17. <DialogTitle>
  18. <SpaceBetweenFlex>
  19. <Typography variant="h3" fontWeight={"bold"}>
  20. {children}
  21. </Typography>
  22. {onClose && (
  23. <IconButton
  24. aria-label="close"
  25. onClick={onClose}
  26. sx={{ float: "right" }}
  27. color="secondary"
  28. >
  29. <CloseIcon />
  30. </IconButton>
  31. )}
  32. </SpaceBetweenFlex>
  33. </DialogTitle>
  34. );
  35. };
  36. export default DialogTitleWithCloseButton;
  37. export const dialogCloseHandler =
  38. ({
  39. staticBackdrop,
  40. nonClosable,
  41. onClose,
  42. }: {
  43. staticBackdrop?: boolean;
  44. nonClosable?: boolean;
  45. onClose: () => void;
  46. }): DialogProps["onClose"] =>
  47. (_, reason) => {
  48. if (nonClosable) {
  49. // no-op
  50. } else if (staticBackdrop && reason === "backdropClick") {
  51. // no-op
  52. } else {
  53. onClose();
  54. }
  55. };