@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,352 +0,0 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import { InputHTMLAttributes, ReactNode, useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
-
import moment from "moment";
|
|
5
|
-
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
6
|
-
import { faChevronLeft, faChevronRight } from "@fortawesome/free-solid-svg-icons";
|
|
7
|
-
import { cn, pcn, useInputHandler, useInputRandomId, useResponsive, useValidation, validation, ValidationRules } from "@utils";
|
|
8
|
-
import { BottomSheetComponent, ButtonComponent, OutsideClickComponent } from "@components";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
type CT = "label" | "tip" | "error" | "input" | "icon";
|
|
13
|
-
|
|
14
|
-
export interface InputDateProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "onChange"> {
|
|
15
|
-
label ?: string;
|
|
16
|
-
tip ?: string | ReactNode;
|
|
17
|
-
leftIcon ?: any;
|
|
18
|
-
rightIcon ?: any;
|
|
19
|
-
|
|
20
|
-
value ?: string;
|
|
21
|
-
invalid ?: string;
|
|
22
|
-
validations ?: ValidationRules;
|
|
23
|
-
|
|
24
|
-
onChange ?: (value: string) => any;
|
|
25
|
-
register ?: (name: string, validations?: ValidationRules) => void;
|
|
26
|
-
unregister ?: (name: string) => void;
|
|
27
|
-
|
|
28
|
-
/** Use custom class with: "label::", "tip::", "error::", "icon::". */
|
|
29
|
-
className ?: string;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
export function InputDateComponent({
|
|
35
|
-
label,
|
|
36
|
-
tip,
|
|
37
|
-
leftIcon,
|
|
38
|
-
rightIcon,
|
|
39
|
-
|
|
40
|
-
value,
|
|
41
|
-
invalid,
|
|
42
|
-
validations,
|
|
43
|
-
|
|
44
|
-
register,
|
|
45
|
-
unregister,
|
|
46
|
-
onChange,
|
|
47
|
-
|
|
48
|
-
className = "",
|
|
49
|
-
...props
|
|
50
|
-
}: InputDateProps) {
|
|
51
|
-
const { isSm } = useResponsive();
|
|
52
|
-
|
|
53
|
-
// =========================>
|
|
54
|
-
// ## Initial
|
|
55
|
-
// =========================>
|
|
56
|
-
const inputHandler = useInputHandler(props.name, value, validations, register, unregister, false)
|
|
57
|
-
const randomId = useInputRandomId()
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// =========================>
|
|
61
|
-
// ## Invalid handler
|
|
62
|
-
// =========================>
|
|
63
|
-
const [invalidMessage] = useValidation(inputHandler.value, validations, invalid, inputHandler.idle);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<>
|
|
68
|
-
<div className="relative flex flex-col gap-y-0.5">
|
|
69
|
-
<label
|
|
70
|
-
htmlFor={randomId}
|
|
71
|
-
className={cn(
|
|
72
|
-
"input-label",
|
|
73
|
-
pcn<CT>(className, "label"),
|
|
74
|
-
props.disabled && "opacity-50",
|
|
75
|
-
props.disabled && pcn<CT>(className, "label", "disabled"),
|
|
76
|
-
inputHandler.focus && "text-primary",
|
|
77
|
-
inputHandler.focus && pcn<CT>(className, "label", "focus"),
|
|
78
|
-
!!invalidMessage && "text-danger",
|
|
79
|
-
!!invalidMessage && pcn<CT>(className, "label", "focus")
|
|
80
|
-
)}
|
|
81
|
-
>
|
|
82
|
-
{label}
|
|
83
|
-
{validations && validation.hasRules(validations, "required") && <span className="text-danger ml-1">*</span>}
|
|
84
|
-
</label>
|
|
85
|
-
|
|
86
|
-
{tip && (
|
|
87
|
-
<small
|
|
88
|
-
className={cn(
|
|
89
|
-
"input-tip",
|
|
90
|
-
pcn<CT>(className, "tip"),
|
|
91
|
-
props.disabled && "opacity-60",
|
|
92
|
-
props.disabled && pcn<CT>(className, "tip", "disabled")
|
|
93
|
-
)}
|
|
94
|
-
>{tip}</small>
|
|
95
|
-
)}
|
|
96
|
-
|
|
97
|
-
<OutsideClickComponent onOutsideClick={!isSm ? () => inputHandler.setFocus(false) : undefined}>
|
|
98
|
-
<div className="relative">
|
|
99
|
-
<input
|
|
100
|
-
{...props}
|
|
101
|
-
id={randomId}
|
|
102
|
-
className={cn(
|
|
103
|
-
"input",
|
|
104
|
-
leftIcon && "pl-12",
|
|
105
|
-
rightIcon && "pr-12",
|
|
106
|
-
pcn<CT>(className, "input"),
|
|
107
|
-
!!invalidMessage && "input-error",
|
|
108
|
-
!!invalidMessage && pcn<CT>(className, "input", "error")
|
|
109
|
-
)}
|
|
110
|
-
value={inputHandler.value}
|
|
111
|
-
onChange={(e) => {
|
|
112
|
-
inputHandler.setValue(e.target.value);
|
|
113
|
-
inputHandler.setValue(false);
|
|
114
|
-
onChange?.(e.target.value);
|
|
115
|
-
}}
|
|
116
|
-
onFocus={(e) => {
|
|
117
|
-
props.onFocus?.(e);
|
|
118
|
-
inputHandler.setFocus(true);
|
|
119
|
-
}}
|
|
120
|
-
onBlur={(e) => {
|
|
121
|
-
props.onBlur?.(e);
|
|
122
|
-
}}
|
|
123
|
-
autoComplete="off"
|
|
124
|
-
inputMode={isSm ? "none" : undefined}
|
|
125
|
-
/>
|
|
126
|
-
|
|
127
|
-
{leftIcon && (
|
|
128
|
-
<FontAwesomeIcon
|
|
129
|
-
className={cn(
|
|
130
|
-
"left-4 input-icon ",
|
|
131
|
-
pcn<CT>(className, "icon"),
|
|
132
|
-
props.disabled && "opacity-60",
|
|
133
|
-
props.disabled && pcn<CT>(className, "icon", "disabled"),
|
|
134
|
-
inputHandler.focus && "text-primary",
|
|
135
|
-
inputHandler.focus && pcn<CT>(className, "icon", "focus")
|
|
136
|
-
)}
|
|
137
|
-
icon={leftIcon}
|
|
138
|
-
/>
|
|
139
|
-
)}
|
|
140
|
-
|
|
141
|
-
{rightIcon && (
|
|
142
|
-
<FontAwesomeIcon
|
|
143
|
-
className={cn(
|
|
144
|
-
"right-4 input-icon",
|
|
145
|
-
pcn<CT>(className, "icon"),
|
|
146
|
-
props.disabled && "opacity-60",
|
|
147
|
-
props.disabled && pcn<CT>(className, "icon", "disabled"),
|
|
148
|
-
inputHandler.focus && "text-primary",
|
|
149
|
-
inputHandler.focus && pcn<CT>(className, "icon", "focus")
|
|
150
|
-
)}
|
|
151
|
-
icon={rightIcon}
|
|
152
|
-
/>
|
|
153
|
-
)}
|
|
154
|
-
|
|
155
|
-
{!isSm && inputHandler.focus && (
|
|
156
|
-
<div className="w-max h-72 bg-background border p-2 rounded-[6px] absolute top-full right-0 mt-1 z-50">
|
|
157
|
-
<InputDatePickerComponent
|
|
158
|
-
onChange={(e) => {
|
|
159
|
-
inputHandler.setValue(e);
|
|
160
|
-
onChange?.(e);
|
|
161
|
-
}}
|
|
162
|
-
/>
|
|
163
|
-
</div>
|
|
164
|
-
)}
|
|
165
|
-
</div>
|
|
166
|
-
</OutsideClickComponent>
|
|
167
|
-
|
|
168
|
-
{invalidMessage && (
|
|
169
|
-
<small className={cn("input-error-message", pcn<CT>(className, "error"))}>{invalidMessage}</small>
|
|
170
|
-
)}
|
|
171
|
-
</div>
|
|
172
|
-
|
|
173
|
-
{isSm && (
|
|
174
|
-
<BottomSheetComponent
|
|
175
|
-
show={inputHandler.focus}
|
|
176
|
-
onClose={() => inputHandler.setFocus(false)}
|
|
177
|
-
size={380}
|
|
178
|
-
footer={
|
|
179
|
-
<div className="p-4">
|
|
180
|
-
<ButtonComponent
|
|
181
|
-
label="Selesai"
|
|
182
|
-
variant="outline"
|
|
183
|
-
onClick={() => inputHandler.setFocus(false)}
|
|
184
|
-
block
|
|
185
|
-
/>
|
|
186
|
-
</div>
|
|
187
|
-
}
|
|
188
|
-
>
|
|
189
|
-
<div className="p-4">
|
|
190
|
-
<InputDatePickerComponent
|
|
191
|
-
onChange={(e) => {
|
|
192
|
-
inputHandler.setValue(e);
|
|
193
|
-
onChange?.(e);
|
|
194
|
-
}}
|
|
195
|
-
/>
|
|
196
|
-
</div>
|
|
197
|
-
</BottomSheetComponent>
|
|
198
|
-
)}
|
|
199
|
-
</>
|
|
200
|
-
);
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
export interface InputDatePickerProps {
|
|
206
|
-
onChange ?: (date: string) => void;
|
|
207
|
-
minDate ?: string;
|
|
208
|
-
maxDate ?: string;
|
|
209
|
-
rightElement ?: ReactNode;
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
export const InputDatePickerComponent: React.FC<InputDatePickerProps> = ({
|
|
215
|
-
onChange,
|
|
216
|
-
minDate,
|
|
217
|
-
maxDate,
|
|
218
|
-
rightElement,
|
|
219
|
-
}) => {
|
|
220
|
-
const activeYearRef = useRef<HTMLDivElement | null>(null);
|
|
221
|
-
const containerYearRef = useRef<HTMLDivElement | null>(null);
|
|
222
|
-
|
|
223
|
-
const [currentDate, setCurrentDate] = useState(moment());
|
|
224
|
-
const [selectedDate, setSelectedDate] = useState(moment());
|
|
225
|
-
|
|
226
|
-
const startDate = moment(currentDate).startOf("month").startOf("week");
|
|
227
|
-
const endDate = moment(currentDate).endOf("month").endOf("week");
|
|
228
|
-
|
|
229
|
-
const handlePrevMonth = () => setCurrentDate(moment(currentDate).subtract(1, "month"));
|
|
230
|
-
const handleNextMonth = () => setCurrentDate(moment(currentDate).add(1, "month"));
|
|
231
|
-
|
|
232
|
-
const handleDateClick = (date: moment.Moment) => {
|
|
233
|
-
if ((minDate && date.isBefore(moment(minDate))) || (maxDate && date.isAfter(moment(maxDate)))) { return; }
|
|
234
|
-
|
|
235
|
-
setSelectedDate(date);
|
|
236
|
-
onChange?.(date.format("YYYY-MM-DD"));
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
const renderDays = () => {
|
|
240
|
-
const days = [];
|
|
241
|
-
const startDay = moment(startDate);
|
|
242
|
-
|
|
243
|
-
for (let i = 0; i < 7; i++) {
|
|
244
|
-
days.push(
|
|
245
|
-
<div key={i} className="text-center font-bold">
|
|
246
|
-
{startDay.add(i, "days").format("dd")}
|
|
247
|
-
</div>
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return days;
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
const renderCells = () => {
|
|
255
|
-
const rows = [];
|
|
256
|
-
let days = [];
|
|
257
|
-
const day = moment(startDate);
|
|
258
|
-
|
|
259
|
-
while (day.isBefore(endDate) || day.isSame(endDate, "day")) {
|
|
260
|
-
for (let i = 0; i < 7; i++) {
|
|
261
|
-
const cloneDay = moment(day);
|
|
262
|
-
|
|
263
|
-
days.push(
|
|
264
|
-
<div
|
|
265
|
-
key={day.toString()}
|
|
266
|
-
className={`w-8 aspect-square flex items-center justify-center text-center rounded-lg transition-all
|
|
267
|
-
${day.isSame(currentDate, "month") ? "text-foreground" : "text-light-foreground"}
|
|
268
|
-
${day.isSame(selectedDate, "day") ? "bg-primary text-background" : "hover:bg-light-primary"}
|
|
269
|
-
${day.isSame(moment(), "day") ? "border !border-primary" : "hover:bg-light-primary"}
|
|
270
|
-
${(minDate && day.isBefore(moment(minDate))) || (maxDate && day.isAfter(moment(maxDate))) ? "opacity-10 cursor-not-allowed" : "cursor-pointer"}`}
|
|
271
|
-
onClick={() => handleDateClick(cloneDay)}
|
|
272
|
-
>{day.format("D")}</div>
|
|
273
|
-
);
|
|
274
|
-
|
|
275
|
-
day.add(1, "day");
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
rows.push(<div key={day.toString()} className="grid grid-cols-7 gap-1">{days}</div>);
|
|
279
|
-
|
|
280
|
-
days = [];
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
return rows;
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
const years = useMemo(() => {
|
|
287
|
-
const dumpYears = [];
|
|
288
|
-
|
|
289
|
-
for (let i = 1945; i <= moment().year(); i++) {
|
|
290
|
-
dumpYears.push(i);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
return dumpYears;
|
|
294
|
-
}, []);
|
|
295
|
-
|
|
296
|
-
useEffect(() => {
|
|
297
|
-
if (activeYearRef.current && containerYearRef.current) {
|
|
298
|
-
containerYearRef.current.scrollTo({
|
|
299
|
-
top: activeYearRef.current.offsetTop - containerYearRef.current.offsetTop,
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
}, []);
|
|
303
|
-
|
|
304
|
-
return (
|
|
305
|
-
<div className="w-full flex gap-2 max-h-[260]">
|
|
306
|
-
<div
|
|
307
|
-
className="w-1/5 overflow-y-auto input-scroll pr-1"
|
|
308
|
-
ref={containerYearRef}
|
|
309
|
-
>
|
|
310
|
-
<div className="flex flex-col">
|
|
311
|
-
{years?.map((item) => {
|
|
312
|
-
const isActive = currentDate?.year() === item;
|
|
313
|
-
|
|
314
|
-
return (
|
|
315
|
-
<>
|
|
316
|
-
<div
|
|
317
|
-
key={item}
|
|
318
|
-
ref={isActive ? activeYearRef : null}
|
|
319
|
-
className={`py-1 px-2 font-semibold rounded-[6px] cursor-pointer ${isActive && "bg-light-primary"}`}
|
|
320
|
-
onClick={() => setCurrentDate(moment().set("year", item))}
|
|
321
|
-
>
|
|
322
|
-
{item}
|
|
323
|
-
</div>
|
|
324
|
-
</>
|
|
325
|
-
);
|
|
326
|
-
})}
|
|
327
|
-
</div>
|
|
328
|
-
</div>
|
|
329
|
-
<div className="w-4/5">
|
|
330
|
-
<div className="flex justify-between items-center mb-2">
|
|
331
|
-
<button
|
|
332
|
-
onClick={handlePrevMonth}
|
|
333
|
-
className="w-8 text-sm aspect-square rounded-full cursor-pointer"
|
|
334
|
-
>
|
|
335
|
-
<FontAwesomeIcon icon={faChevronLeft} />
|
|
336
|
-
</button>
|
|
337
|
-
<h2 className="font-semibold">{currentDate.format("MMMM")}</h2>
|
|
338
|
-
<button
|
|
339
|
-
onClick={handleNextMonth}
|
|
340
|
-
className="w-8 text-sm aspect-square rounded-full cursor-pointer"
|
|
341
|
-
>
|
|
342
|
-
<FontAwesomeIcon icon={faChevronRight} />
|
|
343
|
-
</button>
|
|
344
|
-
</div>
|
|
345
|
-
<div className="grid grid-cols-7 gap-1 mb-2">{renderDays()}</div>
|
|
346
|
-
<div>{renderCells()}</div>
|
|
347
|
-
</div>
|
|
348
|
-
|
|
349
|
-
{rightElement && <div>{rightElement}</div>}
|
|
350
|
-
</div>
|
|
351
|
-
);
|
|
352
|
-
};
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import { InputHTMLAttributes, ReactNode, useEffect, useState } from "react";
|
|
4
|
-
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
5
|
-
import { cn, pcn, useInputHandler, useInputRandomId, useResponsive, useValidation, validation, ValidationRules } from "@utils";
|
|
6
|
-
import { OutsideClickComponent, InputDatePickerComponent, InputTimePickerComponent, BottomSheetComponent, ButtonComponent, TabbarComponent } from "@components";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
type CT = "label" | "tip" | "error" | "input" | "icon";
|
|
11
|
-
|
|
12
|
-
export interface InputDateTimeProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "onChange"> {
|
|
13
|
-
label ?: string;
|
|
14
|
-
tip ?: string | ReactNode;
|
|
15
|
-
leftIcon ?: any;
|
|
16
|
-
rightIcon ?: any;
|
|
17
|
-
|
|
18
|
-
value ?: string;
|
|
19
|
-
invalid ?: string;
|
|
20
|
-
validations ?: ValidationRules;
|
|
21
|
-
|
|
22
|
-
onChange ?: (value: string) => any;
|
|
23
|
-
register ?: (name: string, validations?: ValidationRules) => void;
|
|
24
|
-
unregister ?: (name: string) => void;
|
|
25
|
-
|
|
26
|
-
/** Use custom class with: "label::", "tip::", "error::", "icon::", "suggest::", "suggest-item::". */
|
|
27
|
-
className ?: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
export function InputDatetimeComponent({
|
|
33
|
-
label,
|
|
34
|
-
tip,
|
|
35
|
-
leftIcon,
|
|
36
|
-
rightIcon,
|
|
37
|
-
|
|
38
|
-
value,
|
|
39
|
-
invalid,
|
|
40
|
-
validations,
|
|
41
|
-
|
|
42
|
-
register,
|
|
43
|
-
unregister,
|
|
44
|
-
onChange,
|
|
45
|
-
|
|
46
|
-
className = "",
|
|
47
|
-
...props
|
|
48
|
-
}: InputDateTimeProps) {
|
|
49
|
-
const { isSm } = useResponsive();
|
|
50
|
-
|
|
51
|
-
const [pickerType, setPickerType] = useState<"date" | "time">("date");
|
|
52
|
-
const [dateValue, setDateValue] = useState("");
|
|
53
|
-
const [timeValue, setTimeValue] = useState("");
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
// =========================>
|
|
57
|
-
// ## Initial
|
|
58
|
-
// =========================>
|
|
59
|
-
const inputHandler = useInputHandler(props.name, value, validations, register, unregister, false)
|
|
60
|
-
const randomId = useInputRandomId()
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// =========================>
|
|
64
|
-
// ## Invalid handler
|
|
65
|
-
// =========================>
|
|
66
|
-
const [invalidMessage] = useValidation(inputHandler.value, validations, invalid, inputHandler.idle);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// =========================>
|
|
70
|
-
// ## change value handler
|
|
71
|
-
// =========================>
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
inputHandler.setValue(value || "");
|
|
74
|
-
value && inputHandler.setValue(false);
|
|
75
|
-
|
|
76
|
-
if (value) {
|
|
77
|
-
const [d, t] = value.split(" ");
|
|
78
|
-
setDateValue(d || "");
|
|
79
|
-
setTimeValue(t || "");
|
|
80
|
-
}
|
|
81
|
-
}, [value]);
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const handleChange = (date: string, time: string) => {
|
|
85
|
-
const newVal = `${date} ${time}`;
|
|
86
|
-
inputHandler.setValue(newVal.trim());
|
|
87
|
-
onChange?.(newVal.trim());
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return (
|
|
92
|
-
<>
|
|
93
|
-
<div className="relative flex flex-col gap-y-0.5">
|
|
94
|
-
<label
|
|
95
|
-
htmlFor={randomId}
|
|
96
|
-
className={cn(
|
|
97
|
-
"input-label",
|
|
98
|
-
pcn<CT>(className, "label"),
|
|
99
|
-
props.disabled && "opacity-50",
|
|
100
|
-
inputHandler.focus && "text-primary",
|
|
101
|
-
!!invalidMessage && "text-danger"
|
|
102
|
-
)}
|
|
103
|
-
>
|
|
104
|
-
{label}
|
|
105
|
-
{validations && validation.hasRules(validations, "required") && <span className="text-danger ml-1">*</span>}
|
|
106
|
-
</label>
|
|
107
|
-
|
|
108
|
-
{tip && (
|
|
109
|
-
<small
|
|
110
|
-
className={cn(
|
|
111
|
-
"input-tip",
|
|
112
|
-
pcn<CT>(className, "tip"),
|
|
113
|
-
props.disabled && "opacity-60"
|
|
114
|
-
)}
|
|
115
|
-
>{tip}</small>
|
|
116
|
-
)}
|
|
117
|
-
|
|
118
|
-
<OutsideClickComponent onOutsideClick={!isSm ? () => inputHandler.setFocus(false) : undefined}>
|
|
119
|
-
<div className="relative">
|
|
120
|
-
<input
|
|
121
|
-
{...props}
|
|
122
|
-
id={randomId}
|
|
123
|
-
readOnly
|
|
124
|
-
className={cn(
|
|
125
|
-
"input",
|
|
126
|
-
leftIcon && "pl-12",
|
|
127
|
-
rightIcon && "pr-12",
|
|
128
|
-
pcn<CT>(className, "input"),
|
|
129
|
-
!!invalidMessage && "input-error"
|
|
130
|
-
)}
|
|
131
|
-
value={inputHandler.value}
|
|
132
|
-
onFocus={(e) => {
|
|
133
|
-
props.onFocus?.(e);
|
|
134
|
-
inputHandler.setFocus(true);
|
|
135
|
-
}}
|
|
136
|
-
autoComplete="off"
|
|
137
|
-
inputMode={isSm ? "none" : undefined}
|
|
138
|
-
/>
|
|
139
|
-
|
|
140
|
-
{leftIcon && (
|
|
141
|
-
<FontAwesomeIcon
|
|
142
|
-
className={cn(
|
|
143
|
-
"left-4 input-icon",
|
|
144
|
-
pcn<CT>(className, "icon"),
|
|
145
|
-
props.disabled && "opacity-60",
|
|
146
|
-
inputHandler.focus && "text-primary"
|
|
147
|
-
)}
|
|
148
|
-
icon={leftIcon}
|
|
149
|
-
/>
|
|
150
|
-
)}
|
|
151
|
-
|
|
152
|
-
{rightIcon && (
|
|
153
|
-
<FontAwesomeIcon
|
|
154
|
-
className={cn(
|
|
155
|
-
"right-4 input-icon",
|
|
156
|
-
pcn<CT>(className, "icon"),
|
|
157
|
-
props.disabled && "opacity-60",
|
|
158
|
-
inputHandler.focus && "text-primary"
|
|
159
|
-
)}
|
|
160
|
-
icon={rightIcon}
|
|
161
|
-
/>
|
|
162
|
-
)}
|
|
163
|
-
|
|
164
|
-
{!isSm && inputHandler.focus && (
|
|
165
|
-
<>
|
|
166
|
-
<div className="absolute z-50 top-full right-0 mt-1 w-max bg-background border rounded-[6px] p-2 shadow min-w-[350]">
|
|
167
|
-
<TabbarComponent
|
|
168
|
-
items={[
|
|
169
|
-
{
|
|
170
|
-
label: "Tanggal",
|
|
171
|
-
value: 'date'
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
label: "Jam",
|
|
175
|
-
value: 'time'
|
|
176
|
-
},
|
|
177
|
-
]}
|
|
178
|
-
active={pickerType}
|
|
179
|
-
onChange={(e) => setPickerType(e as "time" | "date")}
|
|
180
|
-
className="mb-4"
|
|
181
|
-
/>
|
|
182
|
-
{pickerType === "date" ? (
|
|
183
|
-
<InputDatePickerComponent
|
|
184
|
-
onChange={(e) => {
|
|
185
|
-
setDateValue(e);
|
|
186
|
-
handleChange(e, timeValue);
|
|
187
|
-
}}
|
|
188
|
-
/>
|
|
189
|
-
) : (
|
|
190
|
-
<InputTimePickerComponent
|
|
191
|
-
onChange={(e) => {
|
|
192
|
-
setTimeValue(e);
|
|
193
|
-
handleChange(dateValue, e);
|
|
194
|
-
}}
|
|
195
|
-
/>
|
|
196
|
-
)}
|
|
197
|
-
</div>
|
|
198
|
-
</>
|
|
199
|
-
)}
|
|
200
|
-
</div>
|
|
201
|
-
</OutsideClickComponent>
|
|
202
|
-
|
|
203
|
-
{invalidMessage && (
|
|
204
|
-
<small className={cn("input-error-message", pcn<CT>(className, "error"))}>{invalidMessage}</small>
|
|
205
|
-
)}
|
|
206
|
-
</div>
|
|
207
|
-
|
|
208
|
-
{isSm && (
|
|
209
|
-
<BottomSheetComponent
|
|
210
|
-
show={inputHandler.focus}
|
|
211
|
-
onClose={() => inputHandler.setFocus(false)}
|
|
212
|
-
size={430}
|
|
213
|
-
footer={
|
|
214
|
-
<div className="p-4">
|
|
215
|
-
<ButtonComponent
|
|
216
|
-
label="Selesai"
|
|
217
|
-
variant="outline"
|
|
218
|
-
onClick={() => inputHandler.setFocus(false)}
|
|
219
|
-
block
|
|
220
|
-
/>
|
|
221
|
-
</div>
|
|
222
|
-
}
|
|
223
|
-
>
|
|
224
|
-
<div className="p-4">
|
|
225
|
-
<TabbarComponent
|
|
226
|
-
items={[
|
|
227
|
-
{
|
|
228
|
-
label: "Tanggal",
|
|
229
|
-
value: 'date'
|
|
230
|
-
},
|
|
231
|
-
{
|
|
232
|
-
label: "Jam",
|
|
233
|
-
value: 'time'
|
|
234
|
-
},
|
|
235
|
-
]}
|
|
236
|
-
active={pickerType}
|
|
237
|
-
onChange={(e) => setPickerType(e as "time" | "date")}
|
|
238
|
-
className="mb-4"
|
|
239
|
-
/>
|
|
240
|
-
{pickerType === "date" ? (
|
|
241
|
-
<InputDatePickerComponent
|
|
242
|
-
onChange={(e) => {
|
|
243
|
-
setDateValue(e);
|
|
244
|
-
handleChange(e, timeValue);
|
|
245
|
-
}}
|
|
246
|
-
/>
|
|
247
|
-
) : (
|
|
248
|
-
<InputTimePickerComponent
|
|
249
|
-
onChange={(e) => {
|
|
250
|
-
setTimeValue(e);
|
|
251
|
-
handleChange(dateValue, e);
|
|
252
|
-
}}
|
|
253
|
-
/>
|
|
254
|
-
)}
|
|
255
|
-
</div>
|
|
256
|
-
</BottomSheetComponent>
|
|
257
|
-
)}
|
|
258
|
-
</>
|
|
259
|
-
);
|
|
260
|
-
}
|