performa 1.0.0
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/LICENSE +21 -0
- package/README.md +850 -0
- package/dist/index.cjs +1623 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +438 -0
- package/dist/index.d.ts +438 -0
- package/dist/index.js +1591 -0
- package/dist/index.js.map +1 -0
- package/dist/nextjs.cjs +1486 -0
- package/dist/nextjs.cjs.map +1 -0
- package/dist/nextjs.d.cts +77 -0
- package/dist/nextjs.d.ts +77 -0
- package/dist/nextjs.js +1483 -0
- package/dist/nextjs.js.map +1 -0
- package/dist/react-router.cjs +1466 -0
- package/dist/react-router.cjs.map +1 -0
- package/dist/react-router.d.cts +50 -0
- package/dist/react-router.d.ts +50 -0
- package/dist/react-router.js +1463 -0
- package/dist/react-router.js.map +1 -0
- package/dist/server-Cjhy29dZ.d.cts +159 -0
- package/dist/server-Cjhy29dZ.d.ts +159 -0
- package/dist/server.cjs +42 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +40 -0
- package/dist/server.js.map +1 -0
- package/dist/tanstack-start.cjs +1499 -0
- package/dist/tanstack-start.cjs.map +1 -0
- package/dist/tanstack-start.d.cts +78 -0
- package/dist/tanstack-start.d.ts +78 -0
- package/dist/tanstack-start.js +1496 -0
- package/dist/tanstack-start.js.map +1 -0
- package/package.json +140 -0
|
@@ -0,0 +1,1463 @@
|
|
|
1
|
+
import { useFetcher } from 'react-router';
|
|
2
|
+
import { createContext, memo, useState, useRef, useEffect, useContext } from 'react';
|
|
3
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
|
+
import { Calendar, ChevronLeft, ChevronRight, Clock, Eye, EyeOff } from 'lucide-react';
|
|
5
|
+
|
|
6
|
+
// src/adapters/react-router.tsx
|
|
7
|
+
var FormContext = createContext(null);
|
|
8
|
+
|
|
9
|
+
// src/core/utils.ts
|
|
10
|
+
function isImage(filename) {
|
|
11
|
+
const imageExtensions = [
|
|
12
|
+
".jpg",
|
|
13
|
+
".jpeg",
|
|
14
|
+
".png",
|
|
15
|
+
".gif",
|
|
16
|
+
".webp",
|
|
17
|
+
".svg",
|
|
18
|
+
".bmp",
|
|
19
|
+
".tiff",
|
|
20
|
+
".ico"
|
|
21
|
+
];
|
|
22
|
+
const ext = filename.toLowerCase().slice(filename.lastIndexOf("."));
|
|
23
|
+
return imageExtensions.includes(ext);
|
|
24
|
+
}
|
|
25
|
+
var widthClasses = {
|
|
26
|
+
1: "col-span-12 @lg:col-span-1",
|
|
27
|
+
2: "col-span-4 @lg:col-span-2",
|
|
28
|
+
3: "col-span-6 @lg:col-span-3",
|
|
29
|
+
4: "col-span-8 @lg:col-span-4",
|
|
30
|
+
5: "col-span-12 @lg:col-span-5",
|
|
31
|
+
6: "col-span-12 @lg:col-span-6",
|
|
32
|
+
7: "col-span-12 @lg:col-span-7",
|
|
33
|
+
8: "col-span-12 @lg:col-span-8",
|
|
34
|
+
9: "col-span-12 @lg:col-span-9",
|
|
35
|
+
10: "col-span-12 @lg:col-span-10",
|
|
36
|
+
11: "col-span-12 @lg:col-span-11",
|
|
37
|
+
12: "col-span-12"
|
|
38
|
+
};
|
|
39
|
+
var defaultTheme = {
|
|
40
|
+
darkMode: true,
|
|
41
|
+
formGroup: "form-group",
|
|
42
|
+
form: "w-full",
|
|
43
|
+
fieldset: "@container grid grid-cols-12 gap-4",
|
|
44
|
+
label: {
|
|
45
|
+
base: "block text-sm font-medium text-gray-700 dark:text-gray-300",
|
|
46
|
+
required: "text-red-500 ml-1"
|
|
47
|
+
},
|
|
48
|
+
input: {
|
|
49
|
+
base: "block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500 focus:outline-none focus:ring focus:ring-primary focus:border-primary",
|
|
50
|
+
error: "border-red-500 dark:border-red-400",
|
|
51
|
+
disabled: "disabled:bg-gray-100 dark:disabled:bg-gray-700 disabled:cursor-not-allowed",
|
|
52
|
+
focus: "focus:outline-none focus:ring focus:ring-primary focus:border-primary"
|
|
53
|
+
},
|
|
54
|
+
select: {
|
|
55
|
+
base: "mt-1 block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 focus:outline-none focus:ring focus:ring-primary focus:border-primary disabled:bg-gray-100 dark:disabled:bg-gray-700 disabled:cursor-not-allowed",
|
|
56
|
+
error: "border-red-500 dark:border-red-400",
|
|
57
|
+
disabled: "disabled:bg-gray-100 dark:disabled:bg-gray-700 disabled:cursor-not-allowed",
|
|
58
|
+
option: "bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100"
|
|
59
|
+
},
|
|
60
|
+
textarea: {
|
|
61
|
+
base: "mt-1 block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500 focus:outline-none focus:ring focus:ring-primary focus:border-primary disabled:bg-gray-100 dark:disabled:bg-gray-700 disabled:cursor-not-allowed",
|
|
62
|
+
error: "border-red-500 dark:border-red-400",
|
|
63
|
+
disabled: "disabled:bg-gray-100 dark:disabled:bg-gray-700 disabled:cursor-not-allowed"
|
|
64
|
+
},
|
|
65
|
+
checkbox: {
|
|
66
|
+
base: "h-4 w-4 text-primary focus:ring-primary border-gray-300 dark:border-gray-600 dark:bg-gray-800 rounded disabled:cursor-not-allowed",
|
|
67
|
+
error: "border-red-500 dark:border-red-400",
|
|
68
|
+
label: "ml-2 block text-sm font-medium text-gray-700 dark:text-gray-300"
|
|
69
|
+
},
|
|
70
|
+
toggle: {
|
|
71
|
+
track: "absolute inset-0 rounded-full transition-colors duration-200 bg-gray-300 dark:bg-gray-600 peer-focus:ring-2 peer-focus:ring-primary peer-focus:ring-offset-2 dark:peer-focus:ring-offset-gray-800",
|
|
72
|
+
trackActive: "peer-checked:bg-primary peer-checked:dark:bg-primary-light",
|
|
73
|
+
thumb: "absolute left-1 top-1 w-4 h-4 bg-white dark:bg-gray-200 rounded-full transition-transform duration-200 peer-checked:translate-x-5",
|
|
74
|
+
label: "block text-sm font-medium text-gray-700 dark:text-gray-300"
|
|
75
|
+
},
|
|
76
|
+
radio: {
|
|
77
|
+
base: "h-4 w-4 text-primary focus:ring-primary border-gray-300 dark:border-gray-600 dark:bg-gray-800 disabled:cursor-not-allowed",
|
|
78
|
+
label: "ml-2 text-sm text-gray-700 dark:text-gray-300",
|
|
79
|
+
group: "mt-1"
|
|
80
|
+
},
|
|
81
|
+
file: {
|
|
82
|
+
dropzone: "flex flex-col items-center justify-center w-full p-6 border-2 border-dashed rounded-md cursor-pointer border-gray-300 dark:border-gray-600 hover:border-primary dark:hover:border-primary transition-colors duration-200",
|
|
83
|
+
dropzoneActive: "border-primary bg-primary-50 dark:bg-primary-900/20",
|
|
84
|
+
dropzoneError: "border-red-500 dark:border-red-400 hover:border-red-500 dark:hover:border-red-400",
|
|
85
|
+
icon: "w-8 h-8 text-gray-400 dark:text-gray-500",
|
|
86
|
+
text: "mt-2 text-sm text-gray-500 dark:text-gray-400",
|
|
87
|
+
hint: "mt-1 text-xs text-gray-500 dark:text-gray-400"
|
|
88
|
+
},
|
|
89
|
+
submit: {
|
|
90
|
+
base: "mt-1 flex items-center justify-center w-full px-4 py-2 border border-transparent rounded-md shadow-sm text-white bg-primary hover:bg-primary-dark dark:bg-primary-light dark:hover:bg-primary focus:outline-none focus:ring-2 focus:ring-offset-2 dark:focus:ring-offset-gray-800 focus:ring-primary transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed",
|
|
91
|
+
loading: "opacity-75",
|
|
92
|
+
spinner: "mr-3 -ml-1 size-5 animate-spin text-white"
|
|
93
|
+
},
|
|
94
|
+
error: "mt-1 text-sm text-red-600 dark:text-red-400",
|
|
95
|
+
alert: {
|
|
96
|
+
base: "p-4 mb-4 border rounded-md",
|
|
97
|
+
error: "bg-red-50 dark:bg-red-900/20 text-red-800 dark:text-red-200 border-red-200 dark:border-red-800",
|
|
98
|
+
success: "bg-green-50 dark:bg-green-900/20 text-green-800 dark:text-green-200 border-green-200 dark:border-green-800",
|
|
99
|
+
warning: "bg-yellow-50 dark:bg-yellow-900/20 text-yellow-800 dark:text-yellow-200 border-yellow-200 dark:border-yellow-800",
|
|
100
|
+
info: "bg-blue-50 dark:bg-blue-900/20 text-blue-800 dark:text-blue-200 border-blue-200 dark:border-blue-800"
|
|
101
|
+
},
|
|
102
|
+
datetime: {
|
|
103
|
+
input: "block w-full px-3 py-2 pr-10 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 placeholder-gray-400 dark:placeholder-gray-500 focus:outline-none focus:ring focus:ring-primary focus:border-primary disabled:bg-gray-100 dark:disabled:bg-gray-700 disabled:cursor-not-allowed cursor-pointer",
|
|
104
|
+
dropdown: "absolute z-50 mt-2 p-4 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg shadow-lg w-80",
|
|
105
|
+
picker: "absolute z-50 mt-2 p-4 bg-white dark:bg-gray-800 border border-gray-300 dark:border-gray-600 rounded-lg shadow-lg w-80",
|
|
106
|
+
calendar: "grid grid-cols-7 gap-1 mb-4",
|
|
107
|
+
day: "p-2 text-sm rounded hover:bg-primary hover:text-white transition-colors text-gray-700 dark:text-gray-300",
|
|
108
|
+
daySelected: "bg-primary text-white",
|
|
109
|
+
dayButton: "p-2 text-sm rounded hover:bg-primary hover:text-white transition-colors text-gray-700 dark:text-gray-300",
|
|
110
|
+
dayButtonSelected: "bg-primary text-white",
|
|
111
|
+
timeInput: "w-14 px-2 py-1 text-center border border-gray-300 dark:border-gray-600 rounded bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100",
|
|
112
|
+
timeLabel: "text-xs font-medium text-gray-700 dark:text-gray-300",
|
|
113
|
+
periodButton: "px-3 py-1 text-xs rounded bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300",
|
|
114
|
+
periodButtonActive: "bg-primary text-white",
|
|
115
|
+
iconButton: "absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 dark:text-gray-400",
|
|
116
|
+
navButton: "p-1 hover:bg-gray-100 dark:hover:bg-gray-700 rounded text-gray-700 dark:text-white",
|
|
117
|
+
monthYear: "text-sm font-medium text-gray-900 dark:text-gray-100",
|
|
118
|
+
weekday: "text-center text-xs font-medium text-gray-500 dark:text-gray-400 p-2",
|
|
119
|
+
formatButton: "px-2 py-1 text-xs bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300 rounded hover:bg-gray-200 dark:hover:bg-gray-600"
|
|
120
|
+
},
|
|
121
|
+
button: {
|
|
122
|
+
primary: "flex-1 px-3 py-2 text-sm bg-primary text-white rounded hover:bg-primary-dark focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2",
|
|
123
|
+
secondary: "flex-1 px-3 py-2 text-sm border border-gray-300 dark:border-gray-600 rounded hover:bg-gray-50 dark:hover:bg-gray-700 text-gray-700 dark:text-gray-300"
|
|
124
|
+
},
|
|
125
|
+
readonly: "mt-1 block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-gray-100 dark:bg-gray-700 text-gray-900 dark:text-gray-100",
|
|
126
|
+
none: {
|
|
127
|
+
container: "form-group",
|
|
128
|
+
label: "block text-sm font-medium text-gray-700 dark:text-gray-300",
|
|
129
|
+
value: "mt-1 block w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md shadow-sm bg-gray-100 dark:bg-gray-700 text-gray-900 dark:text-gray-100"
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
var defaultLabels = {
|
|
133
|
+
required: "*",
|
|
134
|
+
loading: "Loading...",
|
|
135
|
+
fileUpload: {
|
|
136
|
+
clickToUpload: "Click to upload",
|
|
137
|
+
dragAndDrop: "or drag and drop",
|
|
138
|
+
allowedTypes: "Allowed types:",
|
|
139
|
+
maxSize: "Max size:"
|
|
140
|
+
},
|
|
141
|
+
datetime: {
|
|
142
|
+
clear: "Clear",
|
|
143
|
+
done: "Done",
|
|
144
|
+
timeFormat: "Time Format"
|
|
145
|
+
},
|
|
146
|
+
select: {
|
|
147
|
+
loading: "Loading options...",
|
|
148
|
+
noOptions: "No options available"
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
var ThemeContext = createContext({
|
|
152
|
+
theme: defaultTheme,
|
|
153
|
+
labels: defaultLabels
|
|
154
|
+
});
|
|
155
|
+
function useFormTheme() {
|
|
156
|
+
const { theme } = useContext(ThemeContext);
|
|
157
|
+
return theme;
|
|
158
|
+
}
|
|
159
|
+
function useFormLabels() {
|
|
160
|
+
const { labels } = useContext(ThemeContext);
|
|
161
|
+
return labels;
|
|
162
|
+
}
|
|
163
|
+
function cx(...classes) {
|
|
164
|
+
return classes.filter(Boolean).join(" ");
|
|
165
|
+
}
|
|
166
|
+
function Alert({ type, message, className = "" }) {
|
|
167
|
+
const theme = useFormTheme();
|
|
168
|
+
const alertClass = theme.alert?.[type] ?? "";
|
|
169
|
+
return /* @__PURE__ */ jsx(
|
|
170
|
+
"div",
|
|
171
|
+
{
|
|
172
|
+
className: cx(theme.alert?.base, alertClass, className),
|
|
173
|
+
role: "alert",
|
|
174
|
+
children: message
|
|
175
|
+
}
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
var Alert_default = memo(Alert);
|
|
179
|
+
function DateTimeInput({
|
|
180
|
+
label,
|
|
181
|
+
name,
|
|
182
|
+
placeholder,
|
|
183
|
+
defaultValue,
|
|
184
|
+
className,
|
|
185
|
+
disabled,
|
|
186
|
+
error,
|
|
187
|
+
rules,
|
|
188
|
+
before,
|
|
189
|
+
beforeClassName,
|
|
190
|
+
after,
|
|
191
|
+
afterClassName
|
|
192
|
+
}) {
|
|
193
|
+
const [selectedDate, setSelectedDate] = useState(null);
|
|
194
|
+
const [displayValue, setDisplayValue] = useState("");
|
|
195
|
+
const [showPicker, setShowPicker] = useState(false);
|
|
196
|
+
const [currentMonth, setCurrentMonth] = useState(/* @__PURE__ */ new Date());
|
|
197
|
+
const [hours, setHours] = useState("12");
|
|
198
|
+
const [minutes, setMinutes] = useState("00");
|
|
199
|
+
const [period, setPeriod] = useState("PM");
|
|
200
|
+
const [use24Hour, setUse24Hour] = useState(true);
|
|
201
|
+
const pickerRef = useRef(null);
|
|
202
|
+
const theme = useFormTheme();
|
|
203
|
+
const labels = useFormLabels();
|
|
204
|
+
useEffect(() => {
|
|
205
|
+
if (defaultValue) {
|
|
206
|
+
const date = new Date(defaultValue.toString());
|
|
207
|
+
if (!isNaN(date.getTime())) {
|
|
208
|
+
setSelectedDate(date);
|
|
209
|
+
setCurrentMonth(date);
|
|
210
|
+
updateDisplayValue(date);
|
|
211
|
+
const h24 = date.getHours();
|
|
212
|
+
const m = date.getMinutes();
|
|
213
|
+
const p = h24 >= 12 ? "PM" : "AM";
|
|
214
|
+
const h12 = h24 % 12 || 12;
|
|
215
|
+
if (use24Hour) {
|
|
216
|
+
setHours(String(h24).padStart(2, "0"));
|
|
217
|
+
} else {
|
|
218
|
+
setHours(String(h12).padStart(2, "0"));
|
|
219
|
+
}
|
|
220
|
+
setMinutes(String(m).padStart(2, "0"));
|
|
221
|
+
setPeriod(p);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}, [defaultValue, use24Hour]);
|
|
225
|
+
useEffect(() => {
|
|
226
|
+
const handleClickOutside = (event) => {
|
|
227
|
+
if (pickerRef.current && !pickerRef.current.contains(event.target)) {
|
|
228
|
+
setShowPicker(false);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
if (showPicker) {
|
|
232
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
233
|
+
}
|
|
234
|
+
return () => {
|
|
235
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
236
|
+
};
|
|
237
|
+
}, [showPicker]);
|
|
238
|
+
const updateDisplayValue = (date) => {
|
|
239
|
+
setDisplayValue(date.toLocaleString());
|
|
240
|
+
};
|
|
241
|
+
const getDaysInMonth = (date) => {
|
|
242
|
+
const year = date.getFullYear();
|
|
243
|
+
const month = date.getMonth();
|
|
244
|
+
const firstDay = new Date(year, month, 1);
|
|
245
|
+
const lastDay = new Date(year, month + 1, 0);
|
|
246
|
+
const daysInMonth = lastDay.getDate();
|
|
247
|
+
const startingDayOfWeek = firstDay.getDay();
|
|
248
|
+
return { daysInMonth, startingDayOfWeek };
|
|
249
|
+
};
|
|
250
|
+
const handleDateSelect = (day) => {
|
|
251
|
+
let hour24 = parseInt(hours, 10);
|
|
252
|
+
if (!use24Hour) {
|
|
253
|
+
if (period === "PM" && hour24 !== 12) hour24 += 12;
|
|
254
|
+
if (period === "AM" && hour24 === 12) hour24 = 0;
|
|
255
|
+
}
|
|
256
|
+
const newDate = new Date(
|
|
257
|
+
currentMonth.getFullYear(),
|
|
258
|
+
currentMonth.getMonth(),
|
|
259
|
+
day,
|
|
260
|
+
hour24,
|
|
261
|
+
parseInt(minutes, 10)
|
|
262
|
+
);
|
|
263
|
+
setSelectedDate(newDate);
|
|
264
|
+
updateDisplayValue(newDate);
|
|
265
|
+
};
|
|
266
|
+
const handleTimeChange = () => {
|
|
267
|
+
if (selectedDate) {
|
|
268
|
+
const newDate = new Date(selectedDate);
|
|
269
|
+
let h = parseInt(hours, 10);
|
|
270
|
+
if (!use24Hour) {
|
|
271
|
+
if (period === "PM" && h !== 12) h += 12;
|
|
272
|
+
if (period === "AM" && h === 12) h = 0;
|
|
273
|
+
}
|
|
274
|
+
newDate.setHours(h, parseInt(minutes, 10));
|
|
275
|
+
setSelectedDate(newDate);
|
|
276
|
+
updateDisplayValue(newDate);
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
const changeMonth = (offset) => {
|
|
280
|
+
setCurrentMonth(
|
|
281
|
+
(prev) => new Date(prev.getFullYear(), prev.getMonth() + offset, 1)
|
|
282
|
+
);
|
|
283
|
+
};
|
|
284
|
+
const renderCalendar = () => {
|
|
285
|
+
const { daysInMonth, startingDayOfWeek } = getDaysInMonth(currentMonth);
|
|
286
|
+
const days = [];
|
|
287
|
+
for (let i = 0; i < startingDayOfWeek; i++) {
|
|
288
|
+
days.push(/* @__PURE__ */ jsx("div", { className: "p-2" }, `empty-${i}`));
|
|
289
|
+
}
|
|
290
|
+
for (let day = 1; day <= daysInMonth; day++) {
|
|
291
|
+
const isSelected = selectedDate && selectedDate.getDate() === day && selectedDate.getMonth() === currentMonth.getMonth() && selectedDate.getFullYear() === currentMonth.getFullYear();
|
|
292
|
+
days.push(
|
|
293
|
+
/* @__PURE__ */ jsx(
|
|
294
|
+
"button",
|
|
295
|
+
{
|
|
296
|
+
type: "button",
|
|
297
|
+
onClick: () => handleDateSelect(day),
|
|
298
|
+
className: cx(
|
|
299
|
+
theme.datetime?.day,
|
|
300
|
+
isSelected && theme.datetime?.daySelected
|
|
301
|
+
),
|
|
302
|
+
children: day
|
|
303
|
+
},
|
|
304
|
+
day
|
|
305
|
+
)
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
return days;
|
|
309
|
+
};
|
|
310
|
+
return /* @__PURE__ */ jsxs("div", { className: cx(theme.formGroup, className), ref: pickerRef, children: [
|
|
311
|
+
before && /* @__PURE__ */ jsx("p", { className: beforeClassName ?? "", children: before }),
|
|
312
|
+
/* @__PURE__ */ jsxs("label", { htmlFor: name, className: theme.label?.base, children: [
|
|
313
|
+
label,
|
|
314
|
+
" ",
|
|
315
|
+
rules?.required && /* @__PURE__ */ jsx("span", { className: theme.label?.required, children: "*" })
|
|
316
|
+
] }),
|
|
317
|
+
/* @__PURE__ */ jsxs("div", { className: "relative mt-1", children: [
|
|
318
|
+
/* @__PURE__ */ jsx(
|
|
319
|
+
"input",
|
|
320
|
+
{
|
|
321
|
+
type: "text",
|
|
322
|
+
value: displayValue,
|
|
323
|
+
placeholder,
|
|
324
|
+
readOnly: true,
|
|
325
|
+
onFocus: () => !disabled && setShowPicker(true),
|
|
326
|
+
onClick: () => !disabled && setShowPicker(true),
|
|
327
|
+
className: cx(
|
|
328
|
+
theme.datetime?.input,
|
|
329
|
+
error && theme.input?.error
|
|
330
|
+
)
|
|
331
|
+
}
|
|
332
|
+
),
|
|
333
|
+
/* @__PURE__ */ jsx(
|
|
334
|
+
"button",
|
|
335
|
+
{
|
|
336
|
+
type: "button",
|
|
337
|
+
onClick: () => !disabled && setShowPicker(true),
|
|
338
|
+
disabled,
|
|
339
|
+
className: theme.datetime?.iconButton,
|
|
340
|
+
children: /* @__PURE__ */ jsx(Calendar, { className: "h-5 w-5" })
|
|
341
|
+
}
|
|
342
|
+
),
|
|
343
|
+
/* @__PURE__ */ jsx(
|
|
344
|
+
"input",
|
|
345
|
+
{
|
|
346
|
+
type: "hidden",
|
|
347
|
+
name,
|
|
348
|
+
id: name,
|
|
349
|
+
value: selectedDate ? selectedDate.toISOString() : "",
|
|
350
|
+
"aria-invalid": !!error,
|
|
351
|
+
"aria-describedby": error ? `${name}-error` : void 0
|
|
352
|
+
}
|
|
353
|
+
),
|
|
354
|
+
showPicker && /* @__PURE__ */ jsxs("div", { className: theme.datetime?.dropdown, children: [
|
|
355
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-4", children: [
|
|
356
|
+
/* @__PURE__ */ jsx(
|
|
357
|
+
"button",
|
|
358
|
+
{
|
|
359
|
+
type: "button",
|
|
360
|
+
onClick: () => changeMonth(-1),
|
|
361
|
+
className: theme.datetime?.navButton,
|
|
362
|
+
children: /* @__PURE__ */ jsx(ChevronLeft, { className: "w-5 h-5" })
|
|
363
|
+
}
|
|
364
|
+
),
|
|
365
|
+
/* @__PURE__ */ jsx("span", { className: theme.datetime?.monthYear, children: currentMonth.toLocaleDateString("en-GB", {
|
|
366
|
+
month: "long",
|
|
367
|
+
year: "numeric"
|
|
368
|
+
}) }),
|
|
369
|
+
/* @__PURE__ */ jsx(
|
|
370
|
+
"button",
|
|
371
|
+
{
|
|
372
|
+
type: "button",
|
|
373
|
+
onClick: () => changeMonth(1),
|
|
374
|
+
className: theme.datetime?.navButton,
|
|
375
|
+
children: /* @__PURE__ */ jsx(ChevronRight, { className: "w-5 h-5" })
|
|
376
|
+
}
|
|
377
|
+
)
|
|
378
|
+
] }),
|
|
379
|
+
/* @__PURE__ */ jsx("div", { className: "grid grid-cols-7 gap-1 mb-2", children: (labels.datetime?.weekdays ?? [
|
|
380
|
+
"Su",
|
|
381
|
+
"Mo",
|
|
382
|
+
"Tu",
|
|
383
|
+
"We",
|
|
384
|
+
"Th",
|
|
385
|
+
"Fr",
|
|
386
|
+
"Sa"
|
|
387
|
+
]).map((day) => /* @__PURE__ */ jsx(
|
|
388
|
+
"div",
|
|
389
|
+
{
|
|
390
|
+
className: theme.datetime?.weekday,
|
|
391
|
+
children: day
|
|
392
|
+
},
|
|
393
|
+
day
|
|
394
|
+
)) }),
|
|
395
|
+
/* @__PURE__ */ jsx("div", { className: "grid grid-cols-7 gap-1 mb-4", children: renderCalendar() }),
|
|
396
|
+
/* @__PURE__ */ jsxs("div", { className: "border-t border-gray-200 dark:border-gray-700 pt-4", children: [
|
|
397
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between mb-3", children: [
|
|
398
|
+
/* @__PURE__ */ jsx("span", { className: theme.datetime?.timeLabel, children: labels.datetime?.timeFormat }),
|
|
399
|
+
/* @__PURE__ */ jsx(
|
|
400
|
+
"button",
|
|
401
|
+
{
|
|
402
|
+
type: "button",
|
|
403
|
+
onClick: () => {
|
|
404
|
+
const newFormat = !use24Hour;
|
|
405
|
+
setUse24Hour(newFormat);
|
|
406
|
+
if (selectedDate) {
|
|
407
|
+
const h24 = selectedDate.getHours();
|
|
408
|
+
if (newFormat) {
|
|
409
|
+
setHours(
|
|
410
|
+
String(h24).padStart(2, "0")
|
|
411
|
+
);
|
|
412
|
+
} else {
|
|
413
|
+
const h12 = h24 % 12 || 12;
|
|
414
|
+
setHours(
|
|
415
|
+
String(h12).padStart(2, "0")
|
|
416
|
+
);
|
|
417
|
+
setPeriod(
|
|
418
|
+
h24 >= 12 ? "PM" : "AM"
|
|
419
|
+
);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
},
|
|
423
|
+
className: theme.datetime?.formatButton,
|
|
424
|
+
children: use24Hour ? "24hr" : "12hr"
|
|
425
|
+
}
|
|
426
|
+
)
|
|
427
|
+
] }),
|
|
428
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center gap-2", children: [
|
|
429
|
+
/* @__PURE__ */ jsx(Clock, { className: "h-4 w-4 text-gray-500 dark:text-gray-400" }),
|
|
430
|
+
/* @__PURE__ */ jsx(
|
|
431
|
+
"input",
|
|
432
|
+
{
|
|
433
|
+
type: "number",
|
|
434
|
+
min: use24Hour ? "0" : "1",
|
|
435
|
+
max: use24Hour ? "23" : "12",
|
|
436
|
+
value: hours,
|
|
437
|
+
onChange: (e) => {
|
|
438
|
+
const val = parseInt(e.target.value, 10);
|
|
439
|
+
const max = use24Hour ? 23 : 12;
|
|
440
|
+
const min = use24Hour ? 0 : 1;
|
|
441
|
+
if (val >= min && val <= max) {
|
|
442
|
+
setHours(
|
|
443
|
+
e.target.value.padStart(2, "0")
|
|
444
|
+
);
|
|
445
|
+
handleTimeChange();
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
className: theme.datetime?.timeInput
|
|
449
|
+
}
|
|
450
|
+
),
|
|
451
|
+
/* @__PURE__ */ jsx("span", { className: "text-gray-900 dark:text-gray-100", children: ":" }),
|
|
452
|
+
/* @__PURE__ */ jsx(
|
|
453
|
+
"input",
|
|
454
|
+
{
|
|
455
|
+
type: "number",
|
|
456
|
+
min: "0",
|
|
457
|
+
max: "59",
|
|
458
|
+
value: minutes,
|
|
459
|
+
onChange: (e) => {
|
|
460
|
+
const val = parseInt(e.target.value, 10);
|
|
461
|
+
if (val >= 0 && val <= 59) {
|
|
462
|
+
setMinutes(
|
|
463
|
+
e.target.value.padStart(2, "0")
|
|
464
|
+
);
|
|
465
|
+
handleTimeChange();
|
|
466
|
+
}
|
|
467
|
+
},
|
|
468
|
+
className: theme.datetime?.timeInput
|
|
469
|
+
}
|
|
470
|
+
),
|
|
471
|
+
!use24Hour && /* @__PURE__ */ jsxs("div", { className: "flex gap-1", children: [
|
|
472
|
+
/* @__PURE__ */ jsx(
|
|
473
|
+
"button",
|
|
474
|
+
{
|
|
475
|
+
type: "button",
|
|
476
|
+
onClick: () => {
|
|
477
|
+
setPeriod("AM");
|
|
478
|
+
handleTimeChange();
|
|
479
|
+
},
|
|
480
|
+
className: cx(
|
|
481
|
+
theme.datetime?.periodButton,
|
|
482
|
+
period === "AM" && theme.datetime?.periodButtonActive
|
|
483
|
+
),
|
|
484
|
+
children: "AM"
|
|
485
|
+
}
|
|
486
|
+
),
|
|
487
|
+
/* @__PURE__ */ jsx(
|
|
488
|
+
"button",
|
|
489
|
+
{
|
|
490
|
+
type: "button",
|
|
491
|
+
onClick: () => {
|
|
492
|
+
setPeriod("PM");
|
|
493
|
+
handleTimeChange();
|
|
494
|
+
},
|
|
495
|
+
className: cx(
|
|
496
|
+
theme.datetime?.periodButton,
|
|
497
|
+
period === "PM" && theme.datetime?.periodButtonActive
|
|
498
|
+
),
|
|
499
|
+
children: "PM"
|
|
500
|
+
}
|
|
501
|
+
)
|
|
502
|
+
] })
|
|
503
|
+
] })
|
|
504
|
+
] }),
|
|
505
|
+
/* @__PURE__ */ jsxs("div", { className: "flex gap-2 mt-4", children: [
|
|
506
|
+
/* @__PURE__ */ jsx(
|
|
507
|
+
"button",
|
|
508
|
+
{
|
|
509
|
+
type: "button",
|
|
510
|
+
onClick: () => {
|
|
511
|
+
setSelectedDate(null);
|
|
512
|
+
setDisplayValue("");
|
|
513
|
+
setShowPicker(false);
|
|
514
|
+
},
|
|
515
|
+
className: theme.button?.secondary,
|
|
516
|
+
children: labels.datetime?.clear
|
|
517
|
+
}
|
|
518
|
+
),
|
|
519
|
+
/* @__PURE__ */ jsx(
|
|
520
|
+
"button",
|
|
521
|
+
{
|
|
522
|
+
type: "button",
|
|
523
|
+
onClick: () => setShowPicker(false),
|
|
524
|
+
className: theme.button?.primary,
|
|
525
|
+
children: labels.datetime?.done
|
|
526
|
+
}
|
|
527
|
+
)
|
|
528
|
+
] })
|
|
529
|
+
] })
|
|
530
|
+
] }),
|
|
531
|
+
error && /* @__PURE__ */ jsx("p", { id: `${name}-error`, className: theme.error, children: error }),
|
|
532
|
+
after && /* @__PURE__ */ jsx("p", { className: afterClassName ?? "", children: after })
|
|
533
|
+
] });
|
|
534
|
+
}
|
|
535
|
+
var DateTimeInput_default = memo(DateTimeInput);
|
|
536
|
+
function TextInput({
|
|
537
|
+
label,
|
|
538
|
+
placeholder,
|
|
539
|
+
name,
|
|
540
|
+
defaultValue,
|
|
541
|
+
className,
|
|
542
|
+
disabled,
|
|
543
|
+
error,
|
|
544
|
+
rules,
|
|
545
|
+
type = "text",
|
|
546
|
+
before,
|
|
547
|
+
beforeClassName,
|
|
548
|
+
after,
|
|
549
|
+
afterClassName
|
|
550
|
+
}) {
|
|
551
|
+
const [passwordVisible, setPasswordVisible] = useState(false);
|
|
552
|
+
const theme = useFormTheme();
|
|
553
|
+
const onTogglePassword = () => {
|
|
554
|
+
setPasswordVisible((prev) => !prev);
|
|
555
|
+
};
|
|
556
|
+
return /* @__PURE__ */ jsxs("div", { className: cx(theme.formGroup, className), children: [
|
|
557
|
+
before && /* @__PURE__ */ jsx("p", { className: beforeClassName ?? "", children: before }),
|
|
558
|
+
/* @__PURE__ */ jsxs("label", { htmlFor: name, className: theme.label?.base, children: [
|
|
559
|
+
label,
|
|
560
|
+
rules?.required && /* @__PURE__ */ jsx("span", { className: theme.label?.required, children: "*" })
|
|
561
|
+
] }),
|
|
562
|
+
/* @__PURE__ */ jsxs("div", { className: "relative mt-1", children: [
|
|
563
|
+
/* @__PURE__ */ jsx(
|
|
564
|
+
"input",
|
|
565
|
+
{
|
|
566
|
+
type: type === "password" ? passwordVisible ? "text" : "password" : type,
|
|
567
|
+
name,
|
|
568
|
+
id: name,
|
|
569
|
+
placeholder,
|
|
570
|
+
defaultValue: defaultValue?.toString(),
|
|
571
|
+
disabled,
|
|
572
|
+
"aria-invalid": !!error,
|
|
573
|
+
"aria-describedby": error ? `${name}-error` : void 0,
|
|
574
|
+
className: cx(
|
|
575
|
+
theme.input?.base,
|
|
576
|
+
error && theme.input?.error,
|
|
577
|
+
theme.input?.disabled
|
|
578
|
+
)
|
|
579
|
+
}
|
|
580
|
+
),
|
|
581
|
+
type === "password" && /* @__PURE__ */ jsxs(
|
|
582
|
+
"button",
|
|
583
|
+
{
|
|
584
|
+
type: "button",
|
|
585
|
+
onClick: onTogglePassword,
|
|
586
|
+
className: "absolute right-2 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200 z-10",
|
|
587
|
+
"aria-label": passwordVisible ? "Hide password" : "Show password",
|
|
588
|
+
children: [
|
|
589
|
+
passwordVisible ? /* @__PURE__ */ jsx(Eye, { className: "h-5 w-5" }) : /* @__PURE__ */ jsx(EyeOff, { className: "h-5 w-5 opacity-50" }),
|
|
590
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: passwordVisible ? "Hide password" : "Show password" })
|
|
591
|
+
]
|
|
592
|
+
}
|
|
593
|
+
)
|
|
594
|
+
] }),
|
|
595
|
+
error && /* @__PURE__ */ jsx("p", { id: `${name}-error`, className: theme.error, children: error }),
|
|
596
|
+
after && /* @__PURE__ */ jsx("p", { className: afterClassName ?? "", children: after })
|
|
597
|
+
] });
|
|
598
|
+
}
|
|
599
|
+
var TextInput_default = memo(TextInput);
|
|
600
|
+
function SelectInput({
|
|
601
|
+
label,
|
|
602
|
+
name,
|
|
603
|
+
options,
|
|
604
|
+
defaultValue,
|
|
605
|
+
className,
|
|
606
|
+
disabled,
|
|
607
|
+
error,
|
|
608
|
+
rules,
|
|
609
|
+
before,
|
|
610
|
+
beforeClassName,
|
|
611
|
+
after,
|
|
612
|
+
afterClassName
|
|
613
|
+
}) {
|
|
614
|
+
const theme = useFormTheme();
|
|
615
|
+
const labels = useFormLabels();
|
|
616
|
+
return /* @__PURE__ */ jsxs("div", { className: cx(theme.formGroup, className), children: [
|
|
617
|
+
before && /* @__PURE__ */ jsx("p", { className: beforeClassName ?? "", children: before }),
|
|
618
|
+
/* @__PURE__ */ jsxs("label", { htmlFor: name, className: theme.label?.base, children: [
|
|
619
|
+
label,
|
|
620
|
+
rules?.required && /* @__PURE__ */ jsx("span", { className: theme.label?.required, children: "*" })
|
|
621
|
+
] }),
|
|
622
|
+
/* @__PURE__ */ jsx(
|
|
623
|
+
"select",
|
|
624
|
+
{
|
|
625
|
+
name,
|
|
626
|
+
id: name,
|
|
627
|
+
defaultValue: defaultValue?.toString(),
|
|
628
|
+
disabled,
|
|
629
|
+
"aria-invalid": !!error,
|
|
630
|
+
"aria-describedby": error ? `${name}-error` : void 0,
|
|
631
|
+
className: cx(
|
|
632
|
+
theme.select?.base,
|
|
633
|
+
error && theme.select?.error
|
|
634
|
+
),
|
|
635
|
+
children: !options || options.length === 0 ? /* @__PURE__ */ jsx("option", { value: "", disabled: true, className: theme.select?.option, children: !options ? labels.select?.loading : labels.select?.noOptions }) : options.map((option) => /* @__PURE__ */ jsx(
|
|
636
|
+
"option",
|
|
637
|
+
{
|
|
638
|
+
value: option.value,
|
|
639
|
+
className: theme.select?.option,
|
|
640
|
+
children: option.label
|
|
641
|
+
},
|
|
642
|
+
option.value
|
|
643
|
+
))
|
|
644
|
+
}
|
|
645
|
+
),
|
|
646
|
+
error && /* @__PURE__ */ jsx("p", { id: `${name}-error`, className: theme.error, children: error }),
|
|
647
|
+
after && /* @__PURE__ */ jsx("p", { className: afterClassName ?? "", children: after })
|
|
648
|
+
] });
|
|
649
|
+
}
|
|
650
|
+
var SelectInput_default = memo(SelectInput);
|
|
651
|
+
function TextAreaInput({
|
|
652
|
+
label,
|
|
653
|
+
name,
|
|
654
|
+
placeholder,
|
|
655
|
+
defaultValue,
|
|
656
|
+
className,
|
|
657
|
+
disabled,
|
|
658
|
+
error,
|
|
659
|
+
rules,
|
|
660
|
+
before,
|
|
661
|
+
beforeClassName,
|
|
662
|
+
after,
|
|
663
|
+
afterClassName
|
|
664
|
+
}) {
|
|
665
|
+
const theme = useFormTheme();
|
|
666
|
+
return /* @__PURE__ */ jsxs("div", { className: cx(theme.formGroup, className), children: [
|
|
667
|
+
before && /* @__PURE__ */ jsx("p", { className: beforeClassName ?? "", children: before }),
|
|
668
|
+
/* @__PURE__ */ jsxs("label", { htmlFor: name, className: theme.label?.base, children: [
|
|
669
|
+
label,
|
|
670
|
+
rules?.required && /* @__PURE__ */ jsx("span", { className: theme.label?.required, children: "*" })
|
|
671
|
+
] }),
|
|
672
|
+
/* @__PURE__ */ jsx(
|
|
673
|
+
"textarea",
|
|
674
|
+
{
|
|
675
|
+
name,
|
|
676
|
+
id: name,
|
|
677
|
+
placeholder,
|
|
678
|
+
defaultValue: defaultValue?.toString(),
|
|
679
|
+
disabled,
|
|
680
|
+
"aria-invalid": !!error,
|
|
681
|
+
"aria-describedby": error ? `${name}-error` : void 0,
|
|
682
|
+
className: cx(
|
|
683
|
+
theme.textarea?.base,
|
|
684
|
+
error && theme.textarea?.error
|
|
685
|
+
),
|
|
686
|
+
rows: 4
|
|
687
|
+
}
|
|
688
|
+
),
|
|
689
|
+
error && /* @__PURE__ */ jsx("p", { id: `${name}-error`, className: theme.error, children: error }),
|
|
690
|
+
after && /* @__PURE__ */ jsx("p", { className: afterClassName ?? "", children: after })
|
|
691
|
+
] });
|
|
692
|
+
}
|
|
693
|
+
var TextAreaInput_default = memo(TextAreaInput);
|
|
694
|
+
function CheckboxInput({
|
|
695
|
+
label,
|
|
696
|
+
name,
|
|
697
|
+
defaultChecked,
|
|
698
|
+
className,
|
|
699
|
+
disabled,
|
|
700
|
+
error,
|
|
701
|
+
rules,
|
|
702
|
+
before,
|
|
703
|
+
beforeClassName,
|
|
704
|
+
after,
|
|
705
|
+
afterClassName
|
|
706
|
+
}) {
|
|
707
|
+
const theme = useFormTheme();
|
|
708
|
+
return /* @__PURE__ */ jsxs("div", { className: cx(theme.formGroup, className), children: [
|
|
709
|
+
before && /* @__PURE__ */ jsx("p", { className: beforeClassName ?? "", children: before }),
|
|
710
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center", children: [
|
|
711
|
+
/* @__PURE__ */ jsx(
|
|
712
|
+
"input",
|
|
713
|
+
{
|
|
714
|
+
type: "checkbox",
|
|
715
|
+
name,
|
|
716
|
+
id: name,
|
|
717
|
+
defaultChecked,
|
|
718
|
+
disabled,
|
|
719
|
+
"aria-invalid": !!error,
|
|
720
|
+
"aria-describedby": error ? `${name}-error` : void 0,
|
|
721
|
+
className: cx(
|
|
722
|
+
theme.checkbox?.base,
|
|
723
|
+
error && theme.checkbox?.error
|
|
724
|
+
)
|
|
725
|
+
}
|
|
726
|
+
),
|
|
727
|
+
/* @__PURE__ */ jsxs("label", { htmlFor: name, className: theme.checkbox?.label, children: [
|
|
728
|
+
label,
|
|
729
|
+
rules?.required && /* @__PURE__ */ jsx("span", { className: theme.label?.required, children: "*" })
|
|
730
|
+
] })
|
|
731
|
+
] }),
|
|
732
|
+
error && /* @__PURE__ */ jsx("p", { id: `${name}-error`, className: theme.error, children: error }),
|
|
733
|
+
after && /* @__PURE__ */ jsx("p", { className: afterClassName ?? "", children: after })
|
|
734
|
+
] });
|
|
735
|
+
}
|
|
736
|
+
var CheckboxInput_default = memo(CheckboxInput);
|
|
737
|
+
function ToggleInput({
|
|
738
|
+
label,
|
|
739
|
+
name,
|
|
740
|
+
defaultChecked,
|
|
741
|
+
className,
|
|
742
|
+
disabled,
|
|
743
|
+
error,
|
|
744
|
+
rules,
|
|
745
|
+
before,
|
|
746
|
+
beforeClassName,
|
|
747
|
+
after,
|
|
748
|
+
afterClassName
|
|
749
|
+
}) {
|
|
750
|
+
const theme = useFormTheme();
|
|
751
|
+
return /* @__PURE__ */ jsxs("div", { className: cx(theme.formGroup, className), children: [
|
|
752
|
+
before && /* @__PURE__ */ jsx("p", { className: beforeClassName ?? "", children: before }),
|
|
753
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
754
|
+
/* @__PURE__ */ jsxs("label", { htmlFor: name, className: theme.toggle?.label, children: [
|
|
755
|
+
label,
|
|
756
|
+
rules?.required && /* @__PURE__ */ jsx("span", { className: theme.label?.required, children: "*" })
|
|
757
|
+
] }),
|
|
758
|
+
/* @__PURE__ */ jsxs(
|
|
759
|
+
"label",
|
|
760
|
+
{
|
|
761
|
+
htmlFor: name,
|
|
762
|
+
className: "relative inline-block w-11 h-6 cursor-pointer",
|
|
763
|
+
children: [
|
|
764
|
+
/* @__PURE__ */ jsx(
|
|
765
|
+
"input",
|
|
766
|
+
{
|
|
767
|
+
type: "checkbox",
|
|
768
|
+
name,
|
|
769
|
+
id: name,
|
|
770
|
+
defaultChecked,
|
|
771
|
+
disabled,
|
|
772
|
+
"aria-invalid": !!error,
|
|
773
|
+
"aria-describedby": error ? `${name}-error` : void 0,
|
|
774
|
+
className: "sr-only peer"
|
|
775
|
+
}
|
|
776
|
+
),
|
|
777
|
+
/* @__PURE__ */ jsx(
|
|
778
|
+
"span",
|
|
779
|
+
{
|
|
780
|
+
className: cx(
|
|
781
|
+
theme.toggle?.track,
|
|
782
|
+
!disabled && theme.toggle?.trackActive,
|
|
783
|
+
disabled && "cursor-not-allowed"
|
|
784
|
+
)
|
|
785
|
+
}
|
|
786
|
+
),
|
|
787
|
+
/* @__PURE__ */ jsx("span", { className: theme.toggle?.thumb })
|
|
788
|
+
]
|
|
789
|
+
}
|
|
790
|
+
)
|
|
791
|
+
] }),
|
|
792
|
+
error && /* @__PURE__ */ jsx("p", { id: `${name}-error`, className: theme.error, children: error }),
|
|
793
|
+
after && /* @__PURE__ */ jsx("p", { className: afterClassName ?? "", children: after })
|
|
794
|
+
] });
|
|
795
|
+
}
|
|
796
|
+
var ToggleInput_default = memo(ToggleInput);
|
|
797
|
+
function RadioInput({
|
|
798
|
+
label,
|
|
799
|
+
name,
|
|
800
|
+
options,
|
|
801
|
+
defaultValue,
|
|
802
|
+
className,
|
|
803
|
+
disabled,
|
|
804
|
+
error,
|
|
805
|
+
rules,
|
|
806
|
+
before,
|
|
807
|
+
beforeClassName,
|
|
808
|
+
after,
|
|
809
|
+
afterClassName
|
|
810
|
+
}) {
|
|
811
|
+
const theme = useFormTheme();
|
|
812
|
+
return /* @__PURE__ */ jsxs("div", { className: cx(theme.formGroup, className), children: [
|
|
813
|
+
before && /* @__PURE__ */ jsx("p", { className: beforeClassName ?? "", children: before }),
|
|
814
|
+
/* @__PURE__ */ jsxs("div", { id: `${name}-group`, className: theme.label?.base, children: [
|
|
815
|
+
label,
|
|
816
|
+
rules?.required && /* @__PURE__ */ jsx("span", { className: theme.label?.required, children: "*" })
|
|
817
|
+
] }),
|
|
818
|
+
/* @__PURE__ */ jsx(
|
|
819
|
+
"div",
|
|
820
|
+
{
|
|
821
|
+
className: theme.radio?.group,
|
|
822
|
+
role: "radiogroup",
|
|
823
|
+
"aria-labelledby": `${name}-group`,
|
|
824
|
+
children: options?.map((option) => /* @__PURE__ */ jsxs("div", { className: "flex items-center mb-2", children: [
|
|
825
|
+
/* @__PURE__ */ jsx(
|
|
826
|
+
"input",
|
|
827
|
+
{
|
|
828
|
+
type: "radio",
|
|
829
|
+
name,
|
|
830
|
+
id: `${name}-${option.value}`,
|
|
831
|
+
value: option.value,
|
|
832
|
+
defaultChecked: defaultValue === option.value,
|
|
833
|
+
disabled,
|
|
834
|
+
"aria-invalid": !!error,
|
|
835
|
+
className: theme.radio?.base
|
|
836
|
+
}
|
|
837
|
+
),
|
|
838
|
+
/* @__PURE__ */ jsx(
|
|
839
|
+
"label",
|
|
840
|
+
{
|
|
841
|
+
htmlFor: `${name}-${option.value}`,
|
|
842
|
+
className: theme.radio?.label,
|
|
843
|
+
children: option.label
|
|
844
|
+
}
|
|
845
|
+
)
|
|
846
|
+
] }, option.value))
|
|
847
|
+
}
|
|
848
|
+
),
|
|
849
|
+
error && /* @__PURE__ */ jsx("p", { id: `${name}-error`, className: theme.error, children: error }),
|
|
850
|
+
after && /* @__PURE__ */ jsx("p", { className: afterClassName ?? "", children: after })
|
|
851
|
+
] });
|
|
852
|
+
}
|
|
853
|
+
var RadioInput_default = memo(RadioInput);
|
|
854
|
+
|
|
855
|
+
// src/core/types.ts
|
|
856
|
+
var mimeTypes = {
|
|
857
|
+
JPG: "image/jpeg",
|
|
858
|
+
JPEG: "image/jpeg",
|
|
859
|
+
PNG: "image/png",
|
|
860
|
+
GIF: "image/gif",
|
|
861
|
+
WEBP: "image/webp",
|
|
862
|
+
SVG: "image/svg+xml",
|
|
863
|
+
BMP: "image/bmp",
|
|
864
|
+
TIFF: "image/tiff",
|
|
865
|
+
ICO: "image/x-icon",
|
|
866
|
+
PDF: "application/pdf",
|
|
867
|
+
DOC: "application/msword",
|
|
868
|
+
DOCX: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
869
|
+
XLS: "application/vnd.ms-excel",
|
|
870
|
+
XLSX: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
871
|
+
PPT: "application/vnd.ms-powerpoint",
|
|
872
|
+
PPTX: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
873
|
+
ZIP: "application/zip",
|
|
874
|
+
RAR: "application/x-rar-compressed",
|
|
875
|
+
"7Z": "application/x-7z-compressed",
|
|
876
|
+
TAR: "application/x-tar",
|
|
877
|
+
GZ: "application/x-gzip",
|
|
878
|
+
BZ2: "application/x-bzip2",
|
|
879
|
+
ISO: "application/x-iso9660-image",
|
|
880
|
+
SWF: "application/x-shockwave-flash",
|
|
881
|
+
TTF: "application/x-font-ttf",
|
|
882
|
+
MP4: "video/mp4",
|
|
883
|
+
MP3: "audio/mpeg",
|
|
884
|
+
MOV: "video/quicktime",
|
|
885
|
+
AVI: "video/x-msvideo",
|
|
886
|
+
WMV: "video/x-ms-wmv",
|
|
887
|
+
MPEG: "video/mpeg",
|
|
888
|
+
TXT: "text/plain",
|
|
889
|
+
CSV: "text/csv"
|
|
890
|
+
};
|
|
891
|
+
function FileInput({
|
|
892
|
+
label,
|
|
893
|
+
name,
|
|
894
|
+
className,
|
|
895
|
+
disabled,
|
|
896
|
+
error,
|
|
897
|
+
rules,
|
|
898
|
+
before,
|
|
899
|
+
beforeClassName,
|
|
900
|
+
after,
|
|
901
|
+
afterClassName,
|
|
902
|
+
defaultValue,
|
|
903
|
+
metaData,
|
|
904
|
+
uploadDir,
|
|
905
|
+
baseUrl
|
|
906
|
+
}) {
|
|
907
|
+
const [fileName, setFileName] = useState(null);
|
|
908
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
909
|
+
const inputRef = useRef(null);
|
|
910
|
+
const theme = useFormTheme();
|
|
911
|
+
const labels = useFormLabels();
|
|
912
|
+
const handleChange = (e) => {
|
|
913
|
+
if (e.target.files && e.target.files.length > 0) {
|
|
914
|
+
setFileName(e.target.files[0].name);
|
|
915
|
+
} else {
|
|
916
|
+
setFileName(null);
|
|
917
|
+
}
|
|
918
|
+
};
|
|
919
|
+
const handleDragEnter = (e) => {
|
|
920
|
+
e.preventDefault();
|
|
921
|
+
e.stopPropagation();
|
|
922
|
+
if (!disabled) setIsDragging(true);
|
|
923
|
+
};
|
|
924
|
+
const handleDragLeave = (e) => {
|
|
925
|
+
e.preventDefault();
|
|
926
|
+
e.stopPropagation();
|
|
927
|
+
setIsDragging(false);
|
|
928
|
+
};
|
|
929
|
+
const handleDragOver = (e) => {
|
|
930
|
+
e.preventDefault();
|
|
931
|
+
e.stopPropagation();
|
|
932
|
+
if (!disabled) setIsDragging(true);
|
|
933
|
+
};
|
|
934
|
+
const handleDrop = (e) => {
|
|
935
|
+
e.preventDefault();
|
|
936
|
+
e.stopPropagation();
|
|
937
|
+
setIsDragging(false);
|
|
938
|
+
if (disabled) return;
|
|
939
|
+
if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
|
|
940
|
+
if (inputRef.current) {
|
|
941
|
+
inputRef.current.files = e.dataTransfer.files;
|
|
942
|
+
setFileName(e.dataTransfer.files[0].name);
|
|
943
|
+
const event = new Event("change", { bubbles: true });
|
|
944
|
+
inputRef.current.dispatchEvent(event);
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
};
|
|
948
|
+
const getFileUrl = () => {
|
|
949
|
+
if (!defaultValue) return null;
|
|
950
|
+
if (baseUrl && uploadDir) {
|
|
951
|
+
return `${baseUrl}/${uploadDir}/${defaultValue}`;
|
|
952
|
+
}
|
|
953
|
+
if (baseUrl) {
|
|
954
|
+
return `${baseUrl}/${defaultValue}`;
|
|
955
|
+
}
|
|
956
|
+
return null;
|
|
957
|
+
};
|
|
958
|
+
const fileUrl = getFileUrl();
|
|
959
|
+
return /* @__PURE__ */ jsxs("div", { className: cx(theme.formGroup, className), children: [
|
|
960
|
+
before && /* @__PURE__ */ jsx("p", { className: beforeClassName ?? "", children: before }),
|
|
961
|
+
/* @__PURE__ */ jsxs("div", { className: cx(theme.label?.base, "mb-1"), children: [
|
|
962
|
+
label,
|
|
963
|
+
rules?.required && /* @__PURE__ */ jsx("span", { className: theme.label?.required, children: "*" })
|
|
964
|
+
] }),
|
|
965
|
+
/* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
966
|
+
/* @__PURE__ */ jsx(
|
|
967
|
+
"input",
|
|
968
|
+
{
|
|
969
|
+
ref: inputRef,
|
|
970
|
+
type: "file",
|
|
971
|
+
name,
|
|
972
|
+
id: name,
|
|
973
|
+
disabled,
|
|
974
|
+
onChange: handleChange,
|
|
975
|
+
"aria-invalid": !!error,
|
|
976
|
+
"aria-describedby": error ? `${name}-error` : void 0,
|
|
977
|
+
className: "sr-only",
|
|
978
|
+
accept: rules?.mimeTypes ? rules.mimeTypes.map((type) => mimeTypes[type]).join(",") : "*"
|
|
979
|
+
}
|
|
980
|
+
),
|
|
981
|
+
/* @__PURE__ */ jsx(
|
|
982
|
+
"label",
|
|
983
|
+
{
|
|
984
|
+
htmlFor: name,
|
|
985
|
+
onDragEnter: handleDragEnter,
|
|
986
|
+
onDragLeave: handleDragLeave,
|
|
987
|
+
onDragOver: handleDragOver,
|
|
988
|
+
onDrop: handleDrop,
|
|
989
|
+
className: cx(
|
|
990
|
+
theme.file?.dropzone,
|
|
991
|
+
disabled && "cursor-not-allowed",
|
|
992
|
+
isDragging && theme.file?.dropzoneActive,
|
|
993
|
+
error && theme.file?.dropzoneError
|
|
994
|
+
),
|
|
995
|
+
children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center justify-center", children: [
|
|
996
|
+
/* @__PURE__ */ jsx(
|
|
997
|
+
"svg",
|
|
998
|
+
{
|
|
999
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1000
|
+
className: theme.file?.icon,
|
|
1001
|
+
fill: "none",
|
|
1002
|
+
viewBox: "0 0 24 24",
|
|
1003
|
+
stroke: "currentColor",
|
|
1004
|
+
children: /* @__PURE__ */ jsx(
|
|
1005
|
+
"path",
|
|
1006
|
+
{
|
|
1007
|
+
strokeLinecap: "round",
|
|
1008
|
+
strokeLinejoin: "round",
|
|
1009
|
+
strokeWidth: 2,
|
|
1010
|
+
d: "M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M15 13l-3-3m0 0l-3 3m3-3v12"
|
|
1011
|
+
}
|
|
1012
|
+
)
|
|
1013
|
+
}
|
|
1014
|
+
),
|
|
1015
|
+
/* @__PURE__ */ jsx("p", { className: theme.file?.text, children: fileName ? /* @__PURE__ */ jsx("span", { className: "font-medium text-primary", children: fileName }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1016
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium", children: labels.fileUpload?.clickToUpload }),
|
|
1017
|
+
" ",
|
|
1018
|
+
labels.fileUpload?.dragAndDrop
|
|
1019
|
+
] }) }),
|
|
1020
|
+
rules?.mimeTypes && /* @__PURE__ */ jsxs("p", { className: theme.file?.hint, children: [
|
|
1021
|
+
labels.fileUpload?.allowedTypes,
|
|
1022
|
+
" ",
|
|
1023
|
+
Object.values(rules.mimeTypes).join(", ")
|
|
1024
|
+
] }),
|
|
1025
|
+
rules?.maxFileSize && /* @__PURE__ */ jsxs("p", { className: theme.file?.hint, children: [
|
|
1026
|
+
labels.fileUpload?.maxSize,
|
|
1027
|
+
" ",
|
|
1028
|
+
Math.round(
|
|
1029
|
+
rules.maxFileSize / 1024 / 1024 * 10
|
|
1030
|
+
) / 10,
|
|
1031
|
+
" ",
|
|
1032
|
+
"MB"
|
|
1033
|
+
] })
|
|
1034
|
+
] })
|
|
1035
|
+
}
|
|
1036
|
+
),
|
|
1037
|
+
fileUrl && defaultValue && isImage(defaultValue.toString()) && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1038
|
+
/* @__PURE__ */ jsx(
|
|
1039
|
+
"img",
|
|
1040
|
+
{
|
|
1041
|
+
src: fileUrl,
|
|
1042
|
+
alt: "",
|
|
1043
|
+
className: "mt-2 max-h-40 object-contain rounded-md border border-gray-300 dark:border-gray-600"
|
|
1044
|
+
}
|
|
1045
|
+
),
|
|
1046
|
+
/* @__PURE__ */ jsxs(
|
|
1047
|
+
"a",
|
|
1048
|
+
{
|
|
1049
|
+
href: fileUrl,
|
|
1050
|
+
target: "_blank",
|
|
1051
|
+
rel: "noopener noreferrer",
|
|
1052
|
+
className: "mt-2 inline-flex items-center text-xs text-primary hover:underline dark:text-gray-50",
|
|
1053
|
+
children: [
|
|
1054
|
+
"View Current ",
|
|
1055
|
+
label,
|
|
1056
|
+
/* @__PURE__ */ jsx(
|
|
1057
|
+
"svg",
|
|
1058
|
+
{
|
|
1059
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1060
|
+
className: "ml-1 h-4 w-4",
|
|
1061
|
+
fill: "none",
|
|
1062
|
+
viewBox: "0 0 24 24",
|
|
1063
|
+
stroke: "currentColor",
|
|
1064
|
+
children: /* @__PURE__ */ jsx(
|
|
1065
|
+
"path",
|
|
1066
|
+
{
|
|
1067
|
+
strokeLinecap: "round",
|
|
1068
|
+
strokeLinejoin: "round",
|
|
1069
|
+
strokeWidth: 2,
|
|
1070
|
+
d: "M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"
|
|
1071
|
+
}
|
|
1072
|
+
)
|
|
1073
|
+
}
|
|
1074
|
+
)
|
|
1075
|
+
]
|
|
1076
|
+
}
|
|
1077
|
+
)
|
|
1078
|
+
] })
|
|
1079
|
+
] }),
|
|
1080
|
+
error && /* @__PURE__ */ jsx("p", { id: `${name}-error`, className: theme.error, children: error }),
|
|
1081
|
+
after && /* @__PURE__ */ jsx("p", { className: afterClassName ?? "", children: after })
|
|
1082
|
+
] });
|
|
1083
|
+
}
|
|
1084
|
+
var FileInput_default = memo(FileInput);
|
|
1085
|
+
function HiddenInput({
|
|
1086
|
+
name,
|
|
1087
|
+
defaultValue,
|
|
1088
|
+
className,
|
|
1089
|
+
disabled
|
|
1090
|
+
}) {
|
|
1091
|
+
return /* @__PURE__ */ jsx(
|
|
1092
|
+
"input",
|
|
1093
|
+
{
|
|
1094
|
+
type: "hidden",
|
|
1095
|
+
name,
|
|
1096
|
+
defaultValue: defaultValue?.toString(),
|
|
1097
|
+
disabled,
|
|
1098
|
+
className
|
|
1099
|
+
}
|
|
1100
|
+
);
|
|
1101
|
+
}
|
|
1102
|
+
function SubmitInput({
|
|
1103
|
+
label,
|
|
1104
|
+
name,
|
|
1105
|
+
className,
|
|
1106
|
+
disabled,
|
|
1107
|
+
loading,
|
|
1108
|
+
defaultValue,
|
|
1109
|
+
hideSpinner
|
|
1110
|
+
}) {
|
|
1111
|
+
const theme = useFormTheme();
|
|
1112
|
+
return /* @__PURE__ */ jsxs(
|
|
1113
|
+
"button",
|
|
1114
|
+
{
|
|
1115
|
+
type: "submit",
|
|
1116
|
+
name,
|
|
1117
|
+
disabled: disabled || loading,
|
|
1118
|
+
value: defaultValue?.toString() ?? "",
|
|
1119
|
+
className: cx(
|
|
1120
|
+
theme.submit?.base,
|
|
1121
|
+
loading && theme.submit?.loading,
|
|
1122
|
+
className
|
|
1123
|
+
),
|
|
1124
|
+
children: [
|
|
1125
|
+
loading && hideSpinner !== true && /* @__PURE__ */ jsxs(
|
|
1126
|
+
"svg",
|
|
1127
|
+
{
|
|
1128
|
+
className: theme.submit?.spinner,
|
|
1129
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1130
|
+
fill: "none",
|
|
1131
|
+
viewBox: "0 0 24 24",
|
|
1132
|
+
children: [
|
|
1133
|
+
/* @__PURE__ */ jsx(
|
|
1134
|
+
"circle",
|
|
1135
|
+
{
|
|
1136
|
+
className: "opacity-25",
|
|
1137
|
+
cx: "12",
|
|
1138
|
+
cy: "12",
|
|
1139
|
+
r: "10",
|
|
1140
|
+
stroke: "currentColor",
|
|
1141
|
+
strokeWidth: "4"
|
|
1142
|
+
}
|
|
1143
|
+
),
|
|
1144
|
+
/* @__PURE__ */ jsx(
|
|
1145
|
+
"path",
|
|
1146
|
+
{
|
|
1147
|
+
className: "opacity-75",
|
|
1148
|
+
fill: "currentColor",
|
|
1149
|
+
d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
|
1150
|
+
}
|
|
1151
|
+
)
|
|
1152
|
+
]
|
|
1153
|
+
}
|
|
1154
|
+
),
|
|
1155
|
+
label
|
|
1156
|
+
]
|
|
1157
|
+
}
|
|
1158
|
+
);
|
|
1159
|
+
}
|
|
1160
|
+
function NoneInput({ label, value, className }) {
|
|
1161
|
+
const theme = useFormTheme();
|
|
1162
|
+
const isJsonString = (str) => {
|
|
1163
|
+
try {
|
|
1164
|
+
JSON.parse(str);
|
|
1165
|
+
return true;
|
|
1166
|
+
} catch {
|
|
1167
|
+
return false;
|
|
1168
|
+
}
|
|
1169
|
+
};
|
|
1170
|
+
return /* @__PURE__ */ jsxs("div", { className: cx(theme.formGroup, className), children: [
|
|
1171
|
+
/* @__PURE__ */ jsx("span", { className: theme.label?.base, children: label }),
|
|
1172
|
+
/* @__PURE__ */ jsx("div", { className: theme.readonly, children: isJsonString(value) ? /* @__PURE__ */ jsx("ul", { className: "list-disc list-inside space-y-1", children: Object.entries(JSON.parse(value)).map(([key, val]) => /* @__PURE__ */ jsxs("li", { className: "text-sm", children: [
|
|
1173
|
+
/* @__PURE__ */ jsxs("span", { className: "font-medium", children: [
|
|
1174
|
+
key,
|
|
1175
|
+
":"
|
|
1176
|
+
] }),
|
|
1177
|
+
" ",
|
|
1178
|
+
String(val)
|
|
1179
|
+
] }, key)) }) : value })
|
|
1180
|
+
] });
|
|
1181
|
+
}
|
|
1182
|
+
var NoneInput_default = memo(NoneInput);
|
|
1183
|
+
function Form({
|
|
1184
|
+
config,
|
|
1185
|
+
className,
|
|
1186
|
+
errors,
|
|
1187
|
+
isSubmitting = false,
|
|
1188
|
+
formElement: FormElement,
|
|
1189
|
+
formProps = {},
|
|
1190
|
+
fileBaseUrl
|
|
1191
|
+
}) {
|
|
1192
|
+
const theme = useFormTheme();
|
|
1193
|
+
const {
|
|
1194
|
+
method = "post",
|
|
1195
|
+
encType = config.encType || "application/x-www-form-urlencoded",
|
|
1196
|
+
action = "",
|
|
1197
|
+
fields
|
|
1198
|
+
} = config;
|
|
1199
|
+
const state = {
|
|
1200
|
+
errors,
|
|
1201
|
+
isSubmitting
|
|
1202
|
+
};
|
|
1203
|
+
const contextValue = {
|
|
1204
|
+
state,
|
|
1205
|
+
config
|
|
1206
|
+
};
|
|
1207
|
+
const FormTag = FormElement || "form";
|
|
1208
|
+
const formContent = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1209
|
+
errors && "__server" in errors && errors.__server ? /* @__PURE__ */ jsx(Alert_default, { type: "error", message: errors.__server }) : null,
|
|
1210
|
+
/* @__PURE__ */ jsx(
|
|
1211
|
+
"fieldset",
|
|
1212
|
+
{
|
|
1213
|
+
className: theme.fieldset,
|
|
1214
|
+
disabled: isSubmitting,
|
|
1215
|
+
children: Object.entries(fields).map(([key, field]) => {
|
|
1216
|
+
const fieldError = errors?.[key];
|
|
1217
|
+
switch (field.type) {
|
|
1218
|
+
case "text":
|
|
1219
|
+
case "email":
|
|
1220
|
+
case "password":
|
|
1221
|
+
case "number":
|
|
1222
|
+
return /* @__PURE__ */ jsx(
|
|
1223
|
+
TextInput_default,
|
|
1224
|
+
{
|
|
1225
|
+
label: field.label,
|
|
1226
|
+
placeholder: field.placeholder,
|
|
1227
|
+
name: key,
|
|
1228
|
+
defaultValue: field.defaultValue,
|
|
1229
|
+
className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
|
|
1230
|
+
disabled: field.disabled,
|
|
1231
|
+
error: fieldError,
|
|
1232
|
+
rules: field.rules,
|
|
1233
|
+
type: field.type,
|
|
1234
|
+
before: field.before,
|
|
1235
|
+
beforeClassName: field.beforeClassName,
|
|
1236
|
+
after: field.after,
|
|
1237
|
+
afterClassName: field.afterClassName
|
|
1238
|
+
},
|
|
1239
|
+
key
|
|
1240
|
+
);
|
|
1241
|
+
case "datetime":
|
|
1242
|
+
return /* @__PURE__ */ jsx(
|
|
1243
|
+
DateTimeInput_default,
|
|
1244
|
+
{
|
|
1245
|
+
label: field.label,
|
|
1246
|
+
placeholder: field.placeholder,
|
|
1247
|
+
name: key,
|
|
1248
|
+
defaultValue: field.defaultValue,
|
|
1249
|
+
className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
|
|
1250
|
+
disabled: field.disabled,
|
|
1251
|
+
error: fieldError,
|
|
1252
|
+
rules: field.rules,
|
|
1253
|
+
before: field.before,
|
|
1254
|
+
beforeClassName: field.beforeClassName,
|
|
1255
|
+
after: field.after,
|
|
1256
|
+
afterClassName: field.afterClassName
|
|
1257
|
+
},
|
|
1258
|
+
key
|
|
1259
|
+
);
|
|
1260
|
+
case "select":
|
|
1261
|
+
return /* @__PURE__ */ jsx(
|
|
1262
|
+
SelectInput_default,
|
|
1263
|
+
{
|
|
1264
|
+
label: field.label,
|
|
1265
|
+
name: key,
|
|
1266
|
+
options: field.options,
|
|
1267
|
+
defaultValue: field.defaultValue,
|
|
1268
|
+
className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
|
|
1269
|
+
disabled: field.disabled,
|
|
1270
|
+
error: fieldError,
|
|
1271
|
+
rules: field.rules,
|
|
1272
|
+
before: field.before,
|
|
1273
|
+
beforeClassName: field.beforeClassName,
|
|
1274
|
+
after: field.after,
|
|
1275
|
+
afterClassName: field.afterClassName
|
|
1276
|
+
},
|
|
1277
|
+
key
|
|
1278
|
+
);
|
|
1279
|
+
case "textarea":
|
|
1280
|
+
return /* @__PURE__ */ jsx(
|
|
1281
|
+
TextAreaInput_default,
|
|
1282
|
+
{
|
|
1283
|
+
label: field.label,
|
|
1284
|
+
placeholder: field.placeholder,
|
|
1285
|
+
name: key,
|
|
1286
|
+
defaultValue: field.defaultValue,
|
|
1287
|
+
className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
|
|
1288
|
+
disabled: field.disabled,
|
|
1289
|
+
error: fieldError,
|
|
1290
|
+
rules: field.rules,
|
|
1291
|
+
before: field.before,
|
|
1292
|
+
beforeClassName: field.beforeClassName,
|
|
1293
|
+
after: field.after,
|
|
1294
|
+
afterClassName: field.afterClassName
|
|
1295
|
+
},
|
|
1296
|
+
key
|
|
1297
|
+
);
|
|
1298
|
+
case "checkbox":
|
|
1299
|
+
return /* @__PURE__ */ jsx(
|
|
1300
|
+
CheckboxInput_default,
|
|
1301
|
+
{
|
|
1302
|
+
label: field.label,
|
|
1303
|
+
name: key,
|
|
1304
|
+
defaultChecked: field.defaultChecked,
|
|
1305
|
+
className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
|
|
1306
|
+
disabled: field.disabled,
|
|
1307
|
+
error: fieldError,
|
|
1308
|
+
rules: field.rules,
|
|
1309
|
+
before: field.before,
|
|
1310
|
+
beforeClassName: field.beforeClassName,
|
|
1311
|
+
after: field.after,
|
|
1312
|
+
afterClassName: field.afterClassName
|
|
1313
|
+
},
|
|
1314
|
+
key
|
|
1315
|
+
);
|
|
1316
|
+
case "toggle":
|
|
1317
|
+
return /* @__PURE__ */ jsx(
|
|
1318
|
+
ToggleInput_default,
|
|
1319
|
+
{
|
|
1320
|
+
label: field.label,
|
|
1321
|
+
name: key,
|
|
1322
|
+
defaultChecked: field.defaultChecked,
|
|
1323
|
+
className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
|
|
1324
|
+
disabled: field.disabled,
|
|
1325
|
+
error: fieldError,
|
|
1326
|
+
rules: field.rules,
|
|
1327
|
+
before: field.before,
|
|
1328
|
+
beforeClassName: field.beforeClassName,
|
|
1329
|
+
after: field.after,
|
|
1330
|
+
afterClassName: field.afterClassName
|
|
1331
|
+
},
|
|
1332
|
+
key
|
|
1333
|
+
);
|
|
1334
|
+
case "radio":
|
|
1335
|
+
return /* @__PURE__ */ jsx(
|
|
1336
|
+
RadioInput_default,
|
|
1337
|
+
{
|
|
1338
|
+
label: field.label,
|
|
1339
|
+
name: key,
|
|
1340
|
+
options: field.options,
|
|
1341
|
+
defaultValue: field.defaultValue,
|
|
1342
|
+
className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
|
|
1343
|
+
disabled: field.disabled,
|
|
1344
|
+
error: fieldError,
|
|
1345
|
+
rules: field.rules,
|
|
1346
|
+
before: field.before,
|
|
1347
|
+
beforeClassName: field.beforeClassName,
|
|
1348
|
+
after: field.after,
|
|
1349
|
+
afterClassName: field.afterClassName
|
|
1350
|
+
},
|
|
1351
|
+
key
|
|
1352
|
+
);
|
|
1353
|
+
case "file":
|
|
1354
|
+
return /* @__PURE__ */ jsx(
|
|
1355
|
+
FileInput_default,
|
|
1356
|
+
{
|
|
1357
|
+
label: field.label,
|
|
1358
|
+
name: key,
|
|
1359
|
+
className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
|
|
1360
|
+
disabled: field.disabled,
|
|
1361
|
+
defaultValue: field.defaultValue,
|
|
1362
|
+
error: fieldError,
|
|
1363
|
+
rules: field.rules,
|
|
1364
|
+
before: field.before,
|
|
1365
|
+
beforeClassName: field.beforeClassName,
|
|
1366
|
+
after: field.after,
|
|
1367
|
+
afterClassName: field.afterClassName,
|
|
1368
|
+
metaData: field.metaData,
|
|
1369
|
+
uploadDir: field.uploadDir,
|
|
1370
|
+
baseUrl: fileBaseUrl
|
|
1371
|
+
},
|
|
1372
|
+
key
|
|
1373
|
+
);
|
|
1374
|
+
case "hidden":
|
|
1375
|
+
return /* @__PURE__ */ jsx(
|
|
1376
|
+
HiddenInput,
|
|
1377
|
+
{
|
|
1378
|
+
name: key,
|
|
1379
|
+
defaultValue: field.defaultValue,
|
|
1380
|
+
disabled: field.disabled
|
|
1381
|
+
},
|
|
1382
|
+
key
|
|
1383
|
+
);
|
|
1384
|
+
case "submit":
|
|
1385
|
+
return /* @__PURE__ */ jsx(
|
|
1386
|
+
SubmitInput,
|
|
1387
|
+
{
|
|
1388
|
+
label: field.label,
|
|
1389
|
+
name: key,
|
|
1390
|
+
className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
|
|
1391
|
+
disabled: field.disabled,
|
|
1392
|
+
rules: field.rules,
|
|
1393
|
+
loading: isSubmitting,
|
|
1394
|
+
defaultValue: field.defaultValue,
|
|
1395
|
+
hideSpinner: field.hideSpinner
|
|
1396
|
+
},
|
|
1397
|
+
key
|
|
1398
|
+
);
|
|
1399
|
+
case "none":
|
|
1400
|
+
return /* @__PURE__ */ jsx(
|
|
1401
|
+
NoneInput_default,
|
|
1402
|
+
{
|
|
1403
|
+
className: `${widthClasses[field.width || 12]} ${field.className || ""}`,
|
|
1404
|
+
value: field.defaultValue?.toString() ?? "",
|
|
1405
|
+
label: field.label
|
|
1406
|
+
},
|
|
1407
|
+
key
|
|
1408
|
+
);
|
|
1409
|
+
default:
|
|
1410
|
+
return null;
|
|
1411
|
+
}
|
|
1412
|
+
})
|
|
1413
|
+
}
|
|
1414
|
+
)
|
|
1415
|
+
] });
|
|
1416
|
+
return /* @__PURE__ */ jsx(FormContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
|
|
1417
|
+
FormTag,
|
|
1418
|
+
{
|
|
1419
|
+
method,
|
|
1420
|
+
encType,
|
|
1421
|
+
action,
|
|
1422
|
+
className: cx(theme.form, className),
|
|
1423
|
+
noValidate: true,
|
|
1424
|
+
...formProps,
|
|
1425
|
+
children: formContent
|
|
1426
|
+
}
|
|
1427
|
+
) });
|
|
1428
|
+
}
|
|
1429
|
+
function ReactRouterForm({
|
|
1430
|
+
config,
|
|
1431
|
+
className,
|
|
1432
|
+
fileBaseUrl
|
|
1433
|
+
}) {
|
|
1434
|
+
const fetcher = useFetcher({ key: config.key });
|
|
1435
|
+
const errors = fetcher.data?.errors;
|
|
1436
|
+
const isSubmitting = fetcher.state !== "idle";
|
|
1437
|
+
return /* @__PURE__ */ jsx(
|
|
1438
|
+
Form,
|
|
1439
|
+
{
|
|
1440
|
+
config,
|
|
1441
|
+
className,
|
|
1442
|
+
errors,
|
|
1443
|
+
isSubmitting,
|
|
1444
|
+
formElement: fetcher.Form,
|
|
1445
|
+
fileBaseUrl
|
|
1446
|
+
}
|
|
1447
|
+
);
|
|
1448
|
+
}
|
|
1449
|
+
function useReactRouterForm(formKey) {
|
|
1450
|
+
const fetcher = useFetcher({ key: formKey });
|
|
1451
|
+
const errors = fetcher.data?.errors;
|
|
1452
|
+
const isSubmitting = fetcher.state !== "idle";
|
|
1453
|
+
return {
|
|
1454
|
+
fetcher,
|
|
1455
|
+
errors,
|
|
1456
|
+
isSubmitting,
|
|
1457
|
+
data: fetcher.data
|
|
1458
|
+
};
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
export { ReactRouterForm, useReactRouterForm };
|
|
1462
|
+
//# sourceMappingURL=react-router.js.map
|
|
1463
|
+
//# sourceMappingURL=react-router.js.map
|