@skalfa/skalfa-app 1.0.3 → 1.0.5
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 +8 -16
- package/app/auth/edit/page.tsx +1 -1
- package/app/auth/login/page.tsx +1 -1
- package/app/auth/me/page.tsx +1 -1
- package/app/auth/register/page.tsx +1 -1
- package/app/auth/verify/page.tsx +1 -1
- package/app/dashboard/layout.tsx +2 -2
- package/app/dashboard/page.tsx +1 -1
- package/app/index.ts +1 -0
- package/app/layout.tsx +2 -4
- package/app/page.tsx +2 -2
- package/bun.lock +7 -2
- package/components/index.ts +1 -3
- package/package.json +8 -6
- package/styles/components.css +1392 -0
- package/styles/globals.css +40 -175
- package/styles/utilities.css +37 -0
- package/tsconfig.json +4 -2
- package/utils/commands/skalfa.ts +1 -1
- package/components/base.components/accordion/Accordion.component.tsx +0 -82
- package/components/base.components/breadcrumb/Breadcrumb.component.tsx +0 -80
- package/components/base.components/button/Button.component.tsx +0 -91
- package/components/base.components/button/IconButton.component.tsx +0 -88
- package/components/base.components/button/button.decorate.ts +0 -82
- package/components/base.components/card/AlertCard.component.tsx +0 -69
- package/components/base.components/card/Card.component.tsx +0 -25
- package/components/base.components/card/DashboardCard.component.tsx +0 -44
- package/components/base.components/card/GalleryCard.component.tsx +0 -50
- package/components/base.components/card/ProductCard.component.tsx +0 -65
- package/components/base.components/card/ProfileCard.component.tsx +0 -71
- package/components/base.components/carousel/Carousel.component.tsx +0 -113
- package/components/base.components/chip/Chip.component.tsx +0 -39
- package/components/base.components/document/DocumentViewer.component.tsx +0 -164
- package/components/base.components/document/ExportExcel.component.tsx +0 -340
- package/components/base.components/document/ImportExcel.component.tsx +0 -315
- package/components/base.components/document/PrintTable.component.tsx +0 -204
- package/components/base.components/document/RenderPDF.component.tsx +0 -416
- package/components/base.components/index.ts +0 -85
- package/components/base.components/input/Checkbox.component.tsx +0 -109
- package/components/base.components/input/Input.component.tsx +0 -332
- package/components/base.components/input/InputCheckbox.component.tsx +0 -174
- package/components/base.components/input/InputCurrency.component.tsx +0 -163
- package/components/base.components/input/InputDate.component.tsx +0 -352
- package/components/base.components/input/InputDatetime.component.tsx +0 -260
- package/components/base.components/input/InputDocument.component.tsx +0 -352
- package/components/base.components/input/InputImage.component.tsx +0 -533
- package/components/base.components/input/InputMap.component.tsx +0 -318
- package/components/base.components/input/InputNumber.component.tsx +0 -192
- package/components/base.components/input/InputOtp.component.tsx +0 -169
- package/components/base.components/input/InputPassword.component.tsx +0 -236
- package/components/base.components/input/InputRadio.component.tsx +0 -175
- package/components/base.components/input/InputTime.component.tsx +0 -276
- package/components/base.components/input/InputValues.component.tsx +0 -68
- package/components/base.components/input/Radio.component.tsx +0 -102
- package/components/base.components/input/Select.component.tsx +0 -541
- package/components/base.components/modal/BottomSheet.component.tsx +0 -246
- package/components/base.components/modal/FloatingPage.component.tsx +0 -104
- package/components/base.components/modal/Modal.component.tsx +0 -96
- package/components/base.components/modal/ModalConfirm.component.tsx +0 -218
- package/components/base.components/modal/Toast.component.tsx +0 -126
- package/components/base.components/nav/Bottombar.component.tsx +0 -116
- package/components/base.components/nav/Footer.component.tsx +0 -144
- package/components/base.components/nav/Headbar.component.tsx +0 -104
- package/components/base.components/nav/Navbar.component.tsx +0 -100
- package/components/base.components/nav/Sidebar.component.tsx +0 -301
- package/components/base.components/nav/Tabbar.component.tsx +0 -60
- package/components/base.components/nav/Wizard.component.tsx +0 -73
- package/components/base.components/supervision/FormSupervision.component.tsx +0 -434
- package/components/base.components/supervision/TableSupervision.component.tsx +0 -697
- package/components/base.components/table/ControlBar.component.tsx +0 -497
- package/components/base.components/table/FilterComponent.tsx +0 -518
- package/components/base.components/table/Pagination.component.tsx +0 -159
- package/components/base.components/table/Table.component.tsx +0 -469
- package/components/base.components/typography/TypographyArticle.component.tsx +0 -26
- package/components/base.components/typography/TypographyColumn.component.tsx +0 -20
- package/components/base.components/typography/TypographyContent.component.tsx +0 -20
- package/components/base.components/typography/TypographyTips.component.tsx +0 -20
- package/components/base.components/wrap/Draggable.component.tsx +0 -303
- package/components/base.components/wrap/IDBProvider.tsx +0 -12
- package/components/base.components/wrap/Image.component.tsx +0 -10
- package/components/base.components/wrap/OutsideClick.component.tsx +0 -48
- package/components/base.components/wrap/ScrollContainer.component.tsx +0 -104
- package/components/base.components/wrap/ShortcutProvider.tsx +0 -57
- package/components/base.components/wrap/Swipe.component.tsx +0 -93
- package/components/construct.components/example.tsx +0 -1
- package/components/construct.components/index.ts +0 -5
- package/components/structure.components/example.tsx +0 -1
- package/components/structure.components/index.ts +0 -5
- package/schema/idb/app.schema.ts +0 -9
- package/schema/index.ts +0 -5
|
@@ -1,246 +0,0 @@
|
|
|
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
|
-
export const BottomSheetComponent = dynamic(() => Promise.resolve(BottomSheet), { ssr: false })
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import { ReactNode, useEffect } from "react";
|
|
4
|
-
import { faTimes } from "@fortawesome/free-solid-svg-icons";
|
|
5
|
-
import { IconButtonComponent } from "@components";
|
|
6
|
-
import { cn, pcn, shortcut } from "@utils";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
type CT = "base" | "backdrop" | "header" | "footer";
|
|
11
|
-
|
|
12
|
-
export interface FloatingPageProps {
|
|
13
|
-
show : boolean;
|
|
14
|
-
onClose : () => void;
|
|
15
|
-
title ?: string | ReactNode;
|
|
16
|
-
children ?: any;
|
|
17
|
-
tip ?: string | ReactNode;
|
|
18
|
-
footer ?: string | ReactNode;
|
|
19
|
-
|
|
20
|
-
/** Use custom class with: "backdrop::", "header::", "footer::". */
|
|
21
|
-
className ?: string;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export function FloatingPageComponent({
|
|
27
|
-
show,
|
|
28
|
-
onClose,
|
|
29
|
-
title,
|
|
30
|
-
children,
|
|
31
|
-
tip,
|
|
32
|
-
footer,
|
|
33
|
-
className = "",
|
|
34
|
-
}: FloatingPageProps) {
|
|
35
|
-
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
if (show) {
|
|
38
|
-
document.getElementsByTagName("body")[0].style.overflow = "hidden";
|
|
39
|
-
|
|
40
|
-
shortcut.register("escape", () => {
|
|
41
|
-
onClose?.()
|
|
42
|
-
}, "Kembali")
|
|
43
|
-
|
|
44
|
-
} else {
|
|
45
|
-
document.getElementsByTagName("body")[0].style.removeProperty("overflow");
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return () => {
|
|
49
|
-
shortcut.unregister("escape")
|
|
50
|
-
}
|
|
51
|
-
}, [show]);
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<>
|
|
55
|
-
<div
|
|
56
|
-
className={cn(
|
|
57
|
-
"modal-backdrop",
|
|
58
|
-
!show && "opacity-0 scale-0 -translate-y-full",
|
|
59
|
-
pcn<CT>(className, "backdrop"),
|
|
60
|
-
)}
|
|
61
|
-
onClick={() => onClose()}
|
|
62
|
-
></div>
|
|
63
|
-
|
|
64
|
-
<div
|
|
65
|
-
className={cn(
|
|
66
|
-
"floating-page",
|
|
67
|
-
"w-[100vw] md:w-[50vw] max-w-[700px]",
|
|
68
|
-
!show && "top-[200vh] md:top-0 md:-right-[200vw]",
|
|
69
|
-
pcn<CT>(className, "base"),
|
|
70
|
-
)}
|
|
71
|
-
>
|
|
72
|
-
<div className={cn("modal-header", pcn<CT>(className, "header"))}>
|
|
73
|
-
{title && (
|
|
74
|
-
<div>
|
|
75
|
-
<h6 className="text-lg font-semibold text-foreground">{title}</h6>
|
|
76
|
-
<p className="text-sm text-light-foreground leading-4 mt-1">{tip}</p>
|
|
77
|
-
</div>
|
|
78
|
-
)}
|
|
79
|
-
|
|
80
|
-
<IconButtonComponent
|
|
81
|
-
icon={faTimes}
|
|
82
|
-
variant="simple"
|
|
83
|
-
paint="danger"
|
|
84
|
-
onClick={() => onClose()}
|
|
85
|
-
/>
|
|
86
|
-
</div>
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
{show && children}
|
|
90
|
-
|
|
91
|
-
{footer && (
|
|
92
|
-
<div
|
|
93
|
-
className={cn(
|
|
94
|
-
"modal-footer absolute bottom-0 w-full",
|
|
95
|
-
pcn<CT>(className, "footer"),
|
|
96
|
-
)}
|
|
97
|
-
>
|
|
98
|
-
{show && footer}
|
|
99
|
-
</div>
|
|
100
|
-
)}
|
|
101
|
-
</div>
|
|
102
|
-
</>
|
|
103
|
-
);
|
|
104
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import { ReactNode, useEffect } from "react";
|
|
4
|
-
import { faTimes } from "@fortawesome/free-solid-svg-icons";
|
|
5
|
-
import { cn, pcn, shortcut } from "@utils";
|
|
6
|
-
import { IconButtonComponent } from "@components";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
type CT = "base" | "backdrop" | "header" | "footer";
|
|
11
|
-
|
|
12
|
-
export interface ModalProps {
|
|
13
|
-
show : boolean;
|
|
14
|
-
onClose : () => void;
|
|
15
|
-
title ?: string | ReactNode;
|
|
16
|
-
children ?: any;
|
|
17
|
-
tip ?: string | ReactNode;
|
|
18
|
-
footer ?: string | ReactNode;
|
|
19
|
-
|
|
20
|
-
/** Use custom class with: "backdrop::", "header::", "footer::". */
|
|
21
|
-
className ?: string;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export function ModalComponent({
|
|
27
|
-
show,
|
|
28
|
-
onClose,
|
|
29
|
-
title,
|
|
30
|
-
children,
|
|
31
|
-
tip,
|
|
32
|
-
footer,
|
|
33
|
-
className = "",
|
|
34
|
-
}: ModalProps) {
|
|
35
|
-
useEffect(() => {
|
|
36
|
-
if (show) {
|
|
37
|
-
document.getElementsByTagName("body")[0].style.overflow = "hidden";
|
|
38
|
-
|
|
39
|
-
shortcut.register("escape", () => {
|
|
40
|
-
onClose?.()
|
|
41
|
-
}, "Kembali")
|
|
42
|
-
} else {
|
|
43
|
-
document.getElementsByTagName("body")[0].style.removeProperty("overflow");
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return () => {
|
|
47
|
-
shortcut.unregister("escape")
|
|
48
|
-
}
|
|
49
|
-
}, [show]);
|
|
50
|
-
|
|
51
|
-
return (
|
|
52
|
-
<>
|
|
53
|
-
<div
|
|
54
|
-
className={cn(
|
|
55
|
-
"modal-backdrop",
|
|
56
|
-
!show && "opacity-0 scale-0 -translate-y-full",
|
|
57
|
-
pcn<CT>(className, "backdrop"),
|
|
58
|
-
)}
|
|
59
|
-
onClick={() => onClose()}
|
|
60
|
-
></div>
|
|
61
|
-
|
|
62
|
-
<div
|
|
63
|
-
className={cn(
|
|
64
|
-
"modal",
|
|
65
|
-
"w-[calc(100vw-2rem)] md:w-[50vw] max-w-[500px]",
|
|
66
|
-
!show && "-translate-y-full opacity-0 scale-y-0",
|
|
67
|
-
pcn<CT>(className, "base"),
|
|
68
|
-
)}
|
|
69
|
-
>
|
|
70
|
-
{title && (
|
|
71
|
-
<div className={cn("modal-header", pcn<CT>(className, "header"))}>
|
|
72
|
-
<div>
|
|
73
|
-
<h6 className="text-lg font-semibold text-foreground">{title}</h6>
|
|
74
|
-
<p className="text-sm text-light-foreground leading-4 mt-1">{tip}</p>
|
|
75
|
-
</div>
|
|
76
|
-
|
|
77
|
-
<IconButtonComponent
|
|
78
|
-
icon={faTimes}
|
|
79
|
-
variant="simple"
|
|
80
|
-
paint="danger"
|
|
81
|
-
onClick={() => onClose()}
|
|
82
|
-
/>
|
|
83
|
-
</div>
|
|
84
|
-
)}
|
|
85
|
-
|
|
86
|
-
{show && children}
|
|
87
|
-
|
|
88
|
-
{footer && (
|
|
89
|
-
<div className={cn("modal-footer", pcn<CT>(className, "footer"))}>
|
|
90
|
-
{show && footer}
|
|
91
|
-
</div>
|
|
92
|
-
)}
|
|
93
|
-
</div>
|
|
94
|
-
</>
|
|
95
|
-
);
|
|
96
|
-
}
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import { ReactNode, useEffect, useMemo, useState } from "react";
|
|
4
|
-
import { faQuestion } from "@fortawesome/free-solid-svg-icons";
|
|
5
|
-
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
6
|
-
import { api, ApiType, cn, pcn, registry, shortcut, useResponsive } from "@utils";
|
|
7
|
-
import { ToastComponent, ButtonComponent, ButtonProps, BottomSheetComponent } from "@components";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
type CT = "base" | "backdrop" | "header" | "footer";
|
|
12
|
-
|
|
13
|
-
type SubmitIDB = { idb: { store: string , id: string | number}}
|
|
14
|
-
|
|
15
|
-
export interface ModalConfirmProps {
|
|
16
|
-
show : boolean;
|
|
17
|
-
onClose : () => void;
|
|
18
|
-
title ?: string | ReactNode;
|
|
19
|
-
children ?: any;
|
|
20
|
-
icon ?: any;
|
|
21
|
-
footer ?: string | ReactNode;
|
|
22
|
-
submitControl ?: ButtonProps & {
|
|
23
|
-
onSubmit ?: ApiType | SubmitIDB | (() => void);
|
|
24
|
-
onSuccess ?: () => void;
|
|
25
|
-
onError ?: () => void;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
/** Use custom class with: "backdrop::", "header::", "footer::". */
|
|
29
|
-
className ?: string;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export function ModalConfirmComponent({
|
|
35
|
-
show,
|
|
36
|
-
title,
|
|
37
|
-
children,
|
|
38
|
-
icon,
|
|
39
|
-
footer,
|
|
40
|
-
|
|
41
|
-
submitControl,
|
|
42
|
-
onClose,
|
|
43
|
-
|
|
44
|
-
className = "",
|
|
45
|
-
}: ModalConfirmProps) {
|
|
46
|
-
const { isSm } = useResponsive();
|
|
47
|
-
const [toast, setToast] = useState<boolean | "success" | "failed">(false);
|
|
48
|
-
const [loading, setLoading] = useState(false);
|
|
49
|
-
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
if (show) {
|
|
52
|
-
document.getElementsByTagName("body")[0].style.overflow = "hidden";
|
|
53
|
-
|
|
54
|
-
shortcut.register("escape", () => {
|
|
55
|
-
onClose?.()
|
|
56
|
-
}, "Kembali")
|
|
57
|
-
} else {
|
|
58
|
-
document.getElementsByTagName("body")[0].style.removeProperty("overflow");
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return () => {
|
|
62
|
-
shortcut.unregister("escape")
|
|
63
|
-
}
|
|
64
|
-
}, [show]);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const renderChildren = useMemo(() => {
|
|
68
|
-
return (
|
|
69
|
-
<>
|
|
70
|
-
{title && (
|
|
71
|
-
<div
|
|
72
|
-
className={cn(
|
|
73
|
-
"flex flex-col gap-2 items-center text-primary",
|
|
74
|
-
pcn<CT>(className, "header")
|
|
75
|
-
)}
|
|
76
|
-
>
|
|
77
|
-
<div className="mt-6">
|
|
78
|
-
<FontAwesomeIcon
|
|
79
|
-
icon={icon || faQuestion}
|
|
80
|
-
className={`text-xl`}
|
|
81
|
-
/>
|
|
82
|
-
</div>
|
|
83
|
-
|
|
84
|
-
<h6 className="font-semibold text-lg">{title}</h6>
|
|
85
|
-
</div>
|
|
86
|
-
)}
|
|
87
|
-
|
|
88
|
-
{children}
|
|
89
|
-
|
|
90
|
-
{footer && (
|
|
91
|
-
<div className={cn("modal-footer", pcn<CT>(className, "footer"))}>
|
|
92
|
-
{footer}
|
|
93
|
-
</div>
|
|
94
|
-
)}
|
|
95
|
-
</>
|
|
96
|
-
)
|
|
97
|
-
}, [title, footer, children])
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const renderAction = (size: ButtonProps["size"] = 'md') => {
|
|
101
|
-
return (
|
|
102
|
-
<div className="flex justify-center pt-6">
|
|
103
|
-
<ButtonComponent
|
|
104
|
-
label="Batal"
|
|
105
|
-
variant="simple"
|
|
106
|
-
onClick={() => onClose()}
|
|
107
|
-
className="text-foreground bg-background rounded-none"
|
|
108
|
-
block
|
|
109
|
-
size={size}
|
|
110
|
-
/>
|
|
111
|
-
<ButtonComponent
|
|
112
|
-
label={"Konfirmasi"}
|
|
113
|
-
loading={loading}
|
|
114
|
-
onClick={async () => {
|
|
115
|
-
if(!submitControl?.onSubmit) return;
|
|
116
|
-
|
|
117
|
-
setLoading(true);
|
|
118
|
-
if (typeof submitControl?.onSubmit == "function") {
|
|
119
|
-
submitControl?.onSubmit?.();
|
|
120
|
-
} else {
|
|
121
|
-
let response: any = null;
|
|
122
|
-
|
|
123
|
-
if ("path" in submitControl?.onSubmit || "url" in submitControl?.onSubmit) {
|
|
124
|
-
response = await api(submitControl?.onSubmit as ApiType)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if ("idb" in submitControl?.onSubmit) {
|
|
128
|
-
const idb = registry.get("idb");
|
|
129
|
-
if (!idb) {
|
|
130
|
-
throw new Error("IndexedDB (IDB) extension is not installed.");
|
|
131
|
-
}
|
|
132
|
-
await idb.delete((submitControl?.onSubmit as SubmitIDB).idb.store, (submitControl?.onSubmit as SubmitIDB).idb.id)
|
|
133
|
-
|
|
134
|
-
response = { status: 200 }
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (response?.status == 200 || response?.status == 201) {
|
|
138
|
-
setToast("success");
|
|
139
|
-
submitControl?.onSuccess?.();
|
|
140
|
-
setLoading(false);
|
|
141
|
-
} else {
|
|
142
|
-
setToast("failed");
|
|
143
|
-
submitControl?.onError?.();
|
|
144
|
-
setLoading(false);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}}
|
|
148
|
-
className="rounded-none"
|
|
149
|
-
block
|
|
150
|
-
size={size}
|
|
151
|
-
{...submitControl}
|
|
152
|
-
/>
|
|
153
|
-
</div>
|
|
154
|
-
)
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
return (
|
|
158
|
-
<>
|
|
159
|
-
{!isSm ? (
|
|
160
|
-
<>
|
|
161
|
-
<div
|
|
162
|
-
className={cn(
|
|
163
|
-
"modal-backdrop",
|
|
164
|
-
!show && "opacity-0 scale-0 -translate-y-full",
|
|
165
|
-
pcn<CT>(className, "backdrop")
|
|
166
|
-
)}
|
|
167
|
-
onClick={() => onClose()}
|
|
168
|
-
></div>
|
|
169
|
-
|
|
170
|
-
<div
|
|
171
|
-
className={cn(
|
|
172
|
-
"modal rounded-[4px] border-t-4 !border-primary",
|
|
173
|
-
"w-[calc(100vw-2rem)] md:w-[50vw] max-w-[300px]",
|
|
174
|
-
!show && "-translate-y-full opacity-0 scale-y-0",
|
|
175
|
-
pcn<CT>(className, "base")
|
|
176
|
-
)}
|
|
177
|
-
>
|
|
178
|
-
{renderChildren}
|
|
179
|
-
|
|
180
|
-
{renderAction()}
|
|
181
|
-
</div>
|
|
182
|
-
</>
|
|
183
|
-
) : (
|
|
184
|
-
<>
|
|
185
|
-
<BottomSheetComponent
|
|
186
|
-
show={show}
|
|
187
|
-
onClose={onClose}
|
|
188
|
-
size={220}
|
|
189
|
-
footer={renderAction('lg')}
|
|
190
|
-
>
|
|
191
|
-
{renderChildren}
|
|
192
|
-
</BottomSheetComponent>
|
|
193
|
-
</>
|
|
194
|
-
)}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
<ToastComponent
|
|
198
|
-
show={toast == "failed"}
|
|
199
|
-
onClose={() => setToast(false)}
|
|
200
|
-
title="Gagal"
|
|
201
|
-
className="!border-danger header::text-danger"
|
|
202
|
-
>
|
|
203
|
-
<p className="px-3 pb-2 text-sm">
|
|
204
|
-
Gagal {title || ""}! cek data dan koneksi internet dan coba kembali!
|
|
205
|
-
</p>
|
|
206
|
-
</ToastComponent>
|
|
207
|
-
|
|
208
|
-
<ToastComponent
|
|
209
|
-
show={toast == "success"}
|
|
210
|
-
onClose={() => setToast(false)}
|
|
211
|
-
title="Berhasil"
|
|
212
|
-
className="!border-success header::text-success"
|
|
213
|
-
>
|
|
214
|
-
<p className="px-3 pb-2 text-sm">Berhasil {title || ""}!</p>
|
|
215
|
-
</ToastComponent>
|
|
216
|
-
</>
|
|
217
|
-
);
|
|
218
|
-
}
|