@trackunit/react-drawer 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +35 -1
- package/index.esm.js +35 -1
- package/package.json +1 -1
- package/src/hooks/index.d.ts +1 -0
- package/src/hooks/useScrollBlock.d.ts +6 -0
package/index.cjs.js
CHANGED
|
@@ -178,7 +178,7 @@ const cvaDrawerContent = cssClassVarianceUtilities.cvaMerge(["flex", "h-full", "
|
|
|
178
178
|
left: "rounded-r-lg",
|
|
179
179
|
right: "rounded-l-lg",
|
|
180
180
|
top: ["flex-col", "rounded-b-lg"],
|
|
181
|
-
bottom: ["max-h-[calc(
|
|
181
|
+
bottom: ["max-h-[calc(100dvh-10px)]", "flex-col", "rounded-t-lg", "sm:max-h-none"],
|
|
182
182
|
},
|
|
183
183
|
},
|
|
184
184
|
});
|
|
@@ -294,6 +294,39 @@ const cvaToggleContainer = cssClassVarianceUtilities.cvaMerge(["z-8", "absolute"
|
|
|
294
294
|
},
|
|
295
295
|
});
|
|
296
296
|
|
|
297
|
+
/**
|
|
298
|
+
* Hook for blocking scroll to prevent strange behaviors when full-screen swipeable components are open.
|
|
299
|
+
*/
|
|
300
|
+
const useScrollBlock = ({ isDisabled }) => {
|
|
301
|
+
const scrollBlocked = react.useRef(false);
|
|
302
|
+
const blockScroll = react.useCallback(() => {
|
|
303
|
+
const { body } = document;
|
|
304
|
+
const html = document.documentElement;
|
|
305
|
+
const scrollBarWidth = window.innerWidth - (html.clientWidth || 0);
|
|
306
|
+
const bodyPaddingRight = parseInt(window.getComputedStyle(body).getPropertyValue("padding-right")) || 0;
|
|
307
|
+
html.style.position = "relative";
|
|
308
|
+
html.style.overflow = "hidden";
|
|
309
|
+
body.style.position = "relative";
|
|
310
|
+
body.style.overflow = "hidden";
|
|
311
|
+
body.style.paddingRight = `${bodyPaddingRight + scrollBarWidth}px`;
|
|
312
|
+
scrollBlocked.current = true;
|
|
313
|
+
return () => {
|
|
314
|
+
html.style.position = "";
|
|
315
|
+
html.style.overflow = "";
|
|
316
|
+
body.style.position = "";
|
|
317
|
+
body.style.overflow = "";
|
|
318
|
+
body.style.paddingRight = "";
|
|
319
|
+
scrollBlocked.current = false;
|
|
320
|
+
};
|
|
321
|
+
}, []);
|
|
322
|
+
react.useEffect(() => {
|
|
323
|
+
if (isDisabled) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
return blockScroll();
|
|
327
|
+
}, [isDisabled, blockScroll]);
|
|
328
|
+
};
|
|
329
|
+
|
|
297
330
|
/**
|
|
298
331
|
* Retrieves the Y-axis translation value of a given HTML element.
|
|
299
332
|
*
|
|
@@ -392,6 +425,7 @@ const SwipeableDrawer = ({ open, onClose, onOpenGesture, children, keepMountedWh
|
|
|
392
425
|
onCloseGesture: onClose,
|
|
393
426
|
onOpenGesture,
|
|
394
427
|
});
|
|
428
|
+
useScrollBlock({ isDisabled: !open || isDragging });
|
|
395
429
|
const drawerStyle = react.useMemo(() => isDragging
|
|
396
430
|
? {
|
|
397
431
|
transform: `translateY(${dragDistance}px)`,
|
package/index.esm.js
CHANGED
|
@@ -176,7 +176,7 @@ const cvaDrawerContent = cvaMerge(["flex", "h-full", "shadow-lg", "bg-white"], {
|
|
|
176
176
|
left: "rounded-r-lg",
|
|
177
177
|
right: "rounded-l-lg",
|
|
178
178
|
top: ["flex-col", "rounded-b-lg"],
|
|
179
|
-
bottom: ["max-h-[calc(
|
|
179
|
+
bottom: ["max-h-[calc(100dvh-10px)]", "flex-col", "rounded-t-lg", "sm:max-h-none"],
|
|
180
180
|
},
|
|
181
181
|
},
|
|
182
182
|
});
|
|
@@ -292,6 +292,39 @@ const cvaToggleContainer = cvaMerge(["z-8", "absolute"], {
|
|
|
292
292
|
},
|
|
293
293
|
});
|
|
294
294
|
|
|
295
|
+
/**
|
|
296
|
+
* Hook for blocking scroll to prevent strange behaviors when full-screen swipeable components are open.
|
|
297
|
+
*/
|
|
298
|
+
const useScrollBlock = ({ isDisabled }) => {
|
|
299
|
+
const scrollBlocked = useRef(false);
|
|
300
|
+
const blockScroll = useCallback(() => {
|
|
301
|
+
const { body } = document;
|
|
302
|
+
const html = document.documentElement;
|
|
303
|
+
const scrollBarWidth = window.innerWidth - (html.clientWidth || 0);
|
|
304
|
+
const bodyPaddingRight = parseInt(window.getComputedStyle(body).getPropertyValue("padding-right")) || 0;
|
|
305
|
+
html.style.position = "relative";
|
|
306
|
+
html.style.overflow = "hidden";
|
|
307
|
+
body.style.position = "relative";
|
|
308
|
+
body.style.overflow = "hidden";
|
|
309
|
+
body.style.paddingRight = `${bodyPaddingRight + scrollBarWidth}px`;
|
|
310
|
+
scrollBlocked.current = true;
|
|
311
|
+
return () => {
|
|
312
|
+
html.style.position = "";
|
|
313
|
+
html.style.overflow = "";
|
|
314
|
+
body.style.position = "";
|
|
315
|
+
body.style.overflow = "";
|
|
316
|
+
body.style.paddingRight = "";
|
|
317
|
+
scrollBlocked.current = false;
|
|
318
|
+
};
|
|
319
|
+
}, []);
|
|
320
|
+
useEffect(() => {
|
|
321
|
+
if (isDisabled) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
return blockScroll();
|
|
325
|
+
}, [isDisabled, blockScroll]);
|
|
326
|
+
};
|
|
327
|
+
|
|
295
328
|
/**
|
|
296
329
|
* Retrieves the Y-axis translation value of a given HTML element.
|
|
297
330
|
*
|
|
@@ -390,6 +423,7 @@ const SwipeableDrawer = ({ open, onClose, onOpenGesture, children, keepMountedWh
|
|
|
390
423
|
onCloseGesture: onClose,
|
|
391
424
|
onOpenGesture,
|
|
392
425
|
});
|
|
426
|
+
useScrollBlock({ isDisabled: !open || isDragging });
|
|
393
427
|
const drawerStyle = useMemo(() => isDragging
|
|
394
428
|
? {
|
|
395
429
|
transform: `translateY(${dragDistance}px)`,
|
package/package.json
CHANGED
package/src/hooks/index.d.ts
CHANGED