@skalfa/skalfa-app 1.0.0 → 1.0.2
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/.env.example +43 -43
- package/.github/workflows/publish.yml +39 -0
- package/CONTRIBUTING.md +45 -0
- package/LICENSE +21 -0
- package/README.md +91 -28
- package/app/auth/edit/page.tsx +65 -65
- package/app/auth/login/page.tsx +63 -63
- package/app/auth/me/page.tsx +58 -58
- package/app/auth/register/page.tsx +69 -69
- package/app/auth/verify/page.tsx +53 -53
- package/app/dashboard/user/page.tsx +76 -76
- package/app/layout.tsx +37 -37
- package/app/manifest.ts +25 -0
- package/app/page.tsx +13 -13
- package/barrels.json +5 -5
- package/blueprints/starter.blueprint.json +102 -102
- package/bun.lock +916 -0
- package/components/base.components/chip/Chip.component.tsx +39 -39
- package/components/base.components/document/DocumentViewer.component.tsx +163 -163
- package/components/base.components/document/ExportExcel.component.tsx +340 -340
- package/components/base.components/document/ImportExcel.component.tsx +315 -315
- package/components/base.components/document/PrintTable.component.tsx +204 -204
- package/components/base.components/document/RenderPDF.component.tsx +415 -415
- package/components/base.components/input/Checkbox.component.tsx +109 -109
- package/components/base.components/input/Input.component.tsx +332 -332
- package/components/base.components/input/InputCheckbox.component.tsx +174 -174
- package/components/base.components/input/InputCurrency.component.tsx +163 -163
- package/components/base.components/input/InputDate.component.tsx +352 -352
- package/components/base.components/input/InputDatetime.component.tsx +260 -260
- package/components/base.components/input/InputDocument.component.tsx +351 -351
- package/components/base.components/input/InputImage.component.tsx +533 -533
- package/components/base.components/input/InputMap.component.tsx +317 -317
- package/components/base.components/input/InputNumber.component.tsx +192 -192
- package/components/base.components/input/InputOtp.component.tsx +169 -169
- package/components/base.components/input/InputPassword.component.tsx +236 -236
- package/components/base.components/input/InputRadio.component.tsx +175 -175
- package/components/base.components/input/InputTime.component.tsx +275 -275
- package/components/base.components/input/InputValues.component.tsx +68 -68
- package/components/base.components/input/Radio.component.tsx +102 -102
- package/components/base.components/input/Select.component.tsx +541 -541
- package/components/base.components/modal/BottomSheet.component.tsx +245 -245
- package/components/base.components/supervision/FormSupervision.component.tsx +433 -433
- package/components/base.components/supervision/TableSupervision.component.tsx +697 -697
- package/components/base.components/table/ControlBar.component.tsx +497 -497
- package/components/base.components/table/FilterComponent.tsx +518 -518
- package/components/base.components/table/Table.component.tsx +469 -469
- package/components/base.components/typography/TypographyArticle.component.tsx +26 -26
- package/components/base.components/typography/TypographyColumn.component.tsx +20 -20
- package/components/base.components/typography/TypographyContent.component.tsx +20 -20
- package/components/base.components/typography/TypographyTips.component.tsx +20 -20
- package/components/base.components/wrap/Draggable.component.tsx +303 -303
- package/components/base.components/wrap/IDBProvider.tsx +12 -12
- package/components/base.components/wrap/Image.component.tsx +9 -9
- package/components/base.components/wrap/ShortcutProvider.tsx +57 -57
- package/components/base.components/wrap/Swipe.component.tsx +93 -93
- package/components/index.ts +2 -2
- package/contexts/AppProvider.tsx +11 -11
- package/contexts/Auth.context.tsx +64 -64
- package/contexts/Toggle.context.tsx +44 -44
- package/next.config.ts +15 -1
- package/package.json +14 -13
- package/public/204.svg +19 -19
- package/public/500.svg +39 -39
- package/public/icon-192.png +0 -0
- package/public/icon-512.png +0 -0
- package/public/images/logo-fill.png +0 -0
- package/public/images/logo-full-fill.png +0 -0
- package/public/images/logo-full.png +0 -0
- package/public/images/logo.png +0 -0
- package/schema/idb/app.schema.ts +8 -8
- package/src-tauri/Cargo.toml +14 -0
- package/src-tauri/build.rs +3 -0
- package/src-tauri/capabilities/default.json +11 -0
- package/src-tauri/icons/128x128.png +0 -0
- package/src-tauri/icons/128x128@2x.png +0 -0
- package/src-tauri/icons/32x32.png +0 -0
- package/src-tauri/icons/icon.icns +0 -0
- package/src-tauri/icons/icon.ico +0 -0
- package/src-tauri/src/main.rs +7 -0
- package/src-tauri/tauri.conf.json +36 -0
- package/styles/globals.css +231 -231
- package/styles/tailwind.safelist +68 -68
- package/utils/commands/barrels.ts +27 -27
- package/utils/commands/light.ts +21 -21
- package/utils/commands/logger.ts +42 -42
- package/utils/commands/stubs/table-blueprint.stub +12 -12
- package/utils/commands/use-pdf.ts +29 -29
|
@@ -1,246 +1,246 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import { MouseEvent, ReactNode, TouchEvent, useEffect, useRef, useState } from "react";
|
|
4
|
-
import dynamic from 'next/dynamic';
|
|
5
|
-
import { cn, pcn } from "@utils";
|
|
6
|
-
|
|
7
|
-
type CT = "base" | "backdrop" | "footer";
|
|
8
|
-
|
|
9
|
-
export type BottomSheetProps = {
|
|
10
|
-
show : boolean;
|
|
11
|
-
children : ReactNode;
|
|
12
|
-
onClose : () => void;
|
|
13
|
-
size ?: string | number;
|
|
14
|
-
maxSize ?: string | number;
|
|
15
|
-
footer ?: ReactNode;
|
|
16
|
-
|
|
17
|
-
/** Use custom class with: "backdrop::", "footer::". */
|
|
18
|
-
className ?: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
function sizeToPx(value: string | number | undefined): number {
|
|
22
|
-
if (typeof window === "undefined") return 0;
|
|
23
|
-
if (value === undefined || value === null) return 0;
|
|
24
|
-
|
|
25
|
-
if (typeof value === "number") return value;
|
|
26
|
-
|
|
27
|
-
const v = value.trim();
|
|
28
|
-
|
|
29
|
-
if (v.endsWith("vh")) {
|
|
30
|
-
const n = parseFloat(v.replace("vh", ""));
|
|
31
|
-
return (n / 100) * window.innerHeight;
|
|
32
|
-
}
|
|
33
|
-
if (v.endsWith("px")) {
|
|
34
|
-
return parseFloat(v.replace("px", ""));
|
|
35
|
-
}
|
|
36
|
-
return parseFloat(v) || 0;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const BottomSheet = ({
|
|
40
|
-
show,
|
|
41
|
-
children,
|
|
42
|
-
onClose,
|
|
43
|
-
size = 500,
|
|
44
|
-
maxSize,
|
|
45
|
-
footer,
|
|
46
|
-
className = "",
|
|
47
|
-
}: BottomSheetProps) => {
|
|
48
|
-
const scrollRef = useRef<HTMLDivElement | null>(null);
|
|
49
|
-
const sheetRef = useRef<HTMLDivElement | null>(null);
|
|
50
|
-
|
|
51
|
-
const startY = useRef(0);
|
|
52
|
-
const lastY = useRef(0);
|
|
53
|
-
const dragging = useRef(false);
|
|
54
|
-
|
|
55
|
-
const [offset, setOffset] = useState(0);
|
|
56
|
-
const [isExpanded, setIsExpanded] = useState(false);
|
|
57
|
-
const [scrollLocked, setScrollLocked] = useState(false);
|
|
58
|
-
const [contentScrollable, setContentScrollable] = useState(false);
|
|
59
|
-
|
|
60
|
-
const realMaxSize = maxSize ?? size;
|
|
61
|
-
|
|
62
|
-
const clamp = (v: number) => {
|
|
63
|
-
const max = window.innerHeight;
|
|
64
|
-
return Math.max(-200, Math.min(v, max));
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const animateTo = (target: number, onFinish?: () => void) => {
|
|
68
|
-
lastY.current = target;
|
|
69
|
-
setOffset(clamp(target));
|
|
70
|
-
onFinish?.();
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
useEffect(() => {
|
|
74
|
-
if (show) {
|
|
75
|
-
lastY.current = 0;
|
|
76
|
-
setOffset(0);
|
|
77
|
-
setIsExpanded(false);
|
|
78
|
-
} else {
|
|
79
|
-
const t = setTimeout(() => {
|
|
80
|
-
lastY.current = 0;
|
|
81
|
-
setOffset(0);
|
|
82
|
-
setIsExpanded(false);
|
|
83
|
-
}, 250);
|
|
84
|
-
return () => clearTimeout(t);
|
|
85
|
-
}
|
|
86
|
-
}, [show]);
|
|
87
|
-
|
|
88
|
-
const onStart = (clientY: number) => {
|
|
89
|
-
const sc = scrollRef.current;
|
|
90
|
-
|
|
91
|
-
if (sc && sc.scrollTop < 0) {
|
|
92
|
-
setScrollLocked(true);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
setScrollLocked(false);
|
|
97
|
-
|
|
98
|
-
dragging.current = true;
|
|
99
|
-
startY.current = clientY;
|
|
100
|
-
lastY.current = offset;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
const onMove = (clientY: number) => {
|
|
104
|
-
if (scrollLocked) return;
|
|
105
|
-
if (!dragging.current) return;
|
|
106
|
-
|
|
107
|
-
const diff = clientY - startY.current;
|
|
108
|
-
setOffset(clamp(lastY.current + diff));
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const onEnd = () => {
|
|
112
|
-
if (scrollLocked) {
|
|
113
|
-
setScrollLocked(false);
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (!dragging.current) return;
|
|
118
|
-
dragging.current = false;
|
|
119
|
-
|
|
120
|
-
const current = offset;
|
|
121
|
-
|
|
122
|
-
const thresholdDown = 120;
|
|
123
|
-
const thresholdUp = -40;
|
|
124
|
-
|
|
125
|
-
if (!isExpanded && current < thresholdUp && maxSize !== undefined) {
|
|
126
|
-
setIsExpanded(true);
|
|
127
|
-
animateTo(0);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (isExpanded && current > thresholdDown) {
|
|
132
|
-
setIsExpanded(false);
|
|
133
|
-
animateTo(0);
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (!isExpanded && current > thresholdDown) {
|
|
138
|
-
animateTo(window.innerHeight, () => {
|
|
139
|
-
onClose();
|
|
140
|
-
lastY.current = 0;
|
|
141
|
-
setOffset(0);
|
|
142
|
-
});
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
animateTo(0);
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const collapsedPx = sizeToPx(size);
|
|
150
|
-
const expandedPx = sizeToPx(realMaxSize);
|
|
151
|
-
|
|
152
|
-
const topPx = isExpanded ? window.innerHeight - expandedPx : window.innerHeight - collapsedPx;
|
|
153
|
-
|
|
154
|
-
const bindTouch = {
|
|
155
|
-
onTouchStart : (e: TouchEvent) => onStart(e.touches[0].clientY),
|
|
156
|
-
onTouchMove : (e: TouchEvent) => onMove(e.touches[0].clientY),
|
|
157
|
-
onTouchEnd : () => onEnd(),
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
const bindMouse = {
|
|
161
|
-
onMouseDown : (e: MouseEvent) => onStart(e.clientY),
|
|
162
|
-
onMouseMove : (e: MouseEvent) => dragging.current && onMove(e.clientY),
|
|
163
|
-
onMouseUp : () => onEnd(),
|
|
164
|
-
onMouseLeave : () => onEnd(),
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
useEffect(() => {
|
|
168
|
-
const sc = scrollRef.current;
|
|
169
|
-
if (!sc) return;
|
|
170
|
-
|
|
171
|
-
const canScroll = sc.scrollHeight > sc.clientHeight;
|
|
172
|
-
setContentScrollable(canScroll);
|
|
173
|
-
}, [show, size, maxSize]);
|
|
174
|
-
|
|
175
|
-
useEffect(() => {
|
|
176
|
-
if (show) {
|
|
177
|
-
history.pushState({ bottomsheet: true }, "");
|
|
178
|
-
}
|
|
179
|
-
}, [show]);
|
|
180
|
-
|
|
181
|
-
useEffect(() => {
|
|
182
|
-
const onPopState = (event: PopStateEvent) => {
|
|
183
|
-
if (show) {
|
|
184
|
-
event.preventDefault();
|
|
185
|
-
|
|
186
|
-
onClose();
|
|
187
|
-
history.pushState({}, "");
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
window.addEventListener("popstate", onPopState);
|
|
192
|
-
return () => window.removeEventListener("popstate", onPopState);
|
|
193
|
-
}, [show, onClose]);
|
|
194
|
-
|
|
195
|
-
return (
|
|
196
|
-
<>
|
|
197
|
-
<div
|
|
198
|
-
className={cn(
|
|
199
|
-
"modal-backdrop",
|
|
200
|
-
!show && "translate-y-full",
|
|
201
|
-
pcn<CT>(className, "backdrop"),
|
|
202
|
-
)}
|
|
203
|
-
onClick={onClose}
|
|
204
|
-
/>
|
|
205
|
-
|
|
206
|
-
<div
|
|
207
|
-
ref={sheetRef}
|
|
208
|
-
className="fixed left-0 right-0 w-full h-full z-50 transition-[top] duration-75"
|
|
209
|
-
style={{
|
|
210
|
-
top: show ? `${topPx}px` : "150vh",
|
|
211
|
-
transform: `translateY(${offset}px)`,
|
|
212
|
-
touchAction: "none",
|
|
213
|
-
}}
|
|
214
|
-
{...bindTouch}
|
|
215
|
-
{...bindMouse}
|
|
216
|
-
>
|
|
217
|
-
<div className="w-full h-full bg-white rounded-t shadow-xl overflow-hidden">
|
|
218
|
-
<div className="py-2 flex justify-center cursor-grab">
|
|
219
|
-
<div className="w-14 h-[2.5px] bg-slate-200 rounded-full" />
|
|
220
|
-
</div>
|
|
221
|
-
|
|
222
|
-
<div
|
|
223
|
-
ref={scrollRef}
|
|
224
|
-
className="overflow-y-auto"
|
|
225
|
-
style={{
|
|
226
|
-
height: isExpanded ? realMaxSize : size,
|
|
227
|
-
touchAction: contentScrollable ? "auto" : "none",
|
|
228
|
-
overscrollBehaviorY: "contain",
|
|
229
|
-
}}
|
|
230
|
-
>
|
|
231
|
-
{children}
|
|
232
|
-
</div>
|
|
233
|
-
</div>
|
|
234
|
-
</div>
|
|
235
|
-
|
|
236
|
-
{show && footer && (
|
|
237
|
-
<div className="fixed bottom-0 left-0 right-0 z-50">
|
|
238
|
-
{footer}
|
|
239
|
-
</div>
|
|
240
|
-
)}
|
|
241
|
-
</>
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { MouseEvent, ReactNode, TouchEvent, useEffect, useRef, useState } from "react";
|
|
4
|
+
import dynamic from 'next/dynamic';
|
|
5
|
+
import { cn, pcn } from "@utils";
|
|
6
|
+
|
|
7
|
+
type CT = "base" | "backdrop" | "footer";
|
|
8
|
+
|
|
9
|
+
export type BottomSheetProps = {
|
|
10
|
+
show : boolean;
|
|
11
|
+
children : ReactNode;
|
|
12
|
+
onClose : () => void;
|
|
13
|
+
size ?: string | number;
|
|
14
|
+
maxSize ?: string | number;
|
|
15
|
+
footer ?: ReactNode;
|
|
16
|
+
|
|
17
|
+
/** Use custom class with: "backdrop::", "footer::". */
|
|
18
|
+
className ?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function sizeToPx(value: string | number | undefined): number {
|
|
22
|
+
if (typeof window === "undefined") return 0;
|
|
23
|
+
if (value === undefined || value === null) return 0;
|
|
24
|
+
|
|
25
|
+
if (typeof value === "number") return value;
|
|
26
|
+
|
|
27
|
+
const v = value.trim();
|
|
28
|
+
|
|
29
|
+
if (v.endsWith("vh")) {
|
|
30
|
+
const n = parseFloat(v.replace("vh", ""));
|
|
31
|
+
return (n / 100) * window.innerHeight;
|
|
32
|
+
}
|
|
33
|
+
if (v.endsWith("px")) {
|
|
34
|
+
return parseFloat(v.replace("px", ""));
|
|
35
|
+
}
|
|
36
|
+
return parseFloat(v) || 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const BottomSheet = ({
|
|
40
|
+
show,
|
|
41
|
+
children,
|
|
42
|
+
onClose,
|
|
43
|
+
size = 500,
|
|
44
|
+
maxSize,
|
|
45
|
+
footer,
|
|
46
|
+
className = "",
|
|
47
|
+
}: BottomSheetProps) => {
|
|
48
|
+
const scrollRef = useRef<HTMLDivElement | null>(null);
|
|
49
|
+
const sheetRef = useRef<HTMLDivElement | null>(null);
|
|
50
|
+
|
|
51
|
+
const startY = useRef(0);
|
|
52
|
+
const lastY = useRef(0);
|
|
53
|
+
const dragging = useRef(false);
|
|
54
|
+
|
|
55
|
+
const [offset, setOffset] = useState(0);
|
|
56
|
+
const [isExpanded, setIsExpanded] = useState(false);
|
|
57
|
+
const [scrollLocked, setScrollLocked] = useState(false);
|
|
58
|
+
const [contentScrollable, setContentScrollable] = useState(false);
|
|
59
|
+
|
|
60
|
+
const realMaxSize = maxSize ?? size;
|
|
61
|
+
|
|
62
|
+
const clamp = (v: number) => {
|
|
63
|
+
const max = window.innerHeight;
|
|
64
|
+
return Math.max(-200, Math.min(v, max));
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const animateTo = (target: number, onFinish?: () => void) => {
|
|
68
|
+
lastY.current = target;
|
|
69
|
+
setOffset(clamp(target));
|
|
70
|
+
onFinish?.();
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (show) {
|
|
75
|
+
lastY.current = 0;
|
|
76
|
+
setOffset(0);
|
|
77
|
+
setIsExpanded(false);
|
|
78
|
+
} else {
|
|
79
|
+
const t = setTimeout(() => {
|
|
80
|
+
lastY.current = 0;
|
|
81
|
+
setOffset(0);
|
|
82
|
+
setIsExpanded(false);
|
|
83
|
+
}, 250);
|
|
84
|
+
return () => clearTimeout(t);
|
|
85
|
+
}
|
|
86
|
+
}, [show]);
|
|
87
|
+
|
|
88
|
+
const onStart = (clientY: number) => {
|
|
89
|
+
const sc = scrollRef.current;
|
|
90
|
+
|
|
91
|
+
if (sc && sc.scrollTop < 0) {
|
|
92
|
+
setScrollLocked(true);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
setScrollLocked(false);
|
|
97
|
+
|
|
98
|
+
dragging.current = true;
|
|
99
|
+
startY.current = clientY;
|
|
100
|
+
lastY.current = offset;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const onMove = (clientY: number) => {
|
|
104
|
+
if (scrollLocked) return;
|
|
105
|
+
if (!dragging.current) return;
|
|
106
|
+
|
|
107
|
+
const diff = clientY - startY.current;
|
|
108
|
+
setOffset(clamp(lastY.current + diff));
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const onEnd = () => {
|
|
112
|
+
if (scrollLocked) {
|
|
113
|
+
setScrollLocked(false);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (!dragging.current) return;
|
|
118
|
+
dragging.current = false;
|
|
119
|
+
|
|
120
|
+
const current = offset;
|
|
121
|
+
|
|
122
|
+
const thresholdDown = 120;
|
|
123
|
+
const thresholdUp = -40;
|
|
124
|
+
|
|
125
|
+
if (!isExpanded && current < thresholdUp && maxSize !== undefined) {
|
|
126
|
+
setIsExpanded(true);
|
|
127
|
+
animateTo(0);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (isExpanded && current > thresholdDown) {
|
|
132
|
+
setIsExpanded(false);
|
|
133
|
+
animateTo(0);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (!isExpanded && current > thresholdDown) {
|
|
138
|
+
animateTo(window.innerHeight, () => {
|
|
139
|
+
onClose();
|
|
140
|
+
lastY.current = 0;
|
|
141
|
+
setOffset(0);
|
|
142
|
+
});
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
animateTo(0);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const collapsedPx = sizeToPx(size);
|
|
150
|
+
const expandedPx = sizeToPx(realMaxSize);
|
|
151
|
+
|
|
152
|
+
const topPx = isExpanded ? window.innerHeight - expandedPx : window.innerHeight - collapsedPx;
|
|
153
|
+
|
|
154
|
+
const bindTouch = {
|
|
155
|
+
onTouchStart : (e: TouchEvent) => onStart(e.touches[0].clientY),
|
|
156
|
+
onTouchMove : (e: TouchEvent) => onMove(e.touches[0].clientY),
|
|
157
|
+
onTouchEnd : () => onEnd(),
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const bindMouse = {
|
|
161
|
+
onMouseDown : (e: MouseEvent) => onStart(e.clientY),
|
|
162
|
+
onMouseMove : (e: MouseEvent) => dragging.current && onMove(e.clientY),
|
|
163
|
+
onMouseUp : () => onEnd(),
|
|
164
|
+
onMouseLeave : () => onEnd(),
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
useEffect(() => {
|
|
168
|
+
const sc = scrollRef.current;
|
|
169
|
+
if (!sc) return;
|
|
170
|
+
|
|
171
|
+
const canScroll = sc.scrollHeight > sc.clientHeight;
|
|
172
|
+
setContentScrollable(canScroll);
|
|
173
|
+
}, [show, size, maxSize]);
|
|
174
|
+
|
|
175
|
+
useEffect(() => {
|
|
176
|
+
if (show) {
|
|
177
|
+
history.pushState({ bottomsheet: true }, "");
|
|
178
|
+
}
|
|
179
|
+
}, [show]);
|
|
180
|
+
|
|
181
|
+
useEffect(() => {
|
|
182
|
+
const onPopState = (event: PopStateEvent) => {
|
|
183
|
+
if (show) {
|
|
184
|
+
event.preventDefault();
|
|
185
|
+
|
|
186
|
+
onClose();
|
|
187
|
+
history.pushState({}, "");
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
window.addEventListener("popstate", onPopState);
|
|
192
|
+
return () => window.removeEventListener("popstate", onPopState);
|
|
193
|
+
}, [show, onClose]);
|
|
194
|
+
|
|
195
|
+
return (
|
|
196
|
+
<>
|
|
197
|
+
<div
|
|
198
|
+
className={cn(
|
|
199
|
+
"modal-backdrop",
|
|
200
|
+
!show && "translate-y-full",
|
|
201
|
+
pcn<CT>(className, "backdrop"),
|
|
202
|
+
)}
|
|
203
|
+
onClick={onClose}
|
|
204
|
+
/>
|
|
205
|
+
|
|
206
|
+
<div
|
|
207
|
+
ref={sheetRef}
|
|
208
|
+
className="fixed left-0 right-0 w-full h-full z-50 transition-[top] duration-75"
|
|
209
|
+
style={{
|
|
210
|
+
top: show ? `${topPx}px` : "150vh",
|
|
211
|
+
transform: `translateY(${offset}px)`,
|
|
212
|
+
touchAction: "none",
|
|
213
|
+
}}
|
|
214
|
+
{...bindTouch}
|
|
215
|
+
{...bindMouse}
|
|
216
|
+
>
|
|
217
|
+
<div className="w-full h-full bg-white rounded-t shadow-xl overflow-hidden">
|
|
218
|
+
<div className="py-2 flex justify-center cursor-grab">
|
|
219
|
+
<div className="w-14 h-[2.5px] bg-slate-200 rounded-full" />
|
|
220
|
+
</div>
|
|
221
|
+
|
|
222
|
+
<div
|
|
223
|
+
ref={scrollRef}
|
|
224
|
+
className="overflow-y-auto"
|
|
225
|
+
style={{
|
|
226
|
+
height: isExpanded ? realMaxSize : size,
|
|
227
|
+
touchAction: contentScrollable ? "auto" : "none",
|
|
228
|
+
overscrollBehaviorY: "contain",
|
|
229
|
+
}}
|
|
230
|
+
>
|
|
231
|
+
{children}
|
|
232
|
+
</div>
|
|
233
|
+
</div>
|
|
234
|
+
</div>
|
|
235
|
+
|
|
236
|
+
{show && footer && (
|
|
237
|
+
<div className="fixed bottom-0 left-0 right-0 z-50">
|
|
238
|
+
{footer}
|
|
239
|
+
</div>
|
|
240
|
+
)}
|
|
241
|
+
</>
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
|
|
246
246
|
export const BottomSheetComponent = dynamic(() => Promise.resolve(BottomSheet), { ssr: false })
|