@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.
Files changed (87) hide show
  1. package/.env.example +43 -43
  2. package/.github/workflows/publish.yml +39 -0
  3. package/CONTRIBUTING.md +45 -0
  4. package/LICENSE +21 -0
  5. package/README.md +91 -28
  6. package/app/auth/edit/page.tsx +65 -65
  7. package/app/auth/login/page.tsx +63 -63
  8. package/app/auth/me/page.tsx +58 -58
  9. package/app/auth/register/page.tsx +69 -69
  10. package/app/auth/verify/page.tsx +53 -53
  11. package/app/dashboard/user/page.tsx +76 -76
  12. package/app/layout.tsx +37 -37
  13. package/app/manifest.ts +25 -0
  14. package/app/page.tsx +13 -13
  15. package/barrels.json +5 -5
  16. package/blueprints/starter.blueprint.json +102 -102
  17. package/bun.lock +916 -0
  18. package/components/base.components/chip/Chip.component.tsx +39 -39
  19. package/components/base.components/document/DocumentViewer.component.tsx +163 -163
  20. package/components/base.components/document/ExportExcel.component.tsx +340 -340
  21. package/components/base.components/document/ImportExcel.component.tsx +315 -315
  22. package/components/base.components/document/PrintTable.component.tsx +204 -204
  23. package/components/base.components/document/RenderPDF.component.tsx +415 -415
  24. package/components/base.components/input/Checkbox.component.tsx +109 -109
  25. package/components/base.components/input/Input.component.tsx +332 -332
  26. package/components/base.components/input/InputCheckbox.component.tsx +174 -174
  27. package/components/base.components/input/InputCurrency.component.tsx +163 -163
  28. package/components/base.components/input/InputDate.component.tsx +352 -352
  29. package/components/base.components/input/InputDatetime.component.tsx +260 -260
  30. package/components/base.components/input/InputDocument.component.tsx +351 -351
  31. package/components/base.components/input/InputImage.component.tsx +533 -533
  32. package/components/base.components/input/InputMap.component.tsx +317 -317
  33. package/components/base.components/input/InputNumber.component.tsx +192 -192
  34. package/components/base.components/input/InputOtp.component.tsx +169 -169
  35. package/components/base.components/input/InputPassword.component.tsx +236 -236
  36. package/components/base.components/input/InputRadio.component.tsx +175 -175
  37. package/components/base.components/input/InputTime.component.tsx +275 -275
  38. package/components/base.components/input/InputValues.component.tsx +68 -68
  39. package/components/base.components/input/Radio.component.tsx +102 -102
  40. package/components/base.components/input/Select.component.tsx +541 -541
  41. package/components/base.components/modal/BottomSheet.component.tsx +245 -245
  42. package/components/base.components/supervision/FormSupervision.component.tsx +433 -433
  43. package/components/base.components/supervision/TableSupervision.component.tsx +697 -697
  44. package/components/base.components/table/ControlBar.component.tsx +497 -497
  45. package/components/base.components/table/FilterComponent.tsx +518 -518
  46. package/components/base.components/table/Table.component.tsx +469 -469
  47. package/components/base.components/typography/TypographyArticle.component.tsx +26 -26
  48. package/components/base.components/typography/TypographyColumn.component.tsx +20 -20
  49. package/components/base.components/typography/TypographyContent.component.tsx +20 -20
  50. package/components/base.components/typography/TypographyTips.component.tsx +20 -20
  51. package/components/base.components/wrap/Draggable.component.tsx +303 -303
  52. package/components/base.components/wrap/IDBProvider.tsx +12 -12
  53. package/components/base.components/wrap/Image.component.tsx +9 -9
  54. package/components/base.components/wrap/ShortcutProvider.tsx +57 -57
  55. package/components/base.components/wrap/Swipe.component.tsx +93 -93
  56. package/components/index.ts +2 -2
  57. package/contexts/AppProvider.tsx +11 -11
  58. package/contexts/Auth.context.tsx +64 -64
  59. package/contexts/Toggle.context.tsx +44 -44
  60. package/next.config.ts +15 -1
  61. package/package.json +14 -13
  62. package/public/204.svg +19 -19
  63. package/public/500.svg +39 -39
  64. package/public/icon-192.png +0 -0
  65. package/public/icon-512.png +0 -0
  66. package/public/images/logo-fill.png +0 -0
  67. package/public/images/logo-full-fill.png +0 -0
  68. package/public/images/logo-full.png +0 -0
  69. package/public/images/logo.png +0 -0
  70. package/schema/idb/app.schema.ts +8 -8
  71. package/src-tauri/Cargo.toml +14 -0
  72. package/src-tauri/build.rs +3 -0
  73. package/src-tauri/capabilities/default.json +11 -0
  74. package/src-tauri/icons/128x128.png +0 -0
  75. package/src-tauri/icons/128x128@2x.png +0 -0
  76. package/src-tauri/icons/32x32.png +0 -0
  77. package/src-tauri/icons/icon.icns +0 -0
  78. package/src-tauri/icons/icon.ico +0 -0
  79. package/src-tauri/src/main.rs +7 -0
  80. package/src-tauri/tauri.conf.json +36 -0
  81. package/styles/globals.css +231 -231
  82. package/styles/tailwind.safelist +68 -68
  83. package/utils/commands/barrels.ts +27 -27
  84. package/utils/commands/light.ts +21 -21
  85. package/utils/commands/logger.ts +42 -42
  86. package/utils/commands/stubs/table-blueprint.stub +12 -12
  87. package/utils/commands/use-pdf.ts +29 -29
