react-modal-sheet 5.1.2 → 5.2.1
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/README.md +175 -3
- package/dist/index.d.mts +110 -2
- package/dist/index.d.ts +110 -2
- package/dist/index.js +43 -24
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +14 -14
- package/src/SheetContent.tsx +5 -3
- package/src/hooks/use-scroll-position.ts +69 -12
- package/src/hooks/use-virtual-keyboard.ts +58 -17
- package/src/index.tsx +3 -0
- package/src/types.tsx +10 -9
package/dist/index.mjs
CHANGED
|
@@ -270,12 +270,12 @@ function useDragConstraints() {
|
|
|
270
270
|
const onMeasure = useCallback(() => constraints, []);
|
|
271
271
|
return { ref, onMeasure };
|
|
272
272
|
}
|
|
273
|
-
function useScrollPosition() {
|
|
274
|
-
const
|
|
273
|
+
function useScrollPosition(options = {}) {
|
|
274
|
+
const { debounceDelay = 32, isEnabled = true } = options;
|
|
275
|
+
const [element, setElement] = useState(null);
|
|
275
276
|
const [scrollPosition, setScrollPosition] = useState(void 0);
|
|
276
277
|
useEffect(() => {
|
|
277
|
-
|
|
278
|
-
if (!element) return;
|
|
278
|
+
if (!element || !isEnabled) return;
|
|
279
279
|
let scrollTimeout = null;
|
|
280
280
|
function determineScrollPosition(element2) {
|
|
281
281
|
const { scrollTop, scrollHeight, clientHeight } = element2;
|
|
@@ -298,14 +298,21 @@ function useScrollPosition() {
|
|
|
298
298
|
setScrollPosition(position);
|
|
299
299
|
}
|
|
300
300
|
function onScroll(event) {
|
|
301
|
-
if (event.currentTarget instanceof
|
|
301
|
+
if (event.currentTarget instanceof HTMLElement) {
|
|
302
302
|
const el = event.currentTarget;
|
|
303
303
|
if (scrollTimeout) clearTimeout(scrollTimeout);
|
|
304
|
-
|
|
304
|
+
if (debounceDelay === 0) {
|
|
305
|
+
determineScrollPosition(el);
|
|
306
|
+
} else {
|
|
307
|
+
scrollTimeout = setTimeout(
|
|
308
|
+
() => determineScrollPosition(el),
|
|
309
|
+
debounceDelay
|
|
310
|
+
);
|
|
311
|
+
}
|
|
305
312
|
}
|
|
306
313
|
}
|
|
307
314
|
function onTouchStart(event) {
|
|
308
|
-
if (event.currentTarget instanceof
|
|
315
|
+
if (event.currentTarget instanceof HTMLElement) {
|
|
309
316
|
determineScrollPosition(event.currentTarget);
|
|
310
317
|
}
|
|
311
318
|
}
|
|
@@ -317,8 +324,11 @@ function useScrollPosition() {
|
|
|
317
324
|
element.removeEventListener("scroll", onScroll);
|
|
318
325
|
element.removeEventListener("touchstart", onTouchStart);
|
|
319
326
|
};
|
|
320
|
-
}, []);
|
|
321
|
-
return {
|
|
327
|
+
}, [element, isEnabled]);
|
|
328
|
+
return {
|
|
329
|
+
scrollRef: (element2) => setElement(element2),
|
|
330
|
+
scrollPosition
|
|
331
|
+
};
|
|
322
332
|
}
|
|
323
333
|
|
|
324
334
|
// src/SheetContent.tsx
|
|
@@ -329,6 +339,8 @@ var SheetContent = forwardRef(
|
|
|
329
339
|
children,
|
|
330
340
|
style: styleProp,
|
|
331
341
|
className = "",
|
|
342
|
+
scrollClassName = "",
|
|
343
|
+
scrollStyle: scrollStyleProp,
|
|
332
344
|
scrollRef: scrollRefProp = null,
|
|
333
345
|
unstyled,
|
|
334
346
|
...rest
|
|
@@ -373,9 +385,9 @@ var SheetContent = forwardRef(
|
|
|
373
385
|
/* @__PURE__ */ React4.createElement(
|
|
374
386
|
motion.div,
|
|
375
387
|
{
|
|
376
|
-
ref: mergeRefs([scroll.
|
|
377
|
-
style: scrollStyle,
|
|
378
|
-
className:
|
|
388
|
+
ref: mergeRefs([scroll.scrollRef, scrollRefProp]),
|
|
389
|
+
style: { ...scrollStyle, ...scrollStyleProp },
|
|
390
|
+
className: `react-modal-sheet-content-scroller ${scrollClassName}`
|
|
379
391
|
},
|
|
380
392
|
children
|
|
381
393
|
)
|
|
@@ -873,13 +885,14 @@ function useSheetState({
|
|
|
873
885
|
}, [state]);
|
|
874
886
|
return state;
|
|
875
887
|
}
|
|
876
|
-
function useVirtualKeyboard({
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
888
|
+
function useVirtualKeyboard(options = {}) {
|
|
889
|
+
const {
|
|
890
|
+
containerRef,
|
|
891
|
+
isEnabled = true,
|
|
892
|
+
debounceDelay = 100,
|
|
893
|
+
includeContentEditable = true,
|
|
894
|
+
visualViewportThreshold = 100
|
|
895
|
+
} = options;
|
|
883
896
|
const [state, setState] = useState({
|
|
884
897
|
isVisible: false,
|
|
885
898
|
height: 0
|
|
@@ -894,11 +907,15 @@ function useVirtualKeyboard({
|
|
|
894
907
|
const vv = window.visualViewport;
|
|
895
908
|
const vk = navigator.virtualKeyboard;
|
|
896
909
|
function setKeyboardInsetHeightEnv(height) {
|
|
897
|
-
|
|
898
|
-
(
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
910
|
+
const element = (containerRef == null ? void 0 : containerRef.current) || document.documentElement;
|
|
911
|
+
if (window.isSecureContext) {
|
|
912
|
+
element.style.setProperty(
|
|
913
|
+
"--keyboard-inset-height",
|
|
914
|
+
`env(keyboard-inset-height, ${height}px)`
|
|
915
|
+
);
|
|
916
|
+
} else {
|
|
917
|
+
element.style.setProperty("--keyboard-inset-height", `${height}px`);
|
|
918
|
+
}
|
|
902
919
|
}
|
|
903
920
|
function handleFocusIn(e) {
|
|
904
921
|
if (e.target instanceof HTMLElement && isTextInput(e.target)) {
|
|
@@ -1350,6 +1367,6 @@ var Sheet2 = Object.assign(Sheet, {
|
|
|
1350
1367
|
Backdrop: SheetBackdrop
|
|
1351
1368
|
});
|
|
1352
1369
|
|
|
1353
|
-
export { Sheet2 as Sheet };
|
|
1370
|
+
export { Sheet2 as Sheet, useScrollPosition, useVirtualKeyboard };
|
|
1354
1371
|
//# sourceMappingURL=index.mjs.map
|
|
1355
1372
|
//# sourceMappingURL=index.mjs.map
|