@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,352 +1,352 @@
|
|
|
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
|
+
"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
|
+
};
|