Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

feat(SidebarDrawer):use-SwipeableDrawer

Aswin Asoka69e4cd300e8
diff --git a/web/packages/base/components/mui/SidebarDrawer.tsx b/web/packages/base/components/mui/SidebarDrawer.tsx
index 93862059e6..27e974545d 100644
--- a/web/packages/base/components/mui/SidebarDrawer.tsx
+++ b/web/packages/base/components/mui/SidebarDrawer.tsx
@@ -2,12 +2,13 @@ import ArrowBackIcon from "@mui/icons-material/ArrowBack";
import CloseIcon from "@mui/icons-material/Close";
import {
Box,
- Drawer,
IconButton,
Stack,
styled,
+ SwipeableDrawer,
Typography,
type DrawerProps,
+ type SwipeableDrawerProps,
} from "@mui/material";
import { isDesktop } from "ente-base/app";
import type { ModalVisibilityProps } from "ente-base/components/utils/modal";
@@ -26,27 +27,44 @@ import React from "react";
export const SidebarDrawer: React.FC<DrawerProps> = ({
slotProps,
children,
+ onClose,
+ open,
...rest
-}) => (
- <Drawer
- {...rest}
- slotProps={{
- ...(slotProps ?? {}),
- paper: {
- sx: {
- maxWidth: "375px",
- width: "100%",
- scrollbarWidth: "thin",
- // Need to increase specificity to override inherited padding.
- "&&": { padding: 0 },
- },
+}) => {
+ const commonSlotProps = {
+ ...(slotProps ?? {}),
+ paper: {
+ sx: {
+ maxWidth: "375px",
+ width: "100%",
+ scrollbarWidth: "thin",
+ // Need to increase specificity to override inherited padding.
+ "&&": { padding: 0 },
},
- }}
- >
- {isDesktop && <AppTitlebarBackdrop />}
- <Box sx={{ p: 1 }}>{children}</Box>
- </Drawer>
-);
+ },
+ };
+
+ const handleSwipeableClose: SwipeableDrawerProps["onClose"] = (event) => {
+ onClose?.(event as React.SyntheticEvent, "backdropClick");
+ };
+ const handleSwipeableOpen: SwipeableDrawerProps["onOpen"] = () => {
+ // Intentionally a no-op; required by SwipeableDrawer.
+ };
+
+ return (
+ <SwipeableDrawer
+ {...rest}
+ open={open}
+ disableSwipeToOpen
+ onClose={handleSwipeableClose}
+ onOpen={handleSwipeableOpen}
+ slotProps={commonSlotProps}
+ >
+ {isDesktop && <AppTitlebarBackdrop />}
+ <Box sx={{ p: 1 }}>{children}</Box>
+ </SwipeableDrawer>
+ );
+};
/**
* When running on desktop, we adds a sticky opaque bar at the top of the
@@ -92,8 +110,14 @@ export const NestedSidebarDrawer: React.FC<
NestedSidebarDrawerVisibilityProps & DrawerProps
> = ({ onClose, onRootClose, ...rest }) => {
// Intercept backdrop taps and repurpose them to close the entire stack.
- const handleClose: DrawerProps["onClose"] = (_, reason) => {
- if (reason == "backdropClick") {
+ const handleClose: DrawerProps["onClose"] = (event, reason) => {
+ const target = (event as { target?: EventTarget | null }).target;
+ const isBackdropEvent =
+ reason === "backdropClick" &&
+ target instanceof HTMLElement &&
+ target.classList.contains("MuiBackdrop-root");
+
+ if (isBackdropEvent) {
onClose();
onRootClose();
} else {