formik-mui-fields 0.1.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 +192 -0
- package/dist/index.cjs +646 -0
- package/dist/index.d.cts +103 -0
- package/dist/index.d.ts +103 -0
- package/dist/index.js +660 -0
- package/package.json +120 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,646 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/index.ts
|
|
32
|
+
var index_exports = {};
|
|
33
|
+
__export(index_exports, {
|
|
34
|
+
FormikAutocomplete: () => FormikAutocomplete_default,
|
|
35
|
+
FormikCheckbox: () => FormikCheckbox_default,
|
|
36
|
+
FormikColorPicker: () => FormikColorPicker_default,
|
|
37
|
+
FormikDatePicker: () => FormikDatePicker_default,
|
|
38
|
+
FormikFontPicker: () => FormikFontPicker_default,
|
|
39
|
+
FormikImageUpload: () => FormikImageUpload_default,
|
|
40
|
+
FormikRadioGroup: () => FormikRadioGroup_default,
|
|
41
|
+
FormikRating: () => FormikRating_default,
|
|
42
|
+
FormikSelect: () => FormikSelect_default,
|
|
43
|
+
FormikSlider: () => FormikSlider_default,
|
|
44
|
+
FormikSwitch: () => FormikSwitch_default,
|
|
45
|
+
FormikTextField: () => FormikTextField_default,
|
|
46
|
+
FormikToggleButtonGroup: () => FormikToggleButtonGroup_default
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(index_exports);
|
|
49
|
+
|
|
50
|
+
// src/FormikTextField/FormikTextField.tsx
|
|
51
|
+
var import_material = require("@mui/material");
|
|
52
|
+
var import_formik = require("formik");
|
|
53
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
54
|
+
var FormikTextField = ({ name, ...props }) => {
|
|
55
|
+
const [field, meta] = (0, import_formik.useField)(name);
|
|
56
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
57
|
+
import_material.TextField,
|
|
58
|
+
{
|
|
59
|
+
...field,
|
|
60
|
+
...props,
|
|
61
|
+
error: meta.touched && Boolean(meta.error),
|
|
62
|
+
helperText: meta.touched && meta.error
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
var FormikTextField_default = FormikTextField;
|
|
67
|
+
|
|
68
|
+
// src/FormikSelect/FormikSelect.tsx
|
|
69
|
+
var import_material2 = require("@mui/material");
|
|
70
|
+
var import_formik2 = require("formik");
|
|
71
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
72
|
+
var FormikSelect = ({ name, label, options, ...props }) => {
|
|
73
|
+
const [field, meta] = (0, import_formik2.useField)(name);
|
|
74
|
+
const hasError = meta.touched && Boolean(meta.error);
|
|
75
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_material2.FormControl, { fullWidth: true, error: hasError, children: [
|
|
76
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material2.FormLabel, { children: label }),
|
|
77
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material2.Select, { ...field, ...props, children: options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material2.MenuItem, { value: option.value, children: option.label }, option.value)) }),
|
|
78
|
+
hasError && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material2.FormHelperText, { children: meta.error })
|
|
79
|
+
] });
|
|
80
|
+
};
|
|
81
|
+
var FormikSelect_default = FormikSelect;
|
|
82
|
+
|
|
83
|
+
// src/FormikRadioGroup/FormikRadioGroup.tsx
|
|
84
|
+
var import_material3 = require("@mui/material");
|
|
85
|
+
var import_formik3 = require("formik");
|
|
86
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
87
|
+
var FormikRadioGroup = ({ name, label, options, row }) => {
|
|
88
|
+
const [field, meta] = (0, import_formik3.useField)(name);
|
|
89
|
+
const hasError = meta.touched && Boolean(meta.error);
|
|
90
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_material3.FormControl, { error: hasError, children: [
|
|
91
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material3.FormLabel, { children: label }),
|
|
92
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material3.RadioGroup, { ...field, row, children: options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
93
|
+
import_material3.FormControlLabel,
|
|
94
|
+
{
|
|
95
|
+
value: option.value,
|
|
96
|
+
control: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material3.Radio, {}),
|
|
97
|
+
label: option.label
|
|
98
|
+
},
|
|
99
|
+
option.value
|
|
100
|
+
)) }),
|
|
101
|
+
hasError && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material3.FormHelperText, { children: meta.error })
|
|
102
|
+
] });
|
|
103
|
+
};
|
|
104
|
+
var FormikRadioGroup_default = FormikRadioGroup;
|
|
105
|
+
|
|
106
|
+
// src/FormikSlider/FormikSlider.tsx
|
|
107
|
+
var import_material4 = require("@mui/material");
|
|
108
|
+
var import_formik4 = require("formik");
|
|
109
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
110
|
+
var FormikSlider = ({ name, label, ...props }) => {
|
|
111
|
+
const [field, meta, helpers] = (0, import_formik4.useField)(name);
|
|
112
|
+
const hasError = meta.touched && Boolean(meta.error);
|
|
113
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_material4.FormControl, { fullWidth: true, error: hasError, children: [
|
|
114
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_material4.FormLabel, { children: label }),
|
|
115
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
116
|
+
import_material4.Slider,
|
|
117
|
+
{
|
|
118
|
+
...props,
|
|
119
|
+
value: field.value,
|
|
120
|
+
onChange: (_, value) => helpers.setValue(value),
|
|
121
|
+
onBlur: field.onBlur
|
|
122
|
+
}
|
|
123
|
+
),
|
|
124
|
+
hasError && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_material4.FormHelperText, { children: meta.error })
|
|
125
|
+
] });
|
|
126
|
+
};
|
|
127
|
+
var FormikSlider_default = FormikSlider;
|
|
128
|
+
|
|
129
|
+
// src/FormikColorPicker/FormikColorPicker.tsx
|
|
130
|
+
var import_material5 = require("@mui/material");
|
|
131
|
+
var import_formik5 = require("formik");
|
|
132
|
+
var import_react = require("react");
|
|
133
|
+
var import_react_color = require("react-color");
|
|
134
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
135
|
+
var FormikColorPicker = ({ name, label }) => {
|
|
136
|
+
const [field, , helpers] = (0, import_formik5.useField)(name);
|
|
137
|
+
const [open, setOpen] = (0, import_react.useState)(false);
|
|
138
|
+
const anchorRef = (0, import_react.useRef)(null);
|
|
139
|
+
const handleChange = (color) => {
|
|
140
|
+
helpers.setValue(color.hex);
|
|
141
|
+
};
|
|
142
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_material5.FormControl, { children: [
|
|
143
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_material5.FormLabel, { sx: { mb: 1 }, children: label }),
|
|
144
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
145
|
+
import_material5.Box,
|
|
146
|
+
{
|
|
147
|
+
ref: anchorRef,
|
|
148
|
+
onClick: () => setOpen((prev) => !prev),
|
|
149
|
+
sx: {
|
|
150
|
+
width: 32,
|
|
151
|
+
height: 32,
|
|
152
|
+
borderRadius: "50%",
|
|
153
|
+
backgroundColor: field.value,
|
|
154
|
+
border: "2px solid",
|
|
155
|
+
borderColor: "grey.300",
|
|
156
|
+
cursor: "pointer",
|
|
157
|
+
transition: "border-color 0.2s",
|
|
158
|
+
"&:hover": { borderColor: "grey.500" }
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
),
|
|
162
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
163
|
+
import_material5.Popper,
|
|
164
|
+
{
|
|
165
|
+
open,
|
|
166
|
+
anchorEl: anchorRef.current,
|
|
167
|
+
placement: "bottom-start",
|
|
168
|
+
sx: { zIndex: 1500 },
|
|
169
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_material5.ClickAwayListener, { onClickAway: () => setOpen(false), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_material5.Box, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
170
|
+
import_react_color.ChromePicker,
|
|
171
|
+
{
|
|
172
|
+
color: field.value,
|
|
173
|
+
onChange: handleChange,
|
|
174
|
+
disableAlpha: true
|
|
175
|
+
}
|
|
176
|
+
) }) })
|
|
177
|
+
}
|
|
178
|
+
)
|
|
179
|
+
] });
|
|
180
|
+
};
|
|
181
|
+
var FormikColorPicker_default = FormikColorPicker;
|
|
182
|
+
|
|
183
|
+
// src/FormikFontPicker/FormikFontPicker.tsx
|
|
184
|
+
var import_react2 = require("react");
|
|
185
|
+
var import_material6 = require("@mui/material");
|
|
186
|
+
var import_formik6 = require("formik");
|
|
187
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
188
|
+
var FormikFontPicker = ({ name, label }) => {
|
|
189
|
+
const [fonts, setFonts] = (0, import_react2.useState)([]);
|
|
190
|
+
const [loading, setLoading] = (0, import_react2.useState)(true);
|
|
191
|
+
const [field, meta, helpers] = (0, import_formik6.useField)(name);
|
|
192
|
+
(0, import_react2.useEffect)(() => {
|
|
193
|
+
fetch("/api/google/fonts").then((res) => res.json()).then((data) => setFonts(data)).catch(() => setFonts([])).finally(() => setLoading(false));
|
|
194
|
+
}, []);
|
|
195
|
+
(0, import_react2.useEffect)(() => {
|
|
196
|
+
if (!field.value) return;
|
|
197
|
+
const linkId = "google-font-preview";
|
|
198
|
+
let link = document.getElementById(linkId);
|
|
199
|
+
if (!link) {
|
|
200
|
+
link = document.createElement("link");
|
|
201
|
+
link.id = linkId;
|
|
202
|
+
link.rel = "stylesheet";
|
|
203
|
+
document.head.appendChild(link);
|
|
204
|
+
}
|
|
205
|
+
link.href = `https://fonts.googleapis.com/css2?family=${encodeURIComponent(field.value)}&display=swap`;
|
|
206
|
+
}, [field.value]);
|
|
207
|
+
const selectedOption = fonts.find((f) => f.value === field.value) ?? null;
|
|
208
|
+
const hasError = meta.touched && Boolean(meta.error);
|
|
209
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_material6.FormControl, { fullWidth: true, error: hasError, children: [
|
|
210
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_material6.FormLabel, { children: label }),
|
|
211
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
212
|
+
import_material6.Autocomplete,
|
|
213
|
+
{
|
|
214
|
+
options: fonts,
|
|
215
|
+
loading,
|
|
216
|
+
getOptionLabel: (option) => option.label,
|
|
217
|
+
value: selectedOption,
|
|
218
|
+
onChange: (_, newValue) => {
|
|
219
|
+
helpers.setValue(newValue?.value ?? "");
|
|
220
|
+
},
|
|
221
|
+
onBlur: () => helpers.setTouched(true),
|
|
222
|
+
isOptionEqualToValue: (option, value) => option.value === value.value,
|
|
223
|
+
renderInput: (params) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
224
|
+
import_material6.TextField,
|
|
225
|
+
{
|
|
226
|
+
...params,
|
|
227
|
+
size: "small",
|
|
228
|
+
error: hasError,
|
|
229
|
+
helperText: hasError ? meta.error : void 0
|
|
230
|
+
}
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
)
|
|
234
|
+
] });
|
|
235
|
+
};
|
|
236
|
+
var FormikFontPicker_default = FormikFontPicker;
|
|
237
|
+
|
|
238
|
+
// src/FormikImageUpload/FormikImageUpload.tsx
|
|
239
|
+
var import_material8 = require("@mui/material");
|
|
240
|
+
var import_formik7 = require("formik");
|
|
241
|
+
var import_react4 = require("react");
|
|
242
|
+
|
|
243
|
+
// src/CropDialog/CropDialog.tsx
|
|
244
|
+
var import_material7 = require("@mui/material");
|
|
245
|
+
var import_react3 = require("react");
|
|
246
|
+
var import_react_image_crop = __toESM(require("react-image-crop"), 1);
|
|
247
|
+
var import_ReactCrop = require("react-image-crop/dist/ReactCrop.css");
|
|
248
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
249
|
+
var ASPECT_RATIOS = {
|
|
250
|
+
"1.91:1": 1.91,
|
|
251
|
+
"1:1": 1,
|
|
252
|
+
"3:1": 3
|
|
253
|
+
};
|
|
254
|
+
var getCroppedImageUrl = (image, crop) => {
|
|
255
|
+
const canvas = document.createElement("canvas");
|
|
256
|
+
const scaleX = image.naturalWidth / image.width;
|
|
257
|
+
const scaleY = image.naturalHeight / image.height;
|
|
258
|
+
canvas.width = crop.width * scaleX;
|
|
259
|
+
canvas.height = crop.height * scaleY;
|
|
260
|
+
const ctx = canvas.getContext("2d");
|
|
261
|
+
if (!ctx) return "";
|
|
262
|
+
ctx.drawImage(
|
|
263
|
+
image,
|
|
264
|
+
crop.x * scaleX,
|
|
265
|
+
crop.y * scaleY,
|
|
266
|
+
crop.width * scaleX,
|
|
267
|
+
crop.height * scaleY,
|
|
268
|
+
0,
|
|
269
|
+
0,
|
|
270
|
+
canvas.width,
|
|
271
|
+
canvas.height
|
|
272
|
+
);
|
|
273
|
+
return canvas.toDataURL("image/png");
|
|
274
|
+
};
|
|
275
|
+
var CropDialog = ({
|
|
276
|
+
open,
|
|
277
|
+
imageSrc,
|
|
278
|
+
cropOptions,
|
|
279
|
+
onConfirm,
|
|
280
|
+
onCancel
|
|
281
|
+
}) => {
|
|
282
|
+
const imgRef = (0, import_react3.useRef)(null);
|
|
283
|
+
const [selectedAspect, setSelectedAspect] = (0, import_react3.useState)(
|
|
284
|
+
cropOptions[0]
|
|
285
|
+
);
|
|
286
|
+
const [crop, setCrop] = (0, import_react3.useState)();
|
|
287
|
+
const handleImageLoad = (0, import_react3.useCallback)(
|
|
288
|
+
(e) => {
|
|
289
|
+
imgRef.current = e.currentTarget;
|
|
290
|
+
const aspect = ASPECT_RATIOS[selectedAspect];
|
|
291
|
+
const { width, height } = e.currentTarget;
|
|
292
|
+
const cropWidth = Math.min(width, height * aspect);
|
|
293
|
+
const cropHeight = cropWidth / aspect;
|
|
294
|
+
setCrop({
|
|
295
|
+
unit: "px",
|
|
296
|
+
x: (width - cropWidth) / 2,
|
|
297
|
+
y: (height - cropHeight) / 2,
|
|
298
|
+
width: cropWidth,
|
|
299
|
+
height: cropHeight
|
|
300
|
+
});
|
|
301
|
+
},
|
|
302
|
+
[selectedAspect]
|
|
303
|
+
);
|
|
304
|
+
const handleAspectChange = (0, import_react3.useCallback)(
|
|
305
|
+
(_, value) => {
|
|
306
|
+
if (!value || !imgRef.current) return;
|
|
307
|
+
setSelectedAspect(value);
|
|
308
|
+
const aspect = ASPECT_RATIOS[value];
|
|
309
|
+
const { width, height } = imgRef.current;
|
|
310
|
+
const cropWidth = Math.min(width, height * aspect);
|
|
311
|
+
const cropHeight = cropWidth / aspect;
|
|
312
|
+
setCrop({
|
|
313
|
+
unit: "px",
|
|
314
|
+
x: (width - cropWidth) / 2,
|
|
315
|
+
y: (height - cropHeight) / 2,
|
|
316
|
+
width: cropWidth,
|
|
317
|
+
height: cropHeight
|
|
318
|
+
});
|
|
319
|
+
},
|
|
320
|
+
[]
|
|
321
|
+
);
|
|
322
|
+
const handleConfirm = (0, import_react3.useCallback)(() => {
|
|
323
|
+
if (!imgRef.current || !crop) return;
|
|
324
|
+
const url = getCroppedImageUrl(imgRef.current, crop);
|
|
325
|
+
onConfirm(url);
|
|
326
|
+
}, [crop, onConfirm]);
|
|
327
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_material7.Dialog, { open, onClose: onCancel, maxWidth: "md", fullWidth: true, children: [
|
|
328
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material7.DialogTitle, { children: "Crop Image" }),
|
|
329
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material7.DialogContent, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
330
|
+
import_material7.Box,
|
|
331
|
+
{
|
|
332
|
+
sx: {
|
|
333
|
+
display: "flex",
|
|
334
|
+
flexDirection: "column",
|
|
335
|
+
alignItems: "center",
|
|
336
|
+
gap: 2,
|
|
337
|
+
mt: 1
|
|
338
|
+
},
|
|
339
|
+
children: [
|
|
340
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
341
|
+
import_react_image_crop.default,
|
|
342
|
+
{
|
|
343
|
+
crop,
|
|
344
|
+
onChange: (c) => setCrop(c),
|
|
345
|
+
aspect: ASPECT_RATIOS[selectedAspect],
|
|
346
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
347
|
+
"img",
|
|
348
|
+
{
|
|
349
|
+
src: imageSrc,
|
|
350
|
+
alt: "Crop preview",
|
|
351
|
+
onLoad: handleImageLoad,
|
|
352
|
+
style: { maxWidth: "100%", maxHeight: 400 }
|
|
353
|
+
}
|
|
354
|
+
)
|
|
355
|
+
}
|
|
356
|
+
),
|
|
357
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_material7.Box, { children: [
|
|
358
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material7.Typography, { variant: "body2", color: "text.secondary", sx: { mb: 1 }, children: "Aspect ratio" }),
|
|
359
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
360
|
+
import_material7.ToggleButtonGroup,
|
|
361
|
+
{
|
|
362
|
+
value: selectedAspect,
|
|
363
|
+
exclusive: true,
|
|
364
|
+
onChange: handleAspectChange,
|
|
365
|
+
size: "small",
|
|
366
|
+
children: cropOptions.map((option) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material7.ToggleButton, { value: option, children: option }, option))
|
|
367
|
+
}
|
|
368
|
+
)
|
|
369
|
+
] })
|
|
370
|
+
]
|
|
371
|
+
}
|
|
372
|
+
) }),
|
|
373
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_material7.DialogActions, { children: [
|
|
374
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material7.Button, { onClick: onCancel, children: "Cancel" }),
|
|
375
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_material7.Button, { variant: "contained", onClick: handleConfirm, children: "Confirm" })
|
|
376
|
+
] })
|
|
377
|
+
] });
|
|
378
|
+
};
|
|
379
|
+
var CropDialog_default = CropDialog;
|
|
380
|
+
|
|
381
|
+
// src/FormikImageUpload/FormikImageUpload.tsx
|
|
382
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
383
|
+
var ALL_CROP_OPTIONS = ["1.91:1", "1:1", "3:1"];
|
|
384
|
+
var FormikImageUpload = ({
|
|
385
|
+
name,
|
|
386
|
+
label,
|
|
387
|
+
height = 120,
|
|
388
|
+
cropEnabled = false,
|
|
389
|
+
cropOptions = ALL_CROP_OPTIONS
|
|
390
|
+
}) => {
|
|
391
|
+
const [field, meta, helpers] = (0, import_formik7.useField)(name);
|
|
392
|
+
const hasError = meta.touched && Boolean(meta.error);
|
|
393
|
+
const [rawImageSrc, setRawImageSrc] = (0, import_react4.useState)(null);
|
|
394
|
+
const handleFileChange = (0, import_react4.useCallback)(
|
|
395
|
+
(e) => {
|
|
396
|
+
const file = e.target.files?.[0];
|
|
397
|
+
if (!file) return;
|
|
398
|
+
const url = URL.createObjectURL(file);
|
|
399
|
+
if (cropEnabled) {
|
|
400
|
+
setRawImageSrc(url);
|
|
401
|
+
} else {
|
|
402
|
+
helpers.setValue(url);
|
|
403
|
+
}
|
|
404
|
+
e.target.value = "";
|
|
405
|
+
},
|
|
406
|
+
[helpers, cropEnabled]
|
|
407
|
+
);
|
|
408
|
+
const handleCropConfirm = (0, import_react4.useCallback)(
|
|
409
|
+
(croppedUrl) => {
|
|
410
|
+
helpers.setValue(croppedUrl);
|
|
411
|
+
setRawImageSrc(null);
|
|
412
|
+
},
|
|
413
|
+
[helpers]
|
|
414
|
+
);
|
|
415
|
+
const handleCropCancel = (0, import_react4.useCallback)(() => {
|
|
416
|
+
setRawImageSrc(null);
|
|
417
|
+
}, []);
|
|
418
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_material8.FormControl, { fullWidth: true, error: hasError, children: [
|
|
419
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_material8.Typography, { variant: "body2", color: "text.secondary", sx: { mb: 1 }, children: label }),
|
|
420
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
421
|
+
import_material8.Box,
|
|
422
|
+
{
|
|
423
|
+
component: "label",
|
|
424
|
+
sx: {
|
|
425
|
+
display: "flex",
|
|
426
|
+
alignItems: "center",
|
|
427
|
+
justifyContent: "center",
|
|
428
|
+
width: "100%",
|
|
429
|
+
height,
|
|
430
|
+
border: "2px dashed",
|
|
431
|
+
borderColor: hasError ? "error.main" : "divider",
|
|
432
|
+
borderRadius: 1,
|
|
433
|
+
cursor: "pointer",
|
|
434
|
+
overflow: "hidden",
|
|
435
|
+
backgroundImage: field.value ? `url(${field.value})` : "none",
|
|
436
|
+
backgroundSize: "contain",
|
|
437
|
+
backgroundRepeat: "no-repeat",
|
|
438
|
+
backgroundPosition: "center",
|
|
439
|
+
"&:hover": { borderColor: "primary.main" }
|
|
440
|
+
},
|
|
441
|
+
children: [
|
|
442
|
+
!field.value && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_material8.Typography, { variant: "body2", color: "text.secondary", children: "Upload image" }),
|
|
443
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
444
|
+
"input",
|
|
445
|
+
{
|
|
446
|
+
type: "file",
|
|
447
|
+
accept: "image/*",
|
|
448
|
+
hidden: true,
|
|
449
|
+
onChange: handleFileChange
|
|
450
|
+
}
|
|
451
|
+
)
|
|
452
|
+
]
|
|
453
|
+
}
|
|
454
|
+
),
|
|
455
|
+
hasError && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_material8.FormHelperText, { children: meta.error }),
|
|
456
|
+
cropEnabled && rawImageSrc && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
457
|
+
CropDialog_default,
|
|
458
|
+
{
|
|
459
|
+
open: true,
|
|
460
|
+
imageSrc: rawImageSrc,
|
|
461
|
+
cropOptions,
|
|
462
|
+
onConfirm: handleCropConfirm,
|
|
463
|
+
onCancel: handleCropCancel
|
|
464
|
+
}
|
|
465
|
+
)
|
|
466
|
+
] });
|
|
467
|
+
};
|
|
468
|
+
var FormikImageUpload_default = FormikImageUpload;
|
|
469
|
+
|
|
470
|
+
// src/FormikCheckbox/FormikCheckbox.tsx
|
|
471
|
+
var import_material9 = require("@mui/material");
|
|
472
|
+
var import_formik8 = require("formik");
|
|
473
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
474
|
+
var FormikCheckbox = ({ name, label, ...props }) => {
|
|
475
|
+
const [field, meta] = (0, import_formik8.useField)({ name, type: "checkbox" });
|
|
476
|
+
const hasError = meta.touched && Boolean(meta.error);
|
|
477
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_material9.FormControl, { error: hasError, children: [
|
|
478
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
479
|
+
import_material9.FormControlLabel,
|
|
480
|
+
{
|
|
481
|
+
control: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_material9.Checkbox, { ...field, ...props, checked: field.checked }),
|
|
482
|
+
label: label ?? ""
|
|
483
|
+
}
|
|
484
|
+
),
|
|
485
|
+
hasError && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_material9.FormHelperText, { children: meta.error })
|
|
486
|
+
] });
|
|
487
|
+
};
|
|
488
|
+
var FormikCheckbox_default = FormikCheckbox;
|
|
489
|
+
|
|
490
|
+
// src/FormikSwitch/FormikSwitch.tsx
|
|
491
|
+
var import_material10 = require("@mui/material");
|
|
492
|
+
var import_formik9 = require("formik");
|
|
493
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
494
|
+
var FormikSwitch = ({ name, label, ...props }) => {
|
|
495
|
+
const [field, meta] = (0, import_formik9.useField)({ name, type: "checkbox" });
|
|
496
|
+
const hasError = meta.touched && Boolean(meta.error);
|
|
497
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_material10.FormControl, { error: hasError, children: [
|
|
498
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
499
|
+
import_material10.FormControlLabel,
|
|
500
|
+
{
|
|
501
|
+
control: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_material10.Switch, { ...field, ...props, checked: field.checked }),
|
|
502
|
+
label: label ?? ""
|
|
503
|
+
}
|
|
504
|
+
),
|
|
505
|
+
hasError && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_material10.FormHelperText, { children: meta.error })
|
|
506
|
+
] });
|
|
507
|
+
};
|
|
508
|
+
var FormikSwitch_default = FormikSwitch;
|
|
509
|
+
|
|
510
|
+
// src/FormikAutocomplete/FormikAutocomplete.tsx
|
|
511
|
+
var import_material11 = require("@mui/material");
|
|
512
|
+
var import_formik10 = require("formik");
|
|
513
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
514
|
+
var FormikAutocomplete = ({
|
|
515
|
+
name,
|
|
516
|
+
label,
|
|
517
|
+
options,
|
|
518
|
+
getOptionLabel,
|
|
519
|
+
isOptionEqualToValue,
|
|
520
|
+
...props
|
|
521
|
+
}) => {
|
|
522
|
+
const [field, meta, helpers] = (0, import_formik10.useField)(name);
|
|
523
|
+
const hasError = meta.touched && Boolean(meta.error);
|
|
524
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_material11.FormControl, { fullWidth: true, error: hasError, children: [
|
|
525
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_material11.FormLabel, { children: label }),
|
|
526
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
527
|
+
import_material11.Autocomplete,
|
|
528
|
+
{
|
|
529
|
+
...props,
|
|
530
|
+
options,
|
|
531
|
+
getOptionLabel,
|
|
532
|
+
isOptionEqualToValue,
|
|
533
|
+
value: field.value ?? null,
|
|
534
|
+
onChange: (_, newValue) => helpers.setValue(newValue),
|
|
535
|
+
onBlur: () => helpers.setTouched(true),
|
|
536
|
+
renderInput: (params) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
537
|
+
import_material11.TextField,
|
|
538
|
+
{
|
|
539
|
+
...params,
|
|
540
|
+
error: hasError,
|
|
541
|
+
helperText: hasError ? meta.error : void 0
|
|
542
|
+
}
|
|
543
|
+
)
|
|
544
|
+
}
|
|
545
|
+
)
|
|
546
|
+
] });
|
|
547
|
+
};
|
|
548
|
+
var FormikAutocomplete_default = FormikAutocomplete;
|
|
549
|
+
|
|
550
|
+
// src/FormikRating/FormikRating.tsx
|
|
551
|
+
var import_material12 = require("@mui/material");
|
|
552
|
+
var import_formik11 = require("formik");
|
|
553
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
554
|
+
var FormikRating = ({ name, label, ...props }) => {
|
|
555
|
+
const [field, meta, helpers] = (0, import_formik11.useField)(name);
|
|
556
|
+
const hasError = meta.touched && Boolean(meta.error);
|
|
557
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_material12.FormControl, { error: hasError, children: [
|
|
558
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material12.FormLabel, { children: label }),
|
|
559
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
560
|
+
import_material12.Rating,
|
|
561
|
+
{
|
|
562
|
+
...props,
|
|
563
|
+
name,
|
|
564
|
+
value: field.value ?? null,
|
|
565
|
+
onChange: (_, newValue) => helpers.setValue(newValue),
|
|
566
|
+
onBlur: field.onBlur
|
|
567
|
+
}
|
|
568
|
+
),
|
|
569
|
+
hasError && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_material12.FormHelperText, { children: meta.error })
|
|
570
|
+
] });
|
|
571
|
+
};
|
|
572
|
+
var FormikRating_default = FormikRating;
|
|
573
|
+
|
|
574
|
+
// src/FormikToggleButtonGroup/FormikToggleButtonGroup.tsx
|
|
575
|
+
var import_material13 = require("@mui/material");
|
|
576
|
+
var import_formik12 = require("formik");
|
|
577
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
578
|
+
var FormikToggleButtonGroup = ({ name, label, options, ...props }) => {
|
|
579
|
+
const [field, meta, helpers] = (0, import_formik12.useField)(name);
|
|
580
|
+
const hasError = meta.touched && Boolean(meta.error);
|
|
581
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_material13.FormControl, { error: hasError, children: [
|
|
582
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_material13.FormLabel, { children: label }),
|
|
583
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
584
|
+
import_material13.ToggleButtonGroup,
|
|
585
|
+
{
|
|
586
|
+
...props,
|
|
587
|
+
value: field.value,
|
|
588
|
+
onChange: (_, newValue) => {
|
|
589
|
+
if (newValue !== null) {
|
|
590
|
+
helpers.setValue(newValue);
|
|
591
|
+
}
|
|
592
|
+
},
|
|
593
|
+
onBlur: field.onBlur,
|
|
594
|
+
children: options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_material13.ToggleButton, { value: option.value, children: option.label }, option.value))
|
|
595
|
+
}
|
|
596
|
+
),
|
|
597
|
+
hasError && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_material13.FormHelperText, { children: meta.error })
|
|
598
|
+
] });
|
|
599
|
+
};
|
|
600
|
+
var FormikToggleButtonGroup_default = FormikToggleButtonGroup;
|
|
601
|
+
|
|
602
|
+
// src/FormikDatePicker/FormikDatePicker.tsx
|
|
603
|
+
var import_material14 = require("@mui/material");
|
|
604
|
+
var import_DatePicker = require("@mui/x-date-pickers/DatePicker");
|
|
605
|
+
var import_formik13 = require("formik");
|
|
606
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
607
|
+
var FormikDatePicker = ({ name, label, ...props }) => {
|
|
608
|
+
const [field, meta, helpers] = (0, import_formik13.useField)(name);
|
|
609
|
+
const hasError = meta.touched && Boolean(meta.error);
|
|
610
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_material14.FormControl, { fullWidth: true, error: hasError, children: [
|
|
611
|
+
label && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_material14.FormLabel, { children: label }),
|
|
612
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
613
|
+
import_DatePicker.DatePicker,
|
|
614
|
+
{
|
|
615
|
+
...props,
|
|
616
|
+
value: field.value ?? null,
|
|
617
|
+
onChange: (value) => helpers.setValue(value),
|
|
618
|
+
slotProps: {
|
|
619
|
+
textField: {
|
|
620
|
+
onBlur: () => helpers.setTouched(true),
|
|
621
|
+
error: hasError
|
|
622
|
+
},
|
|
623
|
+
...props.slotProps
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
),
|
|
627
|
+
hasError && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_material14.FormHelperText, { children: meta.error })
|
|
628
|
+
] });
|
|
629
|
+
};
|
|
630
|
+
var FormikDatePicker_default = FormikDatePicker;
|
|
631
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
632
|
+
0 && (module.exports = {
|
|
633
|
+
FormikAutocomplete,
|
|
634
|
+
FormikCheckbox,
|
|
635
|
+
FormikColorPicker,
|
|
636
|
+
FormikDatePicker,
|
|
637
|
+
FormikFontPicker,
|
|
638
|
+
FormikImageUpload,
|
|
639
|
+
FormikRadioGroup,
|
|
640
|
+
FormikRating,
|
|
641
|
+
FormikSelect,
|
|
642
|
+
FormikSlider,
|
|
643
|
+
FormikSwitch,
|
|
644
|
+
FormikTextField,
|
|
645
|
+
FormikToggleButtonGroup
|
|
646
|
+
});
|