react-modal-sheet 3.3.0 → 3.4.0
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/dist/index.js +207 -110
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +203 -106
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -4
- package/src/hooks.tsx +85 -16
- package/src/sheet.tsx +5 -1
- package/src/use-prevent-scroll.ts +80 -21
- package/src/utils.ts +41 -42
package/src/utils.ts
CHANGED
|
@@ -15,48 +15,6 @@ export function getClosest(nums: number[], goal: number) {
|
|
|
15
15
|
return closest;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export function applyRootStyles(rootId: string) {
|
|
19
|
-
const body = document.querySelector('body') as HTMLBodyElement;
|
|
20
|
-
const root = document.querySelector(`#${rootId}`) as HTMLDivElement;
|
|
21
|
-
|
|
22
|
-
if (root) {
|
|
23
|
-
const p = 24;
|
|
24
|
-
const h = window.innerHeight;
|
|
25
|
-
const s = (h - p) / h;
|
|
26
|
-
body.style.backgroundColor = '#000';
|
|
27
|
-
root.style.overflow = 'hidden';
|
|
28
|
-
root.style.willChange = 'transform';
|
|
29
|
-
root.style.transition =
|
|
30
|
-
'transform 200ms ease-in-out, border-radius 200ms linear';
|
|
31
|
-
root.style.transform = `translateY(calc(env(safe-area-inset-top) + ${p / 2}px)) scale(${s})`; // prettier-ignore
|
|
32
|
-
root.style.borderTopRightRadius = '10px';
|
|
33
|
-
root.style.borderTopLeftRadius = '10px';
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export function cleanupRootStyles(rootId: string) {
|
|
38
|
-
const body = document.querySelector('body') as HTMLBodyElement;
|
|
39
|
-
const root = document.getElementById(rootId) as HTMLDivElement;
|
|
40
|
-
|
|
41
|
-
function onTransitionEnd() {
|
|
42
|
-
root.style.removeProperty('overflow');
|
|
43
|
-
root.style.removeProperty('will-change');
|
|
44
|
-
root.style.removeProperty('transition');
|
|
45
|
-
body.style.removeProperty('background-color');
|
|
46
|
-
root.removeEventListener('transitionend', onTransitionEnd);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (root) {
|
|
50
|
-
// Start animating back
|
|
51
|
-
root.style.removeProperty('border-top-right-radius');
|
|
52
|
-
root.style.removeProperty('border-top-left-radius');
|
|
53
|
-
root.style.removeProperty('transform');
|
|
54
|
-
|
|
55
|
-
// Remove temp properties after animation is finished
|
|
56
|
-
root.addEventListener('transitionend', onTransitionEnd);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
18
|
export function inDescendingOrder(arr: number[]) {
|
|
61
19
|
for (let i = 0; i < arr.length; i++) {
|
|
62
20
|
if (arr[i + 1] > arr[i]) return false;
|
|
@@ -101,3 +59,44 @@ export function isTouchDevice() {
|
|
|
101
59
|
if (typeof window === 'undefined') return false;
|
|
102
60
|
return 'ontouchstart' in window || navigator.maxTouchPoints > 0;
|
|
103
61
|
}
|
|
62
|
+
|
|
63
|
+
function testPlatform(re: RegExp) {
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
|
65
|
+
return typeof window !== 'undefined' && window.navigator != null
|
|
66
|
+
? re.test(
|
|
67
|
+
// @ts-expect-error
|
|
68
|
+
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
69
|
+
window.navigator['userAgentData']?.platform || window.navigator.platform
|
|
70
|
+
)
|
|
71
|
+
: false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function cached(fn: () => boolean) {
|
|
75
|
+
let res: boolean | null = null;
|
|
76
|
+
return () => {
|
|
77
|
+
if (res == null) {
|
|
78
|
+
res = fn();
|
|
79
|
+
}
|
|
80
|
+
return res;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const isMac = cached(function () {
|
|
85
|
+
return testPlatform(/^Mac/i);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const isIPhone = cached(function () {
|
|
89
|
+
return testPlatform(/^iPhone/i);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const isIPad = cached(function () {
|
|
93
|
+
return (
|
|
94
|
+
testPlatform(/^iPad/i) ||
|
|
95
|
+
// iPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support.
|
|
96
|
+
(isMac() && navigator.maxTouchPoints > 1)
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
export const isIOS = cached(function () {
|
|
101
|
+
return isIPhone() || isIPad();
|
|
102
|
+
});
|