@skalfa/skalfa-app 1.0.3 → 1.0.6

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 (90) hide show
  1. package/.env.example +8 -16
  2. package/app/auth/edit/page.tsx +1 -1
  3. package/app/auth/login/page.tsx +1 -1
  4. package/app/auth/me/page.tsx +1 -1
  5. package/app/auth/register/page.tsx +1 -1
  6. package/app/auth/verify/page.tsx +1 -1
  7. package/app/dashboard/layout.tsx +2 -2
  8. package/app/dashboard/page.tsx +1 -1
  9. package/app/index.ts +1 -0
  10. package/app/layout.tsx +2 -4
  11. package/app/page.tsx +2 -2
  12. package/bun.lock +7 -2
  13. package/components/index.ts +1 -3
  14. package/package.json +10 -7
  15. package/styles/components.css +1392 -0
  16. package/styles/globals.css +40 -175
  17. package/styles/utilities.css +37 -0
  18. package/tsconfig.json +4 -2
  19. package/utils/commands/skalfa.ts +1 -1
  20. package/components/base.components/accordion/Accordion.component.tsx +0 -82
  21. package/components/base.components/breadcrumb/Breadcrumb.component.tsx +0 -80
  22. package/components/base.components/button/Button.component.tsx +0 -91
  23. package/components/base.components/button/IconButton.component.tsx +0 -88
  24. package/components/base.components/button/button.decorate.ts +0 -82
  25. package/components/base.components/card/AlertCard.component.tsx +0 -69
  26. package/components/base.components/card/Card.component.tsx +0 -25
  27. package/components/base.components/card/DashboardCard.component.tsx +0 -44
  28. package/components/base.components/card/GalleryCard.component.tsx +0 -50
  29. package/components/base.components/card/ProductCard.component.tsx +0 -65
  30. package/components/base.components/card/ProfileCard.component.tsx +0 -71
  31. package/components/base.components/carousel/Carousel.component.tsx +0 -113
  32. package/components/base.components/chip/Chip.component.tsx +0 -39
  33. package/components/base.components/document/DocumentViewer.component.tsx +0 -164
  34. package/components/base.components/document/ExportExcel.component.tsx +0 -340
  35. package/components/base.components/document/ImportExcel.component.tsx +0 -315
  36. package/components/base.components/document/PrintTable.component.tsx +0 -204
  37. package/components/base.components/document/RenderPDF.component.tsx +0 -416
  38. package/components/base.components/index.ts +0 -85
  39. package/components/base.components/input/Checkbox.component.tsx +0 -109
  40. package/components/base.components/input/Input.component.tsx +0 -332
  41. package/components/base.components/input/InputCheckbox.component.tsx +0 -174
  42. package/components/base.components/input/InputCurrency.component.tsx +0 -163
  43. package/components/base.components/input/InputDate.component.tsx +0 -352
  44. package/components/base.components/input/InputDatetime.component.tsx +0 -260
  45. package/components/base.components/input/InputDocument.component.tsx +0 -352
  46. package/components/base.components/input/InputImage.component.tsx +0 -533
  47. package/components/base.components/input/InputMap.component.tsx +0 -318
  48. package/components/base.components/input/InputNumber.component.tsx +0 -192
  49. package/components/base.components/input/InputOtp.component.tsx +0 -169
  50. package/components/base.components/input/InputPassword.component.tsx +0 -236
  51. package/components/base.components/input/InputRadio.component.tsx +0 -175
  52. package/components/base.components/input/InputTime.component.tsx +0 -276
  53. package/components/base.components/input/InputValues.component.tsx +0 -68
  54. package/components/base.components/input/Radio.component.tsx +0 -102
  55. package/components/base.components/input/Select.component.tsx +0 -541
  56. package/components/base.components/modal/BottomSheet.component.tsx +0 -246
  57. package/components/base.components/modal/FloatingPage.component.tsx +0 -104
  58. package/components/base.components/modal/Modal.component.tsx +0 -96
  59. package/components/base.components/modal/ModalConfirm.component.tsx +0 -218
  60. package/components/base.components/modal/Toast.component.tsx +0 -126
  61. package/components/base.components/nav/Bottombar.component.tsx +0 -116
  62. package/components/base.components/nav/Footer.component.tsx +0 -144
  63. package/components/base.components/nav/Headbar.component.tsx +0 -104
  64. package/components/base.components/nav/Navbar.component.tsx +0 -100
  65. package/components/base.components/nav/Sidebar.component.tsx +0 -301
  66. package/components/base.components/nav/Tabbar.component.tsx +0 -60
  67. package/components/base.components/nav/Wizard.component.tsx +0 -73
  68. package/components/base.components/supervision/FormSupervision.component.tsx +0 -434
  69. package/components/base.components/supervision/TableSupervision.component.tsx +0 -697
  70. package/components/base.components/table/ControlBar.component.tsx +0 -497
  71. package/components/base.components/table/FilterComponent.tsx +0 -518
  72. package/components/base.components/table/Pagination.component.tsx +0 -159
  73. package/components/base.components/table/Table.component.tsx +0 -469
  74. package/components/base.components/typography/TypographyArticle.component.tsx +0 -26
  75. package/components/base.components/typography/TypographyColumn.component.tsx +0 -20
  76. package/components/base.components/typography/TypographyContent.component.tsx +0 -20
  77. package/components/base.components/typography/TypographyTips.component.tsx +0 -20
  78. package/components/base.components/wrap/Draggable.component.tsx +0 -303
  79. package/components/base.components/wrap/IDBProvider.tsx +0 -12
  80. package/components/base.components/wrap/Image.component.tsx +0 -10
  81. package/components/base.components/wrap/OutsideClick.component.tsx +0 -48
  82. package/components/base.components/wrap/ScrollContainer.component.tsx +0 -104
  83. package/components/base.components/wrap/ShortcutProvider.tsx +0 -57
  84. package/components/base.components/wrap/Swipe.component.tsx +0 -93
  85. package/components/construct.components/example.tsx +0 -1
  86. package/components/construct.components/index.ts +0 -5
  87. package/components/structure.components/example.tsx +0 -1
  88. package/components/structure.components/index.ts +0 -5
  89. package/schema/idb/app.schema.ts +0 -9
  90. package/schema/index.ts +0 -5