@@ -1,497 +1,497 @@
1
- "use client"
2
-
3
- import { ReactNode, useEffect, useRef } from 'react'
4
- import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
5
- import { faArrowDownZA, faArrowUpAZ, faEllipsisV, faEyeLowVision, faMagnifyingGlass, faPlus, faRefresh, faSearch, faSliders, faSort } from '@fortawesome/free-solid-svg-icons';
6
- import { ApiFilterType, cn, conversion, shortcut, useResponsive } from '@utils';
7
- import { useToggleContext } from '@contexts';
8
- import { IconButtonComponent, InputCheckboxComponent, InputComponent, SelectComponent, OutsideClickComponent, ButtonComponent, BottomSheetComponent, FilterComponent, FilterColumnOption } from '@components';
9
-
10
-
11
-
12
- export type ControlBarOptionType = "SEARCH" | "SEARCHABLE" | "FILTER" | "SELECTABLE" | "REFRESH" | ReactNode;
13
-
14
- export interface ControlBarProps {
15
- id ?: string;
16
- options ?: ControlBarOptionType[];
17
- className ?: string
18
- search ?: string,
19
- onSearch ?: (searchable: string) => void,
20
- searchableOptions ?: {label: string | ReactNode, selector: string}[]
21
- searchable ?: string[],
22
- onSearchable ?: (searchable: string[]) => void,
23
- selectableOptions ?: {label: string | ReactNode, selector: string}[]
24
- selectable ?: string[],
25
- onSelectable ?: (searchable: string[]) => void,
26
- sortableOptions ?: {label: string | ReactNode, selector: string}[]
27
- sort ?: string[],
28
- onSort ?: (sort: string[]) => void,
29
- filterableColumns ?: FilterColumnOption[],
30
- onFilter ?: (filters: ApiFilterType[]) => void,
31
- filter ?: ApiFilterType[],
32
- onRefresh ?: () => void,
33
- }
34
-
35
-
36
-
37
- export function ControlBarComponent({
38
- id = "",
39
- options,
40
- className,
41
- search,
42
- onSearch,
43
- searchableOptions,
44
- searchable,
45
- onSearchable,
46
- selectableOptions,
47
- selectable,
48
- onSelectable,
49
- sortableOptions,
50
- sort,
51
- onSort,
52
- filterableColumns,
53
- onFilter,
54
- filter,
55
- onRefresh
56
- }: ControlBarProps) {
57
- const {toggle, setToggle} = useToggleContext()
58
- const { isSm } = useResponsive();
59
-
60
- const searchRef = useRef<HTMLInputElement | null>(null);
61
-
62
- useEffect(() => {
63
- if (options?.includes("SEARCH")) {
64
- shortcut.register("ctrl+s", () => {
65
- searchRef.current?.focus()
66
- }, "Cari")
67
- }
68
-
69
- if (options?.includes("FILTER")) {
70
- shortcut.register("ctrl+f", () => {
71
- setToggle("FILTER")
72
- }, "Filter")
73
- }
74
-
75
- if (options?.includes("SORT")) {
76
- shortcut.register("ctrl+o", () => {
77
- setToggle("SORT")
78
- }, "Urutkan")
79
- }
80
-
81
- if (options?.includes("SELECTABLE")) {
82
- shortcut.register("ctrl+l", () => {
83
- setToggle("SELECTABLE")
84
- }, "Kolom Ditampilkan")
85
- }
86
-
87
- if (options?.includes("REFRESH")) {
88
- shortcut.register("ctrl+shift+r", () => {
89
- onRefresh?.()
90
- }, "Refresh Tabel")
91
- }
92
-
93
- return () => {
94
- options?.includes("SEARCH") && shortcut.unregister("ctrl+s")
95
- options?.includes("FILTER") && shortcut.unregister("ctrl+f")
96
- options?.includes("SORT") && shortcut.unregister("ctrl+o")
97
- options?.includes("SELECTABLE") && shortcut.unregister("ctrl+l")
98
- options?.includes("REFRESH") && shortcut.unregister("ctrl+shift+r")
99
- }
100
- }, [options])
101
-
102
- const onChangeSort = (item: string) => {
103
- if(!!sort?.find((s) => s.split(" ")?.at(0) == item)) {
104
- const findSort = sort.find((s) => s.split(" ")?.at(0) == item);
105
-
106
- if (findSort?.split(" ")?.at(1) == "desc") {
107
- onSort?.(sort.filter((s) => s != findSort));
108
- } else {
109
- const newSorts = [...sort];
110
- newSorts[newSorts?.findIndex((s) => s == findSort)] = `${item} desc`
111
- onSort?.(newSorts);
112
- }
113
- } else {
114
- onSort?.([...(sort || []), `${item} asc`])
115
- }
116
- }
117
-
118
- return (
119
- <>
120
- <div className={cn("py-1 md:py-2 md:px-1.5 bg-white rounded-[6px] border flex items-center mb-2", className)}>
121
- {(isSm ? [
122
- ...(options?.filter((op, iop) => iop == 0 || op == "REFRESH") || []),
123
- ...(options && options?.length > 1 ? ['MOBILE_OPTION'] : [])
124
- ] : options)?.map((option: ControlBarOptionType, key: number) => {
125
- {
126
- // =========================>
127
- // ## Create button
128
- // =========================>
129
- }
130
- if (option == "CREATE") {
131
- return (
132
- <div className="pl-1.5 pr-3 mr-2 border-r" key="button-add">
133
- <ButtonComponent
134
- icon={faPlus}
135
- label="Tambah Data"
136
- size="sm"
137
- onClick={() => setToggle(`MODAL_FORM_${conversion.strSnake(id).toUpperCase()}`)}
138
- />
139
- </div>
140
- );
141
- }
142
-
143
- {
144
- // =========================>
145
- // ## Search Field
146
- // =========================>
147
- }
148
- if (option == "SEARCH") {
149
- const searchable = !!options?.find((option) => option == "SEARCHABLE");
150
-
151
- return (
152
- <div className={cn("w-full min-w-[150px]", searchable ? "pr-1.5" : "px-1.5")} key={key}>
153
- <InputComponent
154
- ref={searchRef}
155
- name="search"
156
- placeholder="Cari disini..."
157
- rightIcon={faMagnifyingGlass}
158
- value={search}
159
- onChange={(e) => onSearch?.(e)}
160
- className={cn("py-1.5 text-sm", searchable && "rounded-l-none")}
161
- />
162
- </div>
163
- );
164
- }
165
-
166
- {
167
- // =========================>
168
- // ## Searchable Field
169
- // =========================>
170
- }
171
- if (option == "SEARCHABLE") {
172
- return searchableOptions?.length ? (
173
- <div className="w-28 pl-1.5" key={key}>
174
- <SelectComponent
175
- name="searchableColumn"
176
- leftIcon={faSearch}
177
- options={searchableOptions?.map((column) => {
178
- return {
179
- label: column.label,
180
- value: column.selector,
181
- };
182
- }) || []}
183
- value={searchable}
184
- onChange={(e) => onSearchable?.(e as string[])}
185
- className="py-1.5 text-sm rounded-r-none border-r-0"
186
- multiple
187
- />
188
- </div>
189
- ) : <></>;
190
- }
191
-
192
- {
193
- // =========================>
194
- // ## Selectable Button
195
- // =========================>
196
- }
197
- if (option == "SELECTABLE") {
198
- return (
199
- <div className="px-1.5 rounded-md relative" key={key}>
200
- <IconButtonComponent
201
- icon={faEyeLowVision}
202
- variant="outline"
203
- className="!text-foreground p-4"
204
- onClick={() => setToggle("SELECTABLE")}
205
- size="sm"
206
- />
207
- <OutsideClickComponent onOutsideClick={() => setToggle("SELECTABLE", false)}>
208
- <div
209
- className={cn(
210
- "absolute -bottom-4 bg-white translate-y-full right-0 w-[240px] z-20 rounded-lg border",
211
- !toggle.SELECTABLE && "scale-y-0 top-0 opacity-0"
212
- )}
213
- >
214
- <p className='input-label text-xs p-4'>Kolom Ditampilkan</p>
215
- <InputCheckboxComponent
216
- vertical
217
- name="show_column"
218
- options={selectableOptions?.map((option) => {
219
- return {
220
- label: option.label as string,
221
- value: option.selector,
222
- };
223
- })}
224
- onChange={(e) => onSelectable?.(Array().concat(e).map((val) => String(val)))}
225
- value={selectable}
226
- className='px-4 border-0 gap-4 mb-4'
227
- classNameCheckbox='w-5 h-5 label::text-xs'
228
- />
229
- </div>
230
- </OutsideClickComponent>
231
- </div>
232
- );
233
- }
234
-
235
- {
236
- // =========================>
237
- // ## Sort Button
238
- // =========================>
239
- }
240
- if (option == "SORT") {
241
- return sortableOptions?.length ? (
242
- <div className="px-1.5 rounded-md relative" key={key}>
243
- <IconButtonComponent
244
- icon={faSort}
245
- variant="outline"
246
- className="!text-foreground p-4"
247
- onClick={() => setToggle("SORT")}
248
- size="sm"
249
- />
250
- <OutsideClickComponent onOutsideClick={() => setToggle("SORT", false)}>
251
- <div
252
- className={cn(
253
- "absolute -bottom-4 bg-white translate-y-full right-0 w-[240px] z-20 rounded-lg border",
254
- !toggle.SORT && "scale-y-0 top-0 opacity-0"
255
- )}
256
- >
257
- <p className='input-label text-xs p-4'>Urut Berdasarkan</p>
258
- <div className='flex flex-col mb-4'>
259
- {sortableOptions?.map((option, key) => {
260
- const sortBy = sort?.find((s) => s.split(" ")?.at(0) == option?.selector)?.split(" ")?.at(1) || "";
261
- return (
262
- <div
263
- key={key}
264
- className={cn('flex justify-between cursor-pointer text-sm px-4 py-2 hover:bg-light-primary', !!sortBy && "text-primary bg-primary/10")}
265
- onClick={() => onChangeSort(option.selector)}
266
- >
267
- <p>{option.label}</p>
268
-
269
- {sortBy && (
270
- <div className='text-primary'>
271
- <FontAwesomeIcon icon={sortBy == "desc" ? faArrowDownZA : faArrowUpAZ} className='text-xs' />
272
- {sort?.length && sort?.length > 1 && <span className='text-[9px] ml-1'>{sort.findIndex((s) => s.split(" ")?.at(0) == option?.selector) + 1}</span>}
273
- </div>
274
- )}
275
- </div>
276
- )
277
- })}
278
- </div>
279
- </div>
280
- </OutsideClickComponent>
281
- </div>
282
- ) : <></>;
283
- }
284
-
285
- {
286
- // =========================>
287
- // ## Refresh Button
288
- // =========================>
289
- }
290
- if (option == "REFRESH") {
291
- return (
292
- <div className="md:px-1.5 relative" key={key}>
293
- <IconButtonComponent
294
- icon={faRefresh}
295
- variant="outline"
296
- className="!text-foreground p-4"
297
- onClick={() => onRefresh?.()}
298
- size="sm"
299
- />
300
- </div>
301
- );
302
- }
303
-
304
- {
305
- // =========================>
306
- // ## Filter Button
307
- // =========================>
308
- }
309
- if (option == "FILTER") {
310
- return (
311
- <div className="px-1.5 rounded-md relative" key={key}>
312
- <ButtonComponent
313
- icon={faSliders}
314
- label="Filter"
315
- variant="outline"
316
- className="!text-foreground"
317
- onClick={() => setToggle("FILTER")}
318
- size="sm"
319
- />
320
- </div>
321
- );
322
- }
323
-
324
- {
325
- // =========================>
326
- // ## Mobile option button
327
- // =========================>
328
- }
329
- if (option == "MOBILE_OPTION") {
330
- return (
331
- <div className="px-1.5 relative" key={key}>
332
- <IconButtonComponent
333
- icon={faEllipsisV}
334
- variant="outline"
335
- className="!text-foreground p-4"
336
- onClick={() => setToggle("MOBILE_OPTION")}
337
- size="sm"
338
- />
339
- </div>
340
- );
341
- }
342
-
343
- return option;
344
- })}
345
- </div>
346
-
347
- {!!filterableColumns && !!filterableColumns?.length && (
348
- <FilterComponent
349
- className={cn("", !toggle.FILTER ? "p-0 h-0 hidden overflow-hidden" : "mb-2 animate-intro-down")}
350
- columns={filterableColumns}
351
- onChange={onFilter}
352
- value={filter}
353
- onMinimize={() => setToggle("FILTER")}
354
- />
355
- )}
356
-
357
- {isSm && (
358
- <BottomSheetComponent
359
- show={!!toggle["MOBILE_OPTION"]}
360
- onClose={() => setToggle("MOBILE_OPTION", false)}
361
- maxSize="98vh"
362
- >
363
- <div className='flex flex-col gap-4 p-2'>
364
- {options?.filter((op, iop) => (iop != 0 && op != "CREATE" && op != "REFRESH"))?.map((option: ControlBarOptionType, key: number) => {
365
- {
366
- // =========================>
367
- // ## Search Field
368
- // =========================>
369
- }
370
- if (option == "SEARCH") {
371
- return (
372
- <div key={key}>
373
- <InputComponent
374
- name="search"
375
- placeholder="Cari disini..."
376
- rightIcon={faMagnifyingGlass}
377
- value={search}
378
- onChange={(e) => onSearch?.(e)}
379
- />
380
- </div>
381
- );
382
- }
383
-
384
- {
385
- // =========================>
386
- // ## Searchable Field
387
- // =========================>
388
- }
389
- if (option == "SEARCHABLE") {
390
- return searchableOptions?.length ? (
391
- <div key={key}>
392
- <SelectComponent
393
- name="searchableColumn"
394
- leftIcon={faSearch}
395
- options={searchableOptions?.map((column) => {
396
- return {
397
- label: column.label,
398
- value: column.selector,
399
- };
400
- }) || []}
401
- value={searchable}
402
- onChange={(e) => onSearchable?.(e as string[])}
403
- multiple
404
- />
405
- </div>
406
- ) : <></>;
407
- }
408
-
409
- {
410
- // =========================>
411
- // ## Selectable Button
412
- // =========================>
413
- }
414
- if (option == "SELECTABLE") {
415
- return (
416
- <div key={key}>
417
- <p className='input-label text-xs pb-2'>Kolom Ditampilkan</p>
418
- <InputCheckboxComponent
419
- vertical
420
- name="show_column"
421
- options={selectableOptions?.map((option) => {
422
- return {
423
- label: option.label as string,
424
- value: option.selector,
425
- };
426
- })}
427
- onChange={(e) => onSelectable?.(Array().concat(e).map((val) => String(val)))}
428
- value={selectable}
429
- className='px-2 border-0 gap-4 bg-transparent'
430
- classNameCheckbox='w-5 h-5 label::text-xs'
431
- />
432
- </div>
433
- );
434
- }
435
-
436
- {
437
- // =========================>
438
- // ## Sort Button
439
- // =========================>
440
- }
441
- if (option == "SORT") {
442
- return sortableOptions?.length ? (
443
- <div key={key}>
444
- <p className='input-label text-xs pb-2'>Urut Berdasarkan</p>
445
- <div className='flex flex-col'>
446
- {sortableOptions?.map((option, key) => {
447
- const sortBy = sort?.find((s) => s.split(" ")?.at(0) == option?.selector)?.split(" ")?.at(1) || "";
448
- return (
449
- <div
450
- key={key}
451
- className={cn('flex justify-between cursor-pointer text-sm p-2 hover:bg-light-primary active:scale-x-[102%]', !!sortBy && "text-primary bg-primary/10")}
452
- onClick={() => onChangeSort(option.selector)}
453
- >
454
- <p>{option.label}</p>
455
-
456
- {sortBy && (
457
- <div className='text-primary'>
458
- <FontAwesomeIcon icon={sortBy == "desc" ? faArrowDownZA : faArrowUpAZ} className='text-xs' />
459
- {sort?.length && sort?.length > 1 && <span className='text-[9px] ml-1'>{sort.findIndex((s) => s.split(" ")?.at(0) == option?.selector) + 1}</span>}
460
- </div>
461
- )}
462
- </div>
463
- )
464
- })}
465
- </div>
466
- </div>
467
- ) : <></>;
468
- }
469
-
470
- {
471
- // =========================>
472
- // ## Filter
473
- // =========================>
474
- }
475
- if (option == "FILTER") {
476
- return (
477
- <div key={key}>
478
- {filterableColumns && filterableColumns?.length && (
479
- <FilterComponent
480
- className='border-0 p-0 mb-2 title::text-xs'
481
- columns={filterableColumns}
482
- onChange={onFilter}
483
- value={filter}
484
- />
485
- )}
486
- </div>
487
- );
488
- }
489
-
490
- return option;
491
- })}
492
- </div>
493
- </BottomSheetComponent>
494
- )}
495
- </>
496
- )
497
- }
1
+ "use client"
2
+
3
+ import { ReactNode, useEffect, useRef } from 'react'
4
+ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
5
+ import { faArrowDownZA, faArrowUpAZ, faEllipsisV, faEyeLowVision, faMagnifyingGlass, faPlus, faRefresh, faSearch, faSliders, faSort } from '@fortawesome/free-solid-svg-icons';
6
+ import { ApiFilterType, cn, conversion, shortcut, useResponsive } from '@utils';
7
+ import { useToggleContext } from '@contexts';
8
+ import { IconButtonComponent, InputCheckboxComponent, InputComponent, SelectComponent, OutsideClickComponent, ButtonComponent, BottomSheetComponent, FilterComponent, FilterColumnOption } from '@components';
9
+
10
+
11
+
12
+ export type ControlBarOptionType = "SEARCH" | "SEARCHABLE" | "FILTER" | "SELECTABLE" | "REFRESH" | ReactNode;
13
+
14
+ export interface ControlBarProps {
15
+ id ?: string;
16
+ options ?: ControlBarOptionType[];
17
+ className ?: string
18
+ search ?: string,
19
+ onSearch ?: (searchable: string) => void,
20
+ searchableOptions ?: {label: string | ReactNode, selector: string}[]
21
+ searchable ?: string[],
22
+ onSearchable ?: (searchable: string[]) => void,
23
+ selectableOptions ?: {label: string | ReactNode, selector: string}[]
24
+ selectable ?: string[],
25
+ onSelectable ?: (searchable: string[]) => void,
26
+ sortableOptions ?: {label: string | ReactNode, selector: string}[]
27
+ sort ?: string[],
28
+ onSort ?: (sort: string[]) => void,
29
+ filterableColumns ?: FilterColumnOption[],
30
+ onFilter ?: (filters: ApiFilterType[]) => void,
31
+ filter ?: ApiFilterType[],
32
+ onRefresh ?: () => void,
33
+ }
34
+
35
+
36
+
37
+ export function ControlBarComponent({
38
+ id = "",
39
+ options,
40
+ className,
41
+ search,
42
+ onSearch,
43
+ searchableOptions,
44
+ searchable,
45
+ onSearchable,
46
+ selectableOptions,
47
+ selectable,
48
+ onSelectable,
49
+ sortableOptions,
50
+ sort,
51
+ onSort,
52
+ filterableColumns,
53
+ onFilter,
54
+ filter,
55
+ onRefresh
56
+ }: ControlBarProps) {
57
+ const {toggle, setToggle} = useToggleContext()
58
+ const { isSm } = useResponsive();
59
+
60
+ const searchRef = useRef<HTMLInputElement | null>(null);
61
+
62
+ useEffect(() => {
63
+ if (options?.includes("SEARCH")) {
64
+ shortcut.register("ctrl+s", () => {
65
+ searchRef.current?.focus()
66
+ }, "Cari")
67
+ }
68
+
69
+ if (options?.includes("FILTER")) {
70
+ shortcut.register("ctrl+f", () => {
71
+ setToggle("FILTER")
72
+ }, "Filter")
73
+ }
74
+
75
+ if (options?.includes("SORT")) {
76
+ shortcut.register("ctrl+o", () => {
77
+ setToggle("SORT")
78
+ }, "Urutkan")
79
+ }
80
+
81
+ if (options?.includes("SELECTABLE")) {
82
+ shortcut.register("ctrl+l", () => {
83
+ setToggle("SELECTABLE")
84
+ }, "Kolom Ditampilkan")
85
+ }
86
+
87
+ if (options?.includes("REFRESH")) {
88
+ shortcut.register("ctrl+shift+r", () => {
89
+ onRefresh?.()
90
+ }, "Refresh Tabel")
91
+ }
92
+
93
+ return () => {
94
+ options?.includes("SEARCH") && shortcut.unregister("ctrl+s")
95
+ options?.includes("FILTER") && shortcut.unregister("ctrl+f")
96
+ options?.includes("SORT") && shortcut.unregister("ctrl+o")
97
+ options?.includes("SELECTABLE") && shortcut.unregister("ctrl+l")
98
+ options?.includes("REFRESH") && shortcut.unregister("ctrl+shift+r")
99
+ }
100
+ }, [options])
101
+
102
+ const onChangeSort = (item: string) => {
103
+ if(!!sort?.find((s) => s.split(" ")?.at(0) == item)) {
104
+ const findSort = sort.find((s) => s.split(" ")?.at(0) == item);
105
+
106
+ if (findSort?.split(" ")?.at(1) == "desc") {
107
+ onSort?.(sort.filter((s) => s != findSort));
108
+ } else {
109
+ const newSorts = [...sort];
110
+ newSorts[newSorts?.findIndex((s) => s == findSort)] = `${item} desc`
111
+ onSort?.(newSorts);
112
+ }
113
+ } else {
114
+ onSort?.([...(sort || []), `${item} asc`])
115
+ }
116
+ }
117
+
118
+ return (
119
+ <>
120
+ <div className={cn("py-1 md:py-2 md:px-1.5 bg-white rounded-[6px] border flex items-center mb-2", className)}>
121
+ {(isSm ? [
122
+ ...(options?.filter((op, iop) => iop == 0 || op == "REFRESH") || []),
123
+ ...(options && options?.length > 1 ? ['MOBILE_OPTION'] : [])
124
+ ] : options)?.map((option: ControlBarOptionType, key: number) => {
125
+ {
126
+ // =========================>
127
+ // ## Create button
128
+ // =========================>
129
+ }
130
+ if (option == "CREATE") {
131
+ return (
132
+ <div className="pl-1.5 pr-3 mr-2 border-r" key="button-add">
133
+ <ButtonComponent
134
+ icon={faPlus}
135
+ label="Tambah Data"
136
+ size="sm"
137
+ onClick={() => setToggle(`MODAL_FORM_${conversion.strSnake(id).toUpperCase()}`)}
138
+ />
139
+ </div>
140
+ );
141
+ }
142
+
143
+ {
144
+ // =========================>
145
+ // ## Search Field
146
+ // =========================>
147
+ }
148
+ if (option == "SEARCH") {
149
+ const searchable = !!options?.find((option) => option == "SEARCHABLE");
150
+
151
+ return (
152
+ <div className={cn("w-full min-w-[150px]", searchable ? "pr-1.5" : "px-1.5")} key={key}>
153
+ <InputComponent
154
+ ref={searchRef}
155
+ name="search"
156
+ placeholder="Cari disini..."
157
+ rightIcon={faMagnifyingGlass}
158
+ value={search}
159
+ onChange={(e) => onSearch?.(e)}
160
+ className={cn("py-1.5 text-sm", searchable && "rounded-l-none")}
161
+ />
162
+ </div>
163
+ );
164
+ }
165
+
166
+ {
167
+ // =========================>
168
+ // ## Searchable Field
169
+ // =========================>
170
+ }
171
+ if (option == "SEARCHABLE") {
172
+ return searchableOptions?.length ? (
173
+ <div className="w-28 pl-1.5" key={key}>
174
+ <SelectComponent
175
+ name="searchableColumn"
176
+ leftIcon={faSearch}
177
+ options={searchableOptions?.map((column) => {
178
+ return {
179
+ label: column.label,
180
+ value: column.selector,
181
+ };
182
+ }) || []}
183
+ value={searchable}
184
+ onChange={(e) => onSearchable?.(e as string[])}
185
+ className="py-1.5 text-sm rounded-r-none border-r-0"
186
+ multiple
187
+ />
188
+ </div>
189
+ ) : <></>;
190
+ }
191
+
192
+ {
193
+ // =========================>
194
+ // ## Selectable Button
195
+ // =========================>
196
+ }
197
+ if (option == "SELECTABLE") {
198
+ return (
199
+ <div className="px-1.5 rounded-md relative" key={key}>
200
+ <IconButtonComponent
201
+ icon={faEyeLowVision}
202
+ variant="outline"
203
+ className="!text-foreground p-4"
204
+ onClick={() => setToggle("SELECTABLE")}
205
+ size="sm"
206
+ />
207
+ <OutsideClickComponent onOutsideClick={() => setToggle("SELECTABLE", false)}>
208
+ <div
209
+ className={cn(
210
+ "absolute -bottom-4 bg-white translate-y-full right-0 w-[240px] z-20 rounded-lg border",
211
+ !toggle.SELECTABLE && "scale-y-0 top-0 opacity-0"
212
+ )}
213
+ >
214
+ <p className='input-label text-xs p-4'>Kolom Ditampilkan</p>
215
+ <InputCheckboxComponent
216
+ vertical
217
+ name="show_column"
218
+ options={selectableOptions?.map((option) => {
219
+ return {
220
+ label: option.label as string,
221
+ value: option.selector,
222
+ };
223
+ })}
224
+ onChange={(e) => onSelectable?.(Array().concat(e).map((val) => String(val)))}
225
+ value={selectable}
226
+ className='px-4 border-0 gap-4 mb-4'
227
+ classNameCheckbox='w-5 h-5 label::text-xs'
228
+ />
229
+ </div>
230
+ </OutsideClickComponent>
231
+ </div>
232
+ );
233
+ }
234
+
235
+ {
236
+ // =========================>
237
+ // ## Sort Button
238
+ // =========================>
239
+ }
240
+ if (option == "SORT") {
241
+ return sortableOptions?.length ? (
242
+ <div className="px-1.5 rounded-md relative" key={key}>
243
+ <IconButtonComponent
244
+ icon={faSort}
245
+ variant="outline"
246
+ className="!text-foreground p-4"
247
+ onClick={() => setToggle("SORT")}
248
+ size="sm"
249
+ />
250
+ <OutsideClickComponent onOutsideClick={() => setToggle("SORT", false)}>
251
+ <div
252
+ className={cn(
253
+ "absolute -bottom-4 bg-white translate-y-full right-0 w-[240px] z-20 rounded-lg border",
254
+ !toggle.SORT && "scale-y-0 top-0 opacity-0"
255
+ )}
256
+ >
257
+ <p className='input-label text-xs p-4'>Urut Berdasarkan</p>
258
+ <div className='flex flex-col mb-4'>
259
+ {sortableOptions?.map((option, key) => {
260
+ const sortBy = sort?.find((s) => s.split(" ")?.at(0) == option?.selector)?.split(" ")?.at(1) || "";
261
+ return (
262
+ <div
263
+ key={key}
264
+ className={cn('flex justify-between cursor-pointer text-sm px-4 py-2 hover:bg-light-primary', !!sortBy && "text-primary bg-primary/10")}
265
+ onClick={() => onChangeSort(option.selector)}
266
+ >
267
+ <p>{option.label}</p>
268
+
269
+ {sortBy && (
270
+ <div className='text-primary'>
271
+ <FontAwesomeIcon icon={sortBy == "desc" ? faArrowDownZA : faArrowUpAZ} className='text-xs' />
272
+ {sort?.length && sort?.length > 1 && <span className='text-[9px] ml-1'>{sort.findIndex((s) => s.split(" ")?.at(0) == option?.selector) + 1}</span>}
273
+ </div>
274
+ )}
275
+ </div>
276
+ )
277
+ })}
278
+ </div>
279
+ </div>
280
+ </OutsideClickComponent>
281
+ </div>
282
+ ) : <></>;
283
+ }
284
+
285
+ {
286
+ // =========================>
287
+ // ## Refresh Button
288
+ // =========================>
289
+ }
290
+ if (option == "REFRESH") {
291
+ return (
292
+ <div className="md:px-1.5 relative" key={key}>
293
+ <IconButtonComponent
294
+ icon={faRefresh}
295
+ variant="outline"
296
+ className="!text-foreground p-4"
297
+ onClick={() => onRefresh?.()}
298
+ size="sm"
299
+ />
300
+ </div>
301
+ );
302
+ }
303
+
304
+ {
305
+ // =========================>
306
+ // ## Filter Button
307
+ // =========================>
308
+ }
309
+ if (option == "FILTER") {
310
+ return (
311
+ <div className="px-1.5 rounded-md relative" key={key}>
312
+ <ButtonComponent
313
+ icon={faSliders}
314
+ label="Filter"
315
+ variant="outline"
316
+ className="!text-foreground"
317
+ onClick={() => setToggle("FILTER")}
318
+ size="sm"
319
+ />
320
+ </div>
321
+ );
322
+ }
323
+
324
+ {
325
+ // =========================>
326
+ // ## Mobile option button
327
+ // =========================>
328
+ }
329
+ if (option == "MOBILE_OPTION") {
330
+ return (
331
+ <div className="px-1.5 relative" key={key}>
332
+ <IconButtonComponent
333
+ icon={faEllipsisV}
334
+ variant="outline"
335
+ className="!text-foreground p-4"
336
+ onClick={() => setToggle("MOBILE_OPTION")}
337
+ size="sm"
338
+ />
339
+ </div>
340
+ );
341
+ }
342
+
343
+ return option;
344
+ })}
345
+ </div>
346
+
347
+ {!!filterableColumns && !!filterableColumns?.length && (
348
+ <FilterComponent
349
+ className={cn("", !toggle.FILTER ? "p-0 h-0 hidden overflow-hidden" : "mb-2 animate-intro-down")}
350
+ columns={filterableColumns}
351
+ onChange={onFilter}
352
+ value={filter}
353
+ onMinimize={() => setToggle("FILTER")}
354
+ />
355
+ )}
356
+
357
+ {isSm && (
358
+ <BottomSheetComponent
359
+ show={!!toggle["MOBILE_OPTION"]}
360
+ onClose={() => setToggle("MOBILE_OPTION", false)}
361
+ maxSize="98vh"
362
+ >
363
+ <div className='flex flex-col gap-4 p-2'>
364
+ {options?.filter((op, iop) => (iop != 0 && op != "CREATE" && op != "REFRESH"))?.map((option: ControlBarOptionType, key: number) => {
365
+ {
366
+ // =========================>
367
+ // ## Search Field
368
+ // =========================>
369
+ }
370
+ if (option == "SEARCH") {
371
+ return (
372
+ <div key={key}>
373
+ <InputComponent
374
+ name="search"
375
+ placeholder="Cari disini..."
376
+ rightIcon={faMagnifyingGlass}
377
+ value={search}
378
+ onChange={(e) => onSearch?.(e)}
379
+ />
380
+ </div>
381
+ );
382
+ }
383
+
384
+ {
385
+ // =========================>
386
+ // ## Searchable Field
387
+ // =========================>
388
+ }
389
+ if (option == "SEARCHABLE") {
390
+ return searchableOptions?.length ? (
391
+ <div key={key}>
392
+ <SelectComponent
393
+ name="searchableColumn"
394
+ leftIcon={faSearch}
395
+ options={searchableOptions?.map((column) => {
396
+ return {
397
+ label: column.label,
398
+ value: column.selector,
399
+ };
400
+ }) || []}
401
+ value={searchable}
402
+ onChange={(e) => onSearchable?.(e as string[])}
403
+ multiple
404
+ />
405
+ </div>
406
+ ) : <></>;
407
+ }
408
+
409
+ {
410
+ // =========================>
411
+ // ## Selectable Button
412
+ // =========================>
413
+ }
414
+ if (option == "SELECTABLE") {
415
+ return (
416
+ <div key={key}>
417
+ <p className='input-label text-xs pb-2'>Kolom Ditampilkan</p>
418
+ <InputCheckboxComponent
419
+ vertical
420
+ name="show_column"
421
+ options={selectableOptions?.map((option) => {
422
+ return {
423
+ label: option.label as string,
424
+ value: option.selector,
425
+ };
426
+ })}
427
+ onChange={(e) => onSelectable?.(Array().concat(e).map((val) => String(val)))}
428
+ value={selectable}
429
+ className='px-2 border-0 gap-4 bg-transparent'
430
+ classNameCheckbox='w-5 h-5 label::text-xs'
431
+ />
432
+ </div>
433
+ );
434
+ }
435
+
436
+ {
437
+ // =========================>
438
+ // ## Sort Button
439
+ // =========================>
440
+ }
441
+ if (option == "SORT") {
442
+ return sortableOptions?.length ? (
443
+ <div key={key}>
444
+ <p className='input-label text-xs pb-2'>Urut Berdasarkan</p>
445
+ <div className='flex flex-col'>
446
+ {sortableOptions?.map((option, key) => {
447
+ const sortBy = sort?.find((s) => s.split(" ")?.at(0) == option?.selector)?.split(" ")?.at(1) || "";
448
+ return (
449
+ <div
450
+ key={key}
451
+ className={cn('flex justify-between cursor-pointer text-sm p-2 hover:bg-light-primary active:scale-x-[102%]', !!sortBy && "text-primary bg-primary/10")}
452
+ onClick={() => onChangeSort(option.selector)}
453
+ >
454
+ <p>{option.label}</p>
455
+
456
+ {sortBy && (
457
+ <div className='text-primary'>
458
+ <FontAwesomeIcon icon={sortBy == "desc" ? faArrowDownZA : faArrowUpAZ} className='text-xs' />
459
+ {sort?.length && sort?.length > 1 && <span className='text-[9px] ml-1'>{sort.findIndex((s) => s.split(" ")?.at(0) == option?.selector) + 1}</span>}
460
+ </div>
461
+ )}
462
+ </div>
463
+ )
464
+ })}
465
+ </div>
466
+ </div>
467
+ ) : <></>;
468
+ }
469
+
470
+ {
471
+ // =========================>
472
+ // ## Filter
473
+ // =========================>
474
+ }
475
+ if (option == "FILTER") {
476
+ return (
477
+ <div key={key}>
478
+ {filterableColumns && filterableColumns?.length && (
479
+ <FilterComponent
480
+ className='border-0 p-0 mb-2 title::text-xs'
481
+ columns={filterableColumns}
482
+ onChange={onFilter}
483
+ value={filter}
484
+ />
485
+ )}
486
+ </div>
487
+ );
488
+ }
489
+
490
+ return option;
491
+ })}
492
+ </div>
493
+ </BottomSheetComponent>
494
+ )}
495
+ </>
496
+ )
497
+ }