@@ -1,236 +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, useValidation, validation, ValidationRules } from "@utils";
6
-
7
-
8
-
9
- type CT = "label" | "tip" | "error" | "base" | "icon";
10
-
11
- export interface InputPasswordProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "onChange"> {
12
- label ?: string;
13
- tip ?: string | ReactNode;
14
- leftIcon ?: any;
15
- rightIcon ?: any;
16
-
17
- value ?: string;
18
- invalid ?: string;
19
- validations ?: ValidationRules;
20
-
21
- onChange ?: (value: string, confirm?: string) => any;
22
- register ?: (name: string, validations?: ValidationRules) => void;
23
- unregister ?: (name: string) => void;
24
-
25
- /** Use custom class with: "label::", "tip::", "error::", "icon::". */
26
- className ?: string;
27
- }
28
-
29
-
30
-
31
- export function InputPasswordComponent({
32
- label,
33
- tip,
34
- leftIcon,
35
- rightIcon,
36
-
37
- value,
38
- invalid,
39
- validations,
40
-
41
- register,
42
- unregister,
43
- onChange,
44
-
45
- className = "",
46
- ...props
47
- }: InputPasswordProps) {
48
- const [password, setPassword] = useState("");
49
- const [confirmPassword, setConfirmPassword] = useState("");
50
- const [strength, setStrength] = useState<"weak" | "strong" | "excellent" | "">("");
51
-
52
-
53
- // =========================>
54
- // ## Initial
55
- // =========================>
56
- const inputHandler = useInputHandler(props.name, value, validations, register, unregister, false)
57
- const randomId = useInputRandomId()
58
- const randomConfirmId = useInputRandomId()
59
-
60
-
61
- // =========================>
62
- // ## Invalid handler
63
- // =========================>
64
- const [invalidMessage] = useValidation(inputHandler.value, validations, invalid, inputHandler.idle);
65
-
66
-
67
- // =========================>
68
- // ## Password strength handler
69
- // =========================>
70
- useEffect(() => {
71
- if (!password) return setStrength("");
72
-
73
- const hasLetter = /[A-Za-z]/.test(password);
74
- const hasNumber = /\d/.test(password);
75
- const hasSymbol = /[^A-Za-z0-9]/.test(password);
76
-
77
- if (hasLetter && !hasNumber && !hasSymbol) setStrength("weak");
78
- else if (hasLetter && hasNumber && !hasSymbol) setStrength("strong");
79
- else if (hasLetter && hasNumber && hasSymbol) setStrength("excellent");
80
- else setStrength("weak");
81
- }, [password]);
82
-
83
-
84
- // =========================>
85
- // ## Check match confirm password
86
- // =========================>
87
- const isConfirmMismatch = confirmPassword && password !== confirmPassword;
88
-
89
-
90
- return (
91
- <div className="relative flex flex-col gap-y-1">
92
- {label && (
93
- <label
94
- htmlFor={randomId}
95
- className={cn(
96
- "input-label",
97
- pcn<CT>(className, "label"),
98
- props.disabled && "opacity-50",
99
- inputHandler.focus && "text-primary",
100
- !!invalidMessage && "text-danger",
101
- )}
102
- >
103
- {label}
104
- {validations && validation.hasRules(validations, "required") && <span className="text-danger ml-1">*</span>}
105
- </label>
106
- )}
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
- <div className="relative">
119
- <input
120
- {...props}
121
- type="password"
122
- id={randomId}
123
- className={cn(
124
- "input",
125
- leftIcon && "pl-12",
126
- rightIcon && "pr-12",
127
- pcn<CT>(className, "base"),
128
- !!invalidMessage && "input-error",
129
- )}
130
- value={password}
131
- onChange={(e) => {
132
- setPassword(e.target.value);
133
- inputHandler.setIdle(false);
134
- onChange?.(e.target.value, confirmPassword);
135
- }}
136
- onFocus={(e) => {
137
- props.onFocus?.(e);
138
- inputHandler.setFocus(true);
139
- }}
140
- onBlur={(e) => {
141
- props.onBlur?.(e);
142
- setTimeout(() => inputHandler.setFocus(false), 100);
143
- }}
144
- autoComplete="off"
145
- />
146
-
147
- {leftIcon && (
148
- <FontAwesomeIcon
149
- className={cn("left-4 input-icon", pcn<CT>(className, "icon"))}
150
- icon={leftIcon}
151
- />
152
- )}
153
- {rightIcon && (
154
- <FontAwesomeIcon
155
- className={cn("right-4 input-icon", pcn<CT>(className, "icon"))}
156
- icon={rightIcon}
157
- />
158
- )}
159
- </div>
160
-
161
- {invalidMessage && (
162
- <small className={cn("input-error-message", "text-danger mt-1")}>
163
- {invalidMessage}
164
- </small>
165
- )}
166
-
167
- {strength && (
168
- <div className="flex items-center gap-2 mt-1">
169
- <div
170
- className={cn(
171
- "h-1 rounded transition-all duration-300 w-1/3",
172
- strength === "weak" && "bg-danger",
173
- strength === "strong" && "bg-warning",
174
- strength === "excellent" && "bg-success",
175
- )}
176
- />
177
- <div
178
- className={cn(
179
- "h-1 rounded transition-all duration-300 w-1/3",
180
- strength === "weak" && "bg-background",
181
- strength === "strong" && "bg-warning",
182
- strength === "excellent" && "bg-success",
183
- )}
184
- />
185
- <div
186
- className={cn(
187
- "h-1 rounded transition-all duration-300 w-1/3",
188
- strength === "weak" && "bg-background ",
189
- strength === "strong" && "bg-background",
190
- strength === "excellent" && "bg-success",
191
- )}
192
- />
193
- <span
194
- className={cn(
195
- "text-[10px] font-medium",
196
- strength === "weak" && "text-danger",
197
- strength === "strong" && "text-warning",
198
- strength === "excellent" && "text-success",
199
- )}
200
- >{strength === "weak" ? "Weak" : strength === "strong" ? "Strong" : "Excellent"}</span>
201
- </div>
202
- )}
203
-
204
- <div className="mt-4">
205
- <label
206
- htmlFor={randomConfirmId}
207
- className={cn("input-label text-sm", pcn<CT>(className, "label"))}
208
- >Password Confirm</label>
209
- <div className="relative">
210
- <input
211
- {...props}
212
- id={randomConfirmId}
213
- type="password"
214
- className={cn(
215
- "input",
216
- leftIcon && "pl-12",
217
- rightIcon && "pr-12",
218
- pcn<CT>(className, "base"),
219
- isConfirmMismatch && "input-error",
220
- )}
221
- value={confirmPassword}
222
- onChange={(e) => {
223
- setConfirmPassword(e.target.value);
224
- onChange?.(password, e.target.value);
225
- }}
226
- autoComplete="off"
227
- />
228
- </div>
229
- </div>
230
-
231
- {isConfirmMismatch && (
232
- <small className={cn("input-error-message", "text-danger mt-1")}>Password confirmation not match</small>
233
- )}
234
- </div>
235
- );
236
- }
@@ -1,175 +0,0 @@
1
- "use client"
2
-
3
- import { ReactNode, useEffect, useState } from "react";
4
- import { api, ApiType, cn, pcn, useInputHandler, useValidation, validation, ValidationRules } from "@utils";
5
- import { RadioComponent } from "@components";
6
-
7
-
8
-
9
- type CT = "label" | "tip" | "error" | "input" | "icon";
10
-
11
- export type InputRadioOptionProps = {
12
- value: string | number;
13
- label: string;
14
- };
15
-
16
- export type InputRadioProps = {
17
- name : string;
18
- label ?: string;
19
- tip ?: string | ReactNode;
20
- vertical ?: boolean;
21
-
22
- value ?: string | number;
23
- disabled ?: boolean;
24
- invalid ?: string;
25
- options ?: InputRadioOptionProps[];
26
- serverOptionControl ?: ApiType;
27
- customOptions ?: any;
28
- validations ?: ValidationRules;
29
-
30
- onChange ?: (value: string | number) => any;
31
- register ?: (name: string, validations?: ValidationRules) => void;
32
- unregister ?: (name: string) => void;
33
-
34
- /** Use custom class with: "label::", "tip::", "error::", "icon::", "suggest::", "suggest-item::". */
35
- className ?: string;
36
- /** Use custom class with: "label::", "checked::", "error::". */
37
- classNameCheckbox ?: string;
38
- };
39
-
40
-
41
-
42
- export function InputRadioComponent({
43
- name,
44
- label,
45
- tip,
46
- vertical,
47
-
48
- value,
49
- disabled,
50
- invalid,
51
-
52
- options,
53
- serverOptionControl,
54
- customOptions,
55
- validations,
56
-
57
- onChange,
58
- register,
59
- unregister,
60
-
61
- className = "",
62
- classNameCheckbox = "",
63
- }: InputRadioProps) {
64
- const [dataOptions, setDataOptions] = useState<InputRadioOptionProps[]>([]);
65
- const [loading, setLoading] = useState(false);
66
-
67
-
68
- // =========================>
69
- // ## Initial
70
- // =========================>
71
- const inputHandler = useInputHandler(name, value, validations, register, unregister, false)
72
-
73
-
74
- // =========================>
75
- // ## Invalid handler
76
- // =========================>
77
- const [invalidMessage] = useValidation(inputHandler.value, validations, invalid, inputHandler.idle);
78
-
79
-
80
- // =========================>
81
- // ## Fetch option
82
- // =========================>
83
- useEffect(() => {
84
- const fetchOptions = async () => {
85
- setLoading(true);
86
- const mutateOptions = await api(serverOptionControl || {});
87
- if (mutateOptions?.status == 200) {
88
- customOptions
89
- ? setDataOptions([customOptions, ...mutateOptions.data])
90
- : setDataOptions(mutateOptions.data);
91
- setLoading(false);
92
- }
93
- };
94
-
95
- if (serverOptionControl?.path || serverOptionControl?.url) {
96
- fetchOptions();
97
- } else {
98
- !options && setDataOptions([]);
99
- }
100
- }, [serverOptionControl?.path, serverOptionControl?.url]);
101
-
102
-
103
- return (
104
- <>
105
- <div className="w-full relative flex flex-col gap-y-0.5">
106
- <label
107
- className={cn(
108
- "input-label",
109
- pcn<CT>(className, "label"),
110
- disabled && "opacity-50",
111
- disabled && pcn<CT>(className, "label", "disabled"),
112
- !!invalidMessage && "text-danger",
113
- !!invalidMessage && pcn<CT>(className, "label", "focus"),
114
- )}
115
- >
116
- {label}
117
- {validations && validation.hasRules(validations, "required") && <span className="text-danger ml-1">*</span>}
118
- </label>
119
-
120
- {tip && (
121
- <small
122
- className={cn(
123
- "input-tip",
124
- pcn<CT>(className, "tip"),
125
- disabled && "opacity-60",
126
- disabled && pcn<CT>(className, "tip", "disabled"),
127
- )}
128
- >{tip}</small>
129
- )}
130
-
131
- <div
132
- className={cn(
133
- `input overflow-auto input-scroll w-full flex flex-nowrap gap-y-2 gap-4 ${
134
- vertical && `flex-col flex-wrap ${vertical}`
135
- }`,
136
- pcn<CT>(className, "input"),
137
- !!invalidMessage && "input-error",
138
- !!invalidMessage && pcn<CT>(className, "input", "error"),
139
- )}
140
- >
141
- {loading && (vertical ? [1, 2, 3, 4, 5, 6, 7, 8, 9] : [1, 2, 3]).map((_, key) => {
142
- return <div key={key} className="w-1/3 h-6 rounded-lg"></div>;
143
- })}
144
-
145
- {(options || dataOptions) &&
146
- (options || dataOptions)?.map((option, key) => {
147
- return (
148
- <RadioComponent
149
- key={key}
150
- label={option.label}
151
- name={`option[${option.value}]#${name}`}
152
- checked={inputHandler.value == option.value}
153
- disabled={disabled}
154
- className={classNameCheckbox}
155
- onChange={() => {
156
- if (inputHandler.value == option.value) {
157
- inputHandler.setValue("");
158
- onChange?.("");
159
- } else {
160
- inputHandler.setValue(option.value || "");
161
- onChange?.(option.value || "");
162
- }
163
- }}
164
- />
165
- );
166
- })}
167
- </div>
168
-
169
- {invalidMessage && (
170
- <small className={cn("input-error-message", pcn<CT>(className, "error"))}>{invalidMessage}</small>
171
- )}
172
- </div>
173
- </>
174
- );
175
- }
@@ -1,276 +0,0 @@
1
- "use client"
2
-
3
- import { FC, InputHTMLAttributes, ReactNode, useEffect, useMemo, useState } from "react";
4
- import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
5
- import { cn, pcn, useInputHandler, useInputRandomId, useResponsive, useValidation, validation, ValidationRules } from "@utils";
6
- import { BottomSheetComponent, ButtonComponent, OutsideClickComponent } from "@components";
7
-
8
-
9
-
10
- type CT = "label" | "tip" | "error" | "input"| "icon";
11
-
12
- export interface InputTimeProps 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::". */
27
- className ?: string;
28
- }
29
-
30
-
31
-
32
- export function InputTimeComponent({
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
- }: InputTimeProps) {
49
- const { isSm } = useResponsive();
50
-
51
- // =========================>
52
- // ## Initial
53
- // =========================>
54
- const inputHandler = useInputHandler(props.name, value, validations, register, unregister, false)
55
- const randomId = useInputRandomId()
56
-
57
-
58
- // =========================>
59
- // ## Invalid handler
60
- // =========================>
61
- const [invalidMessage] = useValidation(inputHandler.value, validations, invalid, inputHandler.idle);
62
-
63
-
64
- return (
65
- <>
66
- <div className="relative flex flex-col gap-y-0.5">
67
- <label
68
- htmlFor={randomId}
69
- className={cn(
70
- "input-label",
71
- pcn<CT>(className, "label"),
72
- props.disabled && "opacity-50",
73
- inputHandler.focus && "text-primary",
74
- !!invalidMessage && "text-danger"
75
- )}
76
- >
77
- {label}
78
- {validations && validation.hasRules(validations, "required") && <span className="text-danger ml-1">*</span>}
79
- </label>
80
-
81
- {tip && (
82
- <small
83
- className={cn(
84
- "input-tip",
85
- pcn<CT>(className, "tip"),
86
- props.disabled && "opacity-60"
87
- )}
88
- >{tip}</small>
89
- )}
90
-
91
- <OutsideClickComponent onOutsideClick={!isSm ? () => inputHandler.setFocus(false) : undefined}>
92
- <div className="relative">
93
- <input
94
- {...props}
95
- id={randomId}
96
- className={cn(
97
- "input",
98
- leftIcon && "pl-12",
99
- rightIcon && "pr-12",
100
- pcn<CT>(className, "input"),
101
- !!invalidMessage && "input-error"
102
- )}
103
- value={inputHandler.value}
104
- onChange={(e) => {
105
- inputHandler.setValue(e.target.value);
106
- inputHandler.setIdle(false);
107
- onChange?.(e.target.value);
108
- }}
109
- onFocus={(e) => {
110
- props.onFocus?.(e);
111
- inputHandler.setFocus(true);
112
- }}
113
- autoComplete="off"
114
- inputMode={isSm ? "none" : undefined}
115
- />
116
-
117
- {leftIcon && (
118
- <FontAwesomeIcon
119
- className={cn(
120
- "left-4 input-icon",
121
- pcn<CT>(className, "icon"),
122
- props.disabled && "opacity-60",
123
- inputHandler.focus && "text-primary"
124
- )}
125
- icon={leftIcon}
126
- />
127
- )}
128
-
129
- {rightIcon && (
130
- <FontAwesomeIcon
131
- className={cn(
132
- "right-4 input-icon",
133
- pcn<CT>(className, "icon"),
134
- props.disabled && "opacity-60",
135
- inputHandler.focus && "text-primary"
136
- )}
137
- icon={rightIcon}
138
- />
139
- )}
140
-
141
- {!isSm && inputHandler.focus && (
142
- <div className="absolute z-50 top-full right-0 mt-1 w-max bg-background border rounded-[6px] p-2 shadow min-w-[300]">
143
- <InputTimePickerComponent
144
- onChange={(time) => {
145
- inputHandler.setValue(time);
146
- onChange?.(time);
147
- }}
148
- />
149
- </div>
150
- )}
151
- </div>
152
- </OutsideClickComponent>
153
-
154
- {invalidMessage && (
155
- <small className={cn("input-error-message", pcn<CT>(className, "error"))}>{invalidMessage}</small>
156
- )}
157
- </div>
158
-
159
- {isSm && (
160
- <BottomSheetComponent
161
- show={inputHandler.focus}
162
- onClose={() => inputHandler.setFocus(false)}
163
- size={380}
164
- footer={
165
- <div className="p-4">
166
- <ButtonComponent
167
- label="Selesai"
168
- variant="outline"
169
- onClick={() => inputHandler.setFocus(false)}
170
- block
171
- />
172
- </div>
173
- }
174
- >
175
- <div className="p-4">
176
- <InputTimePickerComponent
177
- onChange={(time) => {
178
- inputHandler.setValue(time);
179
- onChange?.(time);
180
- }}
181
- />
182
- </div>
183
- </BottomSheetComponent>
184
- )}
185
- </>
186
- );
187
- }
188
-
189
-
190
-
191
- interface InputTimePickerProps {
192
- onChange ?: (time: string) => void;
193
- rightElement ?: ReactNode;
194
- };
195
-
196
-
197
-
198
-
199
- export const InputTimePickerComponent: FC<InputTimePickerProps> = ({
200
- onChange,
201
- rightElement,
202
- }) => {
203
- const [hour, setHour] = useState(0);
204
- const [minute, setMinute] = useState(0);
205
- const [second, setSecond] = useState(0);
206
-
207
- const hours = Array.from({ length: 24 }, (_, i) => String(i).padStart(2, "0"));
208
- const minutes = Array.from({ length: 60 }, (_, i) => String(i).padStart(2, "0"));
209
- const seconds = Array.from({ length: 60 }, (_, i) => String(i).padStart(2, "0"));
210
-
211
- const handleSelect = (type: "h" | "m" | "s", val: string) => {
212
- if (type === "h") setHour(Number(val));
213
- if (type === "m") setMinute(Number(val));
214
- if (type === "s") setSecond(Number(val));
215
- };
216
-
217
- useEffect(() => {
218
- const formatted = `${String(hour).padStart(2, "0")}:${String(minute).padStart(2, "0")}:${String(second).padStart(2, "0")}`;
219
- onChange?.(formatted);
220
- }, [hour, minute, second]);
221
-
222
- const renderColumn = (items: string[], type: "h" | "m" | "s", activeValue: number) => (
223
- <div className="flex-1 overflow-y-auto text-center input-scroll">
224
- {items.map((item) => {
225
- const active = Number(item) === activeValue;
226
-
227
- return (
228
- <div
229
- key={item}
230
- onClick={() => handleSelect(type, item)}
231
- className={cn(
232
- "p-2 cursor-pointer rounded text-sm",
233
- active ? "bg-primary text-background font-semibold" : "hover:bg-light-primary"
234
- )}
235
- >{item}</div>
236
- );
237
- })}
238
- </div>
239
- );
240
-
241
- const timeSlots = useMemo(() => {
242
- const newTimeSlots = [];
243
-
244
- for (let i = 0; i <= 24 * 60; i += 30) {
245
- const hours = Math.floor(i / 60);
246
- const minutes = i % 60;
247
- const label = `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`;
248
-
249
- newTimeSlots.push(label);
250
- }
251
-
252
- return newTimeSlots;
253
- }, [])
254
-
255
- return (
256
- <div className="w-full max-h-[260] flex gap-2">
257
- <div className="w-1/3 overflow-y-auto bg-background rounded-[6px] input-scroll">
258
- {timeSlots.map((time) => (
259
- <div
260
- key={time}
261
- className="p-2 text-sm rounded cursor-pointer hover:bg-light-primary text-center"
262
- onClick={() => onChange?.(time)}
263
- >{time}</div>
264
- ))}
265
- </div>
266
-
267
- <div className="w-2/3 flex gap-2">
268
- {renderColumn(hours, "h", hour)}
269
- {renderColumn(minutes, "m", minute)}
270
- {renderColumn(seconds, "s", second)}
271
- </div>
272
-
273
- {rightElement && <div>{rightElement}</div>}
274
- </div>
275
- );
276
- };