mui-custom-form 1.1.11 → 2.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/dist/CustomForm.js +1 -1
- package/dist/components/fields/DateField.js +8 -2
- package/dist/components/fields/DateField.js.map +1 -1
- package/dist/components/fields/FileField.js +2 -2
- package/dist/components/fields/FileField.js.map +1 -1
- package/dist/src/CustomForm.d.ts +5 -0
- package/dist/src/CustomForm.js +66 -0
- package/dist/src/CustomForm.js.map +1 -0
- package/dist/src/components/fields/CheckboxGroupField.d.ts +9 -0
- package/dist/src/components/fields/CheckboxGroupField.js +23 -0
- package/dist/src/components/fields/CheckboxGroupField.js.map +1 -0
- package/dist/src/components/fields/CustomField.d.ts +9 -0
- package/dist/src/components/fields/CustomField.js +12 -0
- package/dist/src/components/fields/CustomField.js.map +1 -0
- package/dist/src/components/fields/DateField.d.ts +9 -0
- package/dist/src/components/fields/DateField.js +9 -0
- package/dist/src/components/fields/DateField.js.map +1 -0
- package/dist/src/components/fields/FileField.d.ts +9 -0
- package/dist/src/components/fields/FileField.js +44 -0
- package/dist/src/components/fields/FileField.js.map +1 -0
- package/dist/src/components/fields/RadioGroupField.d.ts +9 -0
- package/dist/src/components/fields/RadioGroupField.js +11 -0
- package/dist/src/components/fields/RadioGroupField.js.map +1 -0
- package/dist/src/components/fields/SelectField.d.ts +9 -0
- package/dist/src/components/fields/SelectField.js +11 -0
- package/dist/src/components/fields/SelectField.js.map +1 -0
- package/dist/src/components/fields/SwitchField.d.ts +9 -0
- package/dist/src/components/fields/SwitchField.js +8 -0
- package/dist/src/components/fields/SwitchField.js.map +1 -0
- package/dist/src/components/fields/TextField.d.ts +9 -0
- package/dist/src/components/fields/TextField.js +14 -0
- package/dist/src/components/fields/TextField.js.map +1 -0
- package/dist/src/components/fields/TextareaField.d.ts +9 -0
- package/dist/src/components/fields/TextareaField.js +8 -0
- package/dist/src/components/fields/TextareaField.js.map +1 -0
- package/dist/src/types.d.ts +66 -0
- package/dist/src/types.js +2 -0
- package/dist/src/types.js.map +1 -0
- package/dist/types.d.ts +2 -1
- package/package.json +10 -10
package/dist/CustomForm.js
CHANGED
|
@@ -58,7 +58,7 @@ export const CustomForm = ({ fieldsGroups, onSubmit, formControl, submitButton =
|
|
|
58
58
|
? calculatedSpan
|
|
59
59
|
: 12 }, renderField(field))))));
|
|
60
60
|
}),
|
|
61
|
-
React.createElement(Stack, { direction: "row", justifyContent: actionButtonsPlacement || "flex-end", spacing: 2 },
|
|
61
|
+
React.createElement(Stack, { direction: "row", sx: { justifyContent: actionButtonsPlacement || "flex-end" }, spacing: 2 },
|
|
62
62
|
resetButton && (React.createElement(Button, { type: "reset", variant: "contained", onClick: () => reset(), ...resetButtonProps }, "Reset")),
|
|
63
63
|
submitButton && (React.createElement(Button, { type: "submit", variant: "contained", ...submitButtonProps }, "Submit")))));
|
|
64
64
|
};
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import { TextField as MuiTextField } from "@mui/material";
|
|
2
1
|
import { DatePicker } from "@mui/x-date-pickers";
|
|
3
2
|
import React from "react";
|
|
4
3
|
import { Controller } from "react-hook-form";
|
|
5
4
|
export const DateField = ({ field, formControl, }) => {
|
|
6
5
|
const { control } = formControl;
|
|
7
|
-
return (React.createElement(Controller, { name: field.name, control: control, rules: { required: field.required }, render: ({ field: controlField, fieldState: { error } }) => (React.createElement(DatePicker, { ...controlField, value: controlField.value || null,
|
|
6
|
+
return (React.createElement(Controller, { name: field.name, control: control, rules: { required: field.required }, render: ({ field: controlField, fieldState: { error } }) => (React.createElement(DatePicker, { ...controlField, value: controlField.value || null, label: field.label, onChange: (date) => controlField.onChange(date), slotProps: {
|
|
7
|
+
textField: {
|
|
8
|
+
required: field.required,
|
|
9
|
+
error: !!error,
|
|
10
|
+
helperText: error?.message,
|
|
11
|
+
fullWidth: true,
|
|
12
|
+
},
|
|
13
|
+
}, ...field.otherProps })) }));
|
|
8
14
|
};
|
|
9
15
|
//# sourceMappingURL=DateField.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateField.js","sourceRoot":"","sources":["../../../src/components/fields/DateField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"DateField.js","sourceRoot":"","sources":["../../../src/components/fields/DateField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAoC,MAAM,iBAAiB,CAAA;AAQ9E,MAAM,CAAC,MAAM,SAAS,GAAG,CAAwB,EAC/C,KAAK,EACL,WAAW,GACO,EAAE,EAAE;IACtB,MAAM,EAAE,OAAO,EAAE,GAAG,WAAW,CAAA;IAE/B,OAAO,CACL,oBAAC,UAAU,IACT,IAAI,EAAE,KAAK,CAAC,IAAe,EAC3B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,EACnC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAC1D,oBAAC,UAAU,OACL,YAAY,EAChB,KAAK,EAAE,YAAY,CAAC,KAAK,IAAI,IAAI,EACjC,KAAK,EAAE,KAAK,CAAC,KAAK,EAClB,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,EAC/C,SAAS,EAAE;gBACT,SAAS,EAAE;oBACT,QAAQ,EAAE,KAAK,CAAC,QAAQ;oBACxB,KAAK,EAAE,CAAC,CAAC,KAAK;oBACd,UAAU,EAAE,KAAK,EAAE,OAAO;oBAC1B,SAAS,EAAE,IAAI;iBAChB;aACF,KACG,KAAK,CAAC,UAAU,GACpB,CACH,GACD,CACH,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -12,7 +12,7 @@ export const FileField = ({ field, formControl, }) => {
|
|
|
12
12
|
: null;
|
|
13
13
|
return (React.createElement(FormControl, { fullWidth: true, error: !!error },
|
|
14
14
|
React.createElement(FormLabel, { component: "legend", required: field.required }, field.label),
|
|
15
|
-
React.createElement(Stack, { direction: "row", alignItems: "center"
|
|
15
|
+
React.createElement(Stack, { direction: "row", spacing: 2, sx: { alignItems: "center" } },
|
|
16
16
|
React.createElement(Box, { onClick: () => fileInputRef.current?.click(), sx: { cursor: "pointer" }, ...field.otherProps },
|
|
17
17
|
field.fileInputComponent ? (typeof field.fileInputComponent === "function" ? (React.createElement(field.fileInputComponent)) : (field.fileInputComponent)) : (React.createElement(Button, { variant: "contained", component: "span" }, "Upload File")),
|
|
18
18
|
React.createElement("input", { type: "file", hidden: true, ref: fileInputRef, onChange: (e) => {
|
|
@@ -21,7 +21,7 @@ export const FileField = ({ field, formControl, }) => {
|
|
|
21
21
|
: undefined;
|
|
22
22
|
controlField.onChange(fileValue);
|
|
23
23
|
} })),
|
|
24
|
-
selectedFile && (React.createElement(Stack, { direction: "row", alignItems: "center"
|
|
24
|
+
selectedFile && (React.createElement(Stack, { direction: "row", spacing: 1, sx: { alignItems: "center" } },
|
|
25
25
|
selectedFile.type.startsWith("image/") && previewUrl ? (React.createElement("img", { src: previewUrl, alt: "Preview", style: {
|
|
26
26
|
maxWidth: "50px",
|
|
27
27
|
maxHeight: "50px",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileField.js","sourceRoot":"","sources":["../../../src/components/fields/FileField.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,MAAM,EACN,WAAW,EACX,cAAc,EACd,SAAS,EACT,UAAU,EACV,KAAK,EACL,UAAU,GACX,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC5D,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AACrC,OA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ACT,IAAI,EAAC,OAAO,EACZ,OAAO,EAAE,GAAG,EAAE;gCACZ,YAAY,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;gCAChC,IAAI,YAAY,CAAC,OAAO,EAAE,CAAC;oCACzB,YAAY,CAAC,OAAO,CAAC,KAAK,GAAG,EAAE,CAAA,CAAC,0BAA0B;gCAC5D,CAAC;gCACD,IAAI,UAAU,EAAE,CAAC;oCACf,GAAG,CAAC,eAAe,CAAC,UAAU,CAAC,CAAA,CAAC,0BAA0B;gCAC5D,CAAC;4BACH,CAAC;4BACD,oBAAC,KAAK,IAAC,QAAQ,EAAC,OAAO,GAAG,CACf,CACP,CACT,CACK;gBACP,KAAK,IAAI,oBAAC,cAAc,QAAE,KAAK,CAAC,OAAO,CAAkB,CAC9C,CACf,CAAA;QACH,CAAC,GACD,CACH,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FieldValues } from "react-hook-form";
|
|
3
|
+
import { ICustomForm } from "./types";
|
|
4
|
+
export declare const CustomForm: <T extends FieldValues>({ fieldsGroups, onSubmit, formControl, submitButton, resetButton, actionButtonsPlacement, layout, otherProps, }: ICustomForm<T>) => React.JSX.Element;
|
|
5
|
+
export default CustomForm;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Button, Grid, Stack } from "@mui/material";
|
|
2
|
+
import React from "react";
|
|
3
|
+
// Import modularized field components
|
|
4
|
+
import { TextField } from "./components/fields/TextField";
|
|
5
|
+
import { TextareaField } from "./components/fields/TextareaField";
|
|
6
|
+
import { SelectField } from "./components/fields/SelectField";
|
|
7
|
+
import { DateField } from "./components/fields/DateField";
|
|
8
|
+
import { FileField } from "./components/fields/FileField";
|
|
9
|
+
import { SwitchField } from "./components/fields/SwitchField";
|
|
10
|
+
import { CheckboxGroupField } from "./components/fields/CheckboxGroupField";
|
|
11
|
+
import { RadioGroupField } from "./components/fields/RadioGroupField";
|
|
12
|
+
import { CustomField as CustomComponentField } from "./components/fields/CustomField";
|
|
13
|
+
export const CustomForm = ({ fieldsGroups, onSubmit, formControl, submitButton = true, resetButton, actionButtonsPlacement, layout, otherProps, }) => {
|
|
14
|
+
const { control, reset } = formControl;
|
|
15
|
+
const renderField = (field) => {
|
|
16
|
+
switch (field.type) {
|
|
17
|
+
case "text":
|
|
18
|
+
case "number":
|
|
19
|
+
case "password":
|
|
20
|
+
return React.createElement(TextField, { field: field, formControl: formControl });
|
|
21
|
+
case "textarea":
|
|
22
|
+
return React.createElement(TextareaField, { field: field, formControl: formControl });
|
|
23
|
+
case "single-select":
|
|
24
|
+
case "multi-select":
|
|
25
|
+
return React.createElement(SelectField, { field: field, formControl: formControl });
|
|
26
|
+
case "date":
|
|
27
|
+
return React.createElement(DateField, { field: field, formControl: formControl });
|
|
28
|
+
case "file":
|
|
29
|
+
return React.createElement(FileField, { field: field, formControl: formControl });
|
|
30
|
+
case "switch":
|
|
31
|
+
return React.createElement(SwitchField, { field: field, formControl: formControl });
|
|
32
|
+
case "checkbox-group":
|
|
33
|
+
return React.createElement(CheckboxGroupField, { field: field, formControl: formControl });
|
|
34
|
+
case "radio-group":
|
|
35
|
+
return React.createElement(RadioGroupField, { field: field, formControl: formControl });
|
|
36
|
+
case "custom":
|
|
37
|
+
return React.createElement(CustomComponentField, { field: field, formControl: formControl });
|
|
38
|
+
default:
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const submitButtonProps = submitButton && submitButton !== true ? submitButton : {};
|
|
43
|
+
const resetButtonProps = resetButton && resetButton !== true ? resetButton : {};
|
|
44
|
+
// Function to calculate spans dynamically
|
|
45
|
+
const calculateSpan = (fields) => {
|
|
46
|
+
const totalDefinedSpan = fields.reduce((acc, field) => acc + (field.span || 0), 0);
|
|
47
|
+
const autoSpanFields = fields.filter((field) => !field.span).length;
|
|
48
|
+
const remainingSpan = 12 - totalDefinedSpan;
|
|
49
|
+
const calculatedSpan = autoSpanFields > 0 ? Math.floor(remainingSpan / autoSpanFields) : 12;
|
|
50
|
+
return { calculatedSpan, autoSpanFields };
|
|
51
|
+
};
|
|
52
|
+
return (React.createElement(Stack, { component: "form", onSubmit: formControl.handleSubmit(onSubmit[0], onSubmit[1]), noValidate: true, direction: layout, ...otherProps, spacing: 3 },
|
|
53
|
+
fieldsGroups.map((fields, rowIndex) => {
|
|
54
|
+
const { calculatedSpan, autoSpanFields } = calculateSpan(fields);
|
|
55
|
+
return (React.createElement(Grid, { container: true, key: rowIndex, spacing: 2 }, fields.map((field, fieldIndex) => (React.createElement(Grid, { key: fieldIndex, size: field.span
|
|
56
|
+
? field.span
|
|
57
|
+
: autoSpanFields > 0
|
|
58
|
+
? calculatedSpan
|
|
59
|
+
: 12 }, renderField(field))))));
|
|
60
|
+
}),
|
|
61
|
+
React.createElement(Stack, { direction: "row", sx: { justifyContent: actionButtonsPlacement || "flex-end" }, spacing: 2 },
|
|
62
|
+
resetButton && (React.createElement(Button, { type: "reset", variant: "contained", onClick: () => reset(), ...resetButtonProps }, "Reset")),
|
|
63
|
+
submitButton && (React.createElement(Button, { type: "submit", variant: "contained", ...submitButtonProps }, "Submit")))));
|
|
64
|
+
};
|
|
65
|
+
export default CustomForm;
|
|
66
|
+
//# sourceMappingURL=CustomForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomForm.js","sourceRoot":"","sources":["../../src/CustomForm.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,sCAAsC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAA;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+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C,WAAW,KAAK,iBAAiB,aAEtD,CACV,CACK,CACF,CACT,CAAA;AACH,CAAC,CAAA;AAED,eAAe,UAAU,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FieldValues, Path, UseFormReturn } from "react-hook-form";
|
|
3
|
+
import { ICheckboxGroupField } from "../../types";
|
|
4
|
+
interface CheckboxGroupFieldProps<T extends FieldValues> {
|
|
5
|
+
field: ICheckboxGroupField<Path<T>>;
|
|
6
|
+
formControl: UseFormReturn<T>;
|
|
7
|
+
}
|
|
8
|
+
export declare const CheckboxGroupField: <T extends FieldValues>({ field, formControl, }: CheckboxGroupFieldProps<T>) => React.JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Checkbox, FormControl, FormControlLabel, FormHelperText, FormLabel, Stack, } from "@mui/material";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Controller } from "react-hook-form";
|
|
4
|
+
export const CheckboxGroupField = ({ field, formControl, }) => {
|
|
5
|
+
const { control } = formControl;
|
|
6
|
+
return (React.createElement(Controller, { name: field.name, control: control, rules: { required: field.required }, render: ({ field: controlField, fieldState: { error } }) => (React.createElement(FormControl, { component: "fieldset", error: !!error },
|
|
7
|
+
React.createElement(FormLabel, { component: "legend", required: field.required }, field.label),
|
|
8
|
+
React.createElement(Stack, { direction: "row", spacing: 2 }, field.list?.map((option) => (React.createElement(FormControlLabel, { key: option.value, control: React.createElement(Checkbox, { checked: controlField.value?.includes(option.value) || false, onChange: (e) => {
|
|
9
|
+
const checked = e.target.checked;
|
|
10
|
+
const value = option.value;
|
|
11
|
+
if (checked) {
|
|
12
|
+
controlField.onChange([
|
|
13
|
+
...(controlField.value || []),
|
|
14
|
+
value,
|
|
15
|
+
]);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
controlField.onChange((controlField.value || []).filter((v) => v !== value));
|
|
19
|
+
}
|
|
20
|
+
}, ...field.otherProps }), label: option.label })))),
|
|
21
|
+
error && React.createElement(FormHelperText, null, error.message))) }));
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=CheckboxGroupField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CheckboxGroupField.js","sourceRoot":"","sources":["../../../../src/components/fields/CheckboxGroupField.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,SAAS,EACT,KAAK,GACN,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAoC,MAAM,iBAAiB,CAAA;AAQ9E,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAwB,EACxD,KAAK,EACL,WAAW,GACgB,EAAE,EAAE;IAC/B,MAAM,EAAE,OAAO,EAAE,GAAG,WAAW,CAAA;IAE/B,OAAO,CACL,oBAAC,UAAU,IACT,IAAI,EAAE,KAAK,CAAC,IAAe,EAC3B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,EACnC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAC1D,oBAAC,WAAW,IAAC,SAAS,EAAC,UAAU,EAAC,KAAK,EAAE,CAAC,CAAC,KAAK;YAC9C,oBAAC,SAAS,IAAC,SAAS,EAAC,QAAQ,EAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,IACnD,KAAK,CAAC,KAAK,CACF;YACZ,oBAAC,KAAK,IAAC,SAAS,EAAC,KAAK,EAAC,OAAO,EAAE,CAAC,IAC9B,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAC3B,oBAAC,gBAAgB,IACf,GAAG,EAAE,MAAM,CAAC,KAAK,EACjB,OAAO,EACL,oBAAC,QAAQ,IACP,OAAO,EACL,YAAY,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,EAErD,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE;wBACd,MAAM,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAA;wBAChC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAA;wBAC1B,IAAI,OAAO,EAAE,CAAC;4BACZ,YAAY,CAAC,QAAQ,CAAC;gCACpB,GAAG,CAAC,YAAY,CAAC,KAAK,IAAI,EAAE,CAAC;gCAC7B,KAAK;6BACN,CAAC,CAAA;wBACJ,CAAC;6BAAM,CAAC;4BACN,YAAY,CAAC,QAAQ,CACnB,CAAC,YAAY,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,MAAM,CAC/B,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CACxB,CACF,CAAA;wBACH,CAAC;oBACH,CAAC,KACG,KAAK,CAAC,UAAU,GACpB,EAEJ,KAAK,EAAE,MAAM,CAAC,KAAK,GACnB,CACH,CAAC,CACI;YACP,KAAK,IAAI,oBAAC,cAAc,QAAE,KAAK,CAAC,OAAO,CAAkB,CAC9C,CACf,GACD,CACH,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FieldValues, Path, UseFormReturn } from "react-hook-form";
|
|
3
|
+
import { ICustomComponentField } from "../../types";
|
|
4
|
+
interface CustomFieldProps<T extends FieldValues> {
|
|
5
|
+
field: ICustomComponentField<Path<T>>;
|
|
6
|
+
formControl: UseFormReturn<T>;
|
|
7
|
+
}
|
|
8
|
+
export declare const CustomField: <T extends FieldValues>({ field, formControl, }: CustomFieldProps<T>) => React.JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FormControl, FormHelperText, FormLabel } from "@mui/material";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Controller } from "react-hook-form";
|
|
4
|
+
export const CustomField = ({ field, formControl, }) => {
|
|
5
|
+
const { control } = formControl;
|
|
6
|
+
const CustomComponent = field.component;
|
|
7
|
+
return (React.createElement(Controller, { name: field.name, control: control, rules: { required: field.required }, render: ({ field: controlField, fieldState: { error } }) => (React.createElement(FormControl, { fullWidth: true, error: !!error },
|
|
8
|
+
React.createElement(FormLabel, { component: "legend", required: field.required }, field.label),
|
|
9
|
+
React.createElement(CustomComponent, { value: controlField.value, onChange: controlField.onChange, ...field.otherProps }),
|
|
10
|
+
error && React.createElement(FormHelperText, null, error.message))) }));
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=CustomField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomField.js","sourceRoot":"","sources":["../../../../src/components/fields/CustomField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACtE,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAoC,MAAM,iBAAiB,CAAA;AAQ9E,MAAM,CAAC,MAAM,WAAW,GAAG,CAAwB,EACjD,KAAK,EACL,WAAW,GACS,EAAE,EAAE;IACxB,MAAM,EAAE,OAAO,EAAE,GAAG,WAAW,CAAA;IAC/B,MAAM,eAAe,GAAG,KAAK,CAAC,SAAS,CAAA;IAEvC,OAAO,CACL,oBAAC,UAAU,IACT,IAAI,EAAE,KAAK,CAAC,IAAe,EAC3B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,EACnC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAC1D,oBAAC,WAAW,IAAC,SAAS,QAAC,KAAK,EAAE,CAAC,CAAC,KAAK;YACnC,oBAAC,SAAS,IAAC,SAAS,EAAC,QAAQ,EAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,IACnD,KAAK,CAAC,KAAK,CACF;YACZ,oBAAC,eAAe,IACd,KAAK,EAAE,YAAY,CAAC,KAAK,EACzB,QAAQ,EAAE,YAAY,CAAC,QAAQ,KAC3B,KAAK,CAAC,UAAU,GACpB;YACD,KAAK,IAAI,oBAAC,cAAc,QAAE,KAAK,CAAC,OAAO,CAAkB,CAC9C,CACf,GACD,CACH,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FieldValues, Path, UseFormReturn } from "react-hook-form";
|
|
3
|
+
import { IDateField } from "../../types";
|
|
4
|
+
interface DateFieldProps<T extends FieldValues> {
|
|
5
|
+
field: IDateField<Path<T>>;
|
|
6
|
+
formControl: UseFormReturn<T>;
|
|
7
|
+
}
|
|
8
|
+
export declare const DateField: <T extends FieldValues>({ field, formControl, }: DateFieldProps<T>) => React.JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TextField as MuiTextField } from "@mui/material";
|
|
2
|
+
import { DatePicker } from "@mui/x-date-pickers";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { Controller } from "react-hook-form";
|
|
5
|
+
export const DateField = ({ field, formControl, }) => {
|
|
6
|
+
const { control } = formControl;
|
|
7
|
+
return (React.createElement(Controller, { name: field.name, control: control, rules: { required: field.required }, render: ({ field: controlField, fieldState: { error } }) => (React.createElement(DatePicker, { ...controlField, value: controlField.value || null, ...field.otherProps, label: field.label, onChange: (date) => controlField.onChange(date), renderInput: (params) => (React.createElement(MuiTextField, { ...params, required: field.required, error: !!error, helperText: error?.message, fullWidth: true })) })) }));
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=DateField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DateField.js","sourceRoot":"","sources":["../../../../src/components/fields/DateField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,YAAY,EAAkB,MAAM,eAAe,CAAA;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAoC,MAAM,iBAAiB,CAAA;AAQ9E,MAAM,CAAC,MAAM,SAAS,GAAG,CAAwB,EAC/C,KAAK,EACL,WAAW,GACO,EAAE,EAAE;IACtB,MAAM,EAAE,OAAO,EAAE,GAAG,WAAW,CAAA;IAE/B,OAAO,CACL,oBAAC,UAAU,IACT,IAAI,EAAE,KAAK,CAAC,IAAe,EAC3B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,EACnC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAC1D,oBAAC,UAAU,OACL,YAAY,EAChB,KAAK,EAAE,YAAY,CAAC,KAAK,IAAI,IAAI,KAC7B,KAAK,CAAC,UAAU,EACpB,KAAK,EAAE,KAAK,CAAC,KAAK,EAClB,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,EAC/C,WAAW,EAAE,CAAC,MAAsB,EAAE,EAAE,CAAC,CACvC,oBAAC,YAAY,OACP,MAAM,EACV,QAAQ,EAAE,KAAK,CAAC,QAAQ,EACxB,KAAK,EAAE,CAAC,CAAC,KAAK,EACd,UAAU,EAAE,KAAK,EAAE,OAAO,EAC1B,SAAS,SACT,CACH,GACD,CACH,GACD,CACH,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FieldValues, Path, UseFormReturn } from "react-hook-form";
|
|
3
|
+
import { IFileField } from "../../types";
|
|
4
|
+
interface FileFieldProps<T extends FieldValues> {
|
|
5
|
+
field: IFileField<Path<T>>;
|
|
6
|
+
formControl: UseFormReturn<T>;
|
|
7
|
+
}
|
|
8
|
+
export declare const FileField: <T extends FieldValues>({ field, formControl, }: FileFieldProps<T>) => React.JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Box, Button, FormControl, FormHelperText, FormLabel, IconButton, Stack, Typography, } from "@mui/material";
|
|
2
|
+
import { Close, InsertDriveFile } from "@mui/icons-material";
|
|
3
|
+
import React, { useRef } from "react";
|
|
4
|
+
import { Controller } from "react-hook-form";
|
|
5
|
+
export const FileField = ({ field, formControl, }) => {
|
|
6
|
+
const { control } = formControl;
|
|
7
|
+
const fileInputRef = useRef(null);
|
|
8
|
+
return (React.createElement(Controller, { name: field.name, control: control, rules: { required: field.required }, render: ({ field: controlField, fieldState: { error } }) => {
|
|
9
|
+
const selectedFile = controlField.value?.[0];
|
|
10
|
+
const previewUrl = selectedFile
|
|
11
|
+
? URL.createObjectURL(selectedFile)
|
|
12
|
+
: null;
|
|
13
|
+
return (React.createElement(FormControl, { fullWidth: true, error: !!error },
|
|
14
|
+
React.createElement(FormLabel, { component: "legend", required: field.required }, field.label),
|
|
15
|
+
React.createElement(Stack, { direction: "row", alignItems: "center", spacing: 2 },
|
|
16
|
+
React.createElement(Box, { onClick: () => fileInputRef.current?.click(), sx: { cursor: "pointer" }, ...field.otherProps },
|
|
17
|
+
field.fileInputComponent ? (typeof field.fileInputComponent === "function" ? (React.createElement(field.fileInputComponent)) : (field.fileInputComponent)) : (React.createElement(Button, { variant: "contained", component: "span" }, "Upload File")),
|
|
18
|
+
React.createElement("input", { type: "file", hidden: true, ref: fileInputRef, onChange: (e) => {
|
|
19
|
+
const fileValue = e.target.files && e.target.files.length > 0
|
|
20
|
+
? e.target.files
|
|
21
|
+
: undefined;
|
|
22
|
+
controlField.onChange(fileValue);
|
|
23
|
+
} })),
|
|
24
|
+
selectedFile && (React.createElement(Stack, { direction: "row", alignItems: "center", spacing: 1 },
|
|
25
|
+
selectedFile.type.startsWith("image/") && previewUrl ? (React.createElement("img", { src: previewUrl, alt: "Preview", style: {
|
|
26
|
+
maxWidth: "50px",
|
|
27
|
+
maxHeight: "50px",
|
|
28
|
+
objectFit: "contain",
|
|
29
|
+
} })) : (React.createElement(InsertDriveFile, { sx: { fontSize: 50 } })),
|
|
30
|
+
React.createElement(Typography, { variant: "body2" }, selectedFile.name),
|
|
31
|
+
React.createElement(IconButton, { size: "small", onClick: () => {
|
|
32
|
+
controlField.onChange(undefined);
|
|
33
|
+
if (fileInputRef.current) {
|
|
34
|
+
fileInputRef.current.value = ""; // Clear the input element
|
|
35
|
+
}
|
|
36
|
+
if (previewUrl) {
|
|
37
|
+
URL.revokeObjectURL(previewUrl); // Clean up the object URL
|
|
38
|
+
}
|
|
39
|
+
} },
|
|
40
|
+
React.createElement(Close, { fontSize: "small" }))))),
|
|
41
|
+
error && React.createElement(FormHelperText, null, error.message)));
|
|
42
|
+
} }));
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=FileField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileField.js","sourceRoot":"","sources":["../../../../src/components/fields/FileField.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,MAAM,EACN,WAAW,EACX,cAAc,EACd,SAAS,EACT,UAAU,EACV,KAAK,EACL,UAAU,GACX,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAA;AAC5D,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,EAAE,UAAU,EAAoC,MAAM,iBAAiB,CAAA;AAQ9E,MAAM,CAAC,MAAM,SAAS,GAAG,CAAwB,EAC/C,KAAK,EACL,WAAW,GACO,EAAE,EAAE;IACtB,MA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AC5D,CAAC;gCACD,IAAI,UAAU,EAAE,CAAC;oCACf,GAAG,CAAC,eAAe,CAAC,UAAU,CAAC,CAAA,CAAC,0BAA0B;gCAC5D,CAAC;4BACH,CAAC;4BACD,oBAAC,KAAK,IAAC,QAAQ,EAAC,OAAO,GAAG,CACf,CACP,CACT,CACK;gBACP,KAAK,IAAI,oBAAC,cAAc,QAAE,KAAK,CAAC,OAAO,CAAkB,CAC9C,CACf,CAAA;QACH,CAAC,GACD,CACH,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FieldValues, Path, UseFormReturn } from "react-hook-form";
|
|
3
|
+
import { IRadioGroupField } from "../../types";
|
|
4
|
+
interface RadioGroupFieldProps<T extends FieldValues> {
|
|
5
|
+
field: IRadioGroupField<Path<T>>;
|
|
6
|
+
formControl: UseFormReturn<T>;
|
|
7
|
+
}
|
|
8
|
+
export declare const RadioGroupField: <T extends FieldValues>({ field, formControl, }: RadioGroupFieldProps<T>) => React.JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FormControl, FormControlLabel, FormHelperText, FormLabel, Radio, RadioGroup, } from "@mui/material";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Controller } from "react-hook-form";
|
|
4
|
+
export const RadioGroupField = ({ field, formControl, }) => {
|
|
5
|
+
const { control } = formControl;
|
|
6
|
+
return (React.createElement(Controller, { name: field.name, control: control, rules: { required: field.required }, render: ({ field: controlField, fieldState: { error } }) => (React.createElement(FormControl, { component: "fieldset", error: !!error },
|
|
7
|
+
React.createElement(FormLabel, { component: "legend", required: field.required }, field.label),
|
|
8
|
+
React.createElement(RadioGroup, { ...controlField, value: controlField.value || "", onChange: (e) => controlField.onChange(e.target.value), row: field.otherProps?.row || false }, field.list?.map((option) => (React.createElement(FormControlLabel, { key: option.value, value: option.value, control: React.createElement(Radio, { ...field.otherProps }), label: option.label })))),
|
|
9
|
+
error && React.createElement(FormHelperText, null, error.message))) }));
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=RadioGroupField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RadioGroupField.js","sourceRoot":"","sources":["../../../../src/components/fields/RadioGroupField.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,SAAS,EACT,KAAK,EACL,UAAU,GACX,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAoC,MAAM,iBAAiB,CAAA;AAQ9E,MAAM,CAAC,MAAM,eAAe,GAAG,CAAwB,EACrD,KAAK,EACL,WAAW,GACa,EAAE,EAAE;IAC5B,MAAM,EAAE,OAAO,EAAE,GAAG,WAAW,CAAA;IAE/B,OAAO,CACL,oBAAC,UAAU,IACT,IAAI,EAAE,KAAK,CAAC,IAAe,EAC3B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,EACnC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAC1D,oBAAC,WAAW,IAAC,SAAS,EAAC,UAAU,EAAC,KAAK,EAAE,CAAC,CAAC,KAAK;YAC9C,oBAAC,SAAS,IAAC,SAAS,EAAC,QAAQ,EAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,IACnD,KAAK,CAAC,KAAK,CACF;YACZ,oBAAC,UAAU,OACL,YAAY,EAChB,KAAK,EAAE,YAAY,CAAC,KAAK,IAAI,EAAE,EAC/B,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EACtD,GAAG,EAAE,KAAK,CAAC,UAAU,EAAE,GAAG,IAAI,KAAK,IAClC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAC3B,oBAAC,gBAAgB,IACf,GAAG,EAAE,MAAM,CAAC,KAAK,EACjB,KAAK,EAAE,MAAM,CAAC,KAAK,EACnB,OAAO,EAAE,oBAAC,KAAK,OAAK,KAAK,CAAC,UAAU,GAAI,EACxC,KAAK,EAAE,MAAM,CAAC,KAAK,GACnB,CACH,CAAC,CACS;YACZ,KAAK,IAAI,oBAAC,cAAc,QAAE,KAAK,CAAC,OAAO,CAAkB,CAC9C,CACf,GACD,CACH,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FieldValues, Path, UseFormReturn } from "react-hook-form";
|
|
3
|
+
import { ISelectField } from "../../types";
|
|
4
|
+
interface SelectFieldProps<T extends FieldValues> {
|
|
5
|
+
field: ISelectField<Path<T>>;
|
|
6
|
+
formControl: UseFormReturn<T>;
|
|
7
|
+
}
|
|
8
|
+
export declare const SelectField: <T extends FieldValues>({ field, formControl, }: SelectFieldProps<T>) => React.JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FormControl, InputLabel, MenuItem, Select as MuiSelect, FormHelperText, } from "@mui/material";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Controller } from "react-hook-form";
|
|
4
|
+
export const SelectField = ({ field, formControl, }) => {
|
|
5
|
+
const { control } = formControl;
|
|
6
|
+
return (React.createElement(Controller, { name: field.name, control: control, rules: { required: field.required }, render: ({ field: controlField, fieldState: { error } }) => (React.createElement(FormControl, { fullWidth: true, error: !!error },
|
|
7
|
+
React.createElement(InputLabel, { required: field.required }, field.label),
|
|
8
|
+
React.createElement(MuiSelect, { label: field.label, ...controlField, value: controlField.value || (field.type === "multi-select" ? [] : ""), ...field.otherProps, multiple: field.type === "multi-select" }, field.list?.map((item) => (React.createElement(MenuItem, { key: item.value, value: item.value }, item.label)))),
|
|
9
|
+
error && React.createElement(FormHelperText, null, error.message))) }));
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=SelectField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SelectField.js","sourceRoot":"","sources":["../../../../src/components/fields/SelectField.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,UAAU,EACV,QAAQ,EACR,MAAM,IAAI,SAAS,EACnB,cAAc,GACf,MAAM,eAAe,CAAA;AACtB,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAoC,MAAM,iBAAiB,CAAA;AAQ9E,MAAM,CAAC,MAAM,WAAW,GAAG,CAAwB,EACjD,KAAK,EACL,WAAW,GACS,EAAE,EAAE;IACxB,MAAM,EAAE,OAAO,EAAE,GAAG,WAAW,CAAA;IAE/B,OAAO,CACL,oBAAC,UAAU,IACT,IAAI,EAAE,KAAK,CAAC,IAAe,EAC3B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,EACnC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAC1D,oBAAC,WAAW,IAAC,SAAS,QAAC,KAAK,EAAE,CAAC,CAAC,KAAK;YACnC,oBAAC,UAAU,IAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAG,KAAK,CAAC,KAAK,CAAc;YAChE,oBAAC,SAAS,IACR,KAAK,EAAE,KAAK,CAAC,KAAK,KACd,YAAY,EAChB,KAAK,EACH,YAAY,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,KAE7D,KAAK,CAAC,UAAU,EACpB,QAAQ,EAAE,KAAK,CAAC,IAAI,KAAK,cAAc,IACtC,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CACzB,oBAAC,QAAQ,IAAC,GAAG,EAAE,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,IACzC,IAAI,CAAC,KAAK,CACF,CACZ,CAAC,CACQ;YACX,KAAK,IAAI,oBAAC,cAAc,QAAE,KAAK,CAAC,OAAO,CAAkB,CAC9C,CACf,GACD,CACH,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FieldValues, Path, UseFormReturn } from "react-hook-form";
|
|
3
|
+
import { ISwitchField } from "../../types";
|
|
4
|
+
interface SwitchFieldProps<T extends FieldValues> {
|
|
5
|
+
field: ISwitchField<Path<T>>;
|
|
6
|
+
formControl: UseFormReturn<T>;
|
|
7
|
+
}
|
|
8
|
+
export declare const SwitchField: <T extends FieldValues>({ field, formControl, }: SwitchFieldProps<T>) => React.JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FormControlLabel, Switch as MuiSwitch } from "@mui/material";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Controller } from "react-hook-form";
|
|
4
|
+
export const SwitchField = ({ field, formControl, }) => {
|
|
5
|
+
const { control } = formControl;
|
|
6
|
+
return (React.createElement(Controller, { name: field.name, control: control, rules: { required: field.required }, render: ({ field: controlField, fieldState: { error } }) => (React.createElement(FormControlLabel, { control: React.createElement(MuiSwitch, { ...controlField, checked: !!controlField.value, onChange: (e) => controlField.onChange(e.target.checked), ...field.otherProps }), label: field.label })) }));
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=SwitchField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SwitchField.js","sourceRoot":"","sources":["../../../../src/components/fields/SwitchField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,eAAe,CAAA;AACrE,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAoC,MAAM,iBAAiB,CAAA;AAQ9E,MAAM,CAAC,MAAM,WAAW,GAAG,CAAwB,EACjD,KAAK,EACL,WAAW,GACS,EAAE,EAAE;IACxB,MAAM,EAAE,OAAO,EAAE,GAAG,WAAW,CAAA;IAE/B,OAAO,CACL,oBAAC,UAAU,IACT,IAAI,EAAE,KAAK,CAAC,IAAe,EAC3B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,EACnC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAC1D,oBAAC,gBAAgB,IACf,OAAO,EACL,oBAAC,SAAS,OACJ,YAAY,EAChB,OAAO,EAAE,CAAC,CAAC,YAAY,CAAC,KAAK,EAC7B,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,KACpD,KAAK,CAAC,UAAU,GACpB,EAEJ,KAAK,EAAE,KAAK,CAAC,KAAK,GAClB,CACH,GACD,CACH,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FieldValues, Path, UseFormReturn } from "react-hook-form";
|
|
3
|
+
import { ICustomField } from "../../types";
|
|
4
|
+
interface TextFieldProps<T extends FieldValues> {
|
|
5
|
+
field: ICustomField<Path<T>>;
|
|
6
|
+
formControl: UseFormReturn<T>;
|
|
7
|
+
}
|
|
8
|
+
export declare const TextField: <T extends FieldValues>({ field, formControl, }: TextFieldProps<T>) => React.JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TextField as MuiTextField } from "@mui/material";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Controller } from "react-hook-form";
|
|
4
|
+
export const TextField = ({ field, formControl, }) => {
|
|
5
|
+
const { control } = formControl;
|
|
6
|
+
return (React.createElement(Controller, { name: field.name, control: control, rules: { required: field.required }, render: ({ field: controlField, fieldState: { error } }) => (React.createElement(MuiTextField, { ...controlField, value: controlField.value || "", ...field.otherProps, label: field.label, type: field.type, fullWidth: true, required: field.required, error: !!error, helperText: error?.message, onChange: (e) => {
|
|
7
|
+
if (!e.target.value)
|
|
8
|
+
return controlField.onChange(undefined);
|
|
9
|
+
controlField.onChange(field.type === "number"
|
|
10
|
+
? parseFloat(e.target.value)
|
|
11
|
+
: e.target.value);
|
|
12
|
+
} })) }));
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=TextField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextField.js","sourceRoot":"","sources":["../../../../src/components/fields/TextField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,eAAe,CAAA;AACzD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAoC,MAAM,iBAAiB,CAAA;AAQ9E,MAAM,CAAC,MAAM,SAAS,GAAG,CAAwB,EAC/C,KAAK,EACL,WAAW,GACO,EAAE,EAAE;IACtB,MAAM,EAAE,OAAO,EAAE,GAAG,WAAW,CAAA;IAE/B,OAAO,CACL,oBAAC,UAAU,IACT,IAAI,EAAE,KAAK,CAAC,IAAe,EAC3B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,EACnC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAC1D,oBAAC,YAAY,OACP,YAAY,EAChB,KAAK,EAAE,YAAY,CAAC,KAAK,IAAI,EAAE,KAC3B,KAAK,CAAC,UAAU,EACpB,KAAK,EAAE,KAAK,CAAC,KAAK,EAClB,IAAI,EAAE,KAAK,CAAC,IAAI,EAChB,SAAS,QACT,QAAQ,EAAE,KAAK,CAAC,QAAQ,EACxB,KAAK,EAAE,CAAC,CAAC,KAAK,EACd,UAAU,EAAE,KAAK,EAAE,OAAO,EAC1B,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE;gBACd,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK;oBAAE,OAAO,YAAY,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAA;gBAC5D,YAAY,CAAC,QAAQ,CACnB,KAAK,CAAC,IAAI,KAAK,QAAQ;oBACrB,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;oBAC5B,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CACnB,CAAA;YACH,CAAC,GACD,CACH,GACD,CACH,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FieldValues, Path, UseFormReturn } from "react-hook-form";
|
|
3
|
+
import { ICustomField } from "../../types";
|
|
4
|
+
interface TextareaFieldProps<T extends FieldValues> {
|
|
5
|
+
field: ICustomField<Path<T>>;
|
|
6
|
+
formControl: UseFormReturn<T>;
|
|
7
|
+
}
|
|
8
|
+
export declare const TextareaField: <T extends FieldValues>({ field, formControl, }: TextareaFieldProps<T>) => React.JSX.Element;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TextField as MuiTextField } from "@mui/material";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { Controller } from "react-hook-form";
|
|
4
|
+
export const TextareaField = ({ field, formControl, }) => {
|
|
5
|
+
const { control } = formControl;
|
|
6
|
+
return (React.createElement(Controller, { name: field.name, control: control, rules: { required: field.required }, render: ({ field: controlField, fieldState: { error } }) => (React.createElement(MuiTextField, { ...controlField, value: controlField.value || "", ...field.otherProps, label: field.label, type: "text", fullWidth: true, multiline: true, rows: field.otherProps?.rows || 4, required: field.required, error: !!error, helperText: error?.message, onChange: controlField.onChange })) }));
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=TextareaField.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextareaField.js","sourceRoot":"","sources":["../../../../src/components/fields/TextareaField.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,YAAY,EAAE,MAAM,eAAe,CAAA;AACzD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAoC,MAAM,iBAAiB,CAAA;AAQ9E,MAAM,CAAC,MAAM,aAAa,GAAG,CAAwB,EACnD,KAAK,EACL,WAAW,GACW,EAAE,EAAE;IAC1B,MAAM,EAAE,OAAO,EAAE,GAAG,WAAW,CAAA;IAE/B,OAAO,CACL,oBAAC,UAAU,IACT,IAAI,EAAE,KAAK,CAAC,IAAe,EAC3B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,EACnC,MAAM,EAAE,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,CAAC,CAC1D,oBAAC,YAAY,OACP,YAAY,EAChB,KAAK,EAAE,YAAY,CAAC,KAAK,IAAI,EAAE,KAC3B,KAAK,CAAC,UAAU,EACpB,KAAK,EAAE,KAAK,CAAC,KAAK,EAClB,IAAI,EAAC,MAAM,EACX,SAAS,QACT,SAAS,QACT,IAAI,EAAE,KAAK,CAAC,UAAU,EAAE,IAAI,IAAI,CAAC,EACjC,QAAQ,EAAE,KAAK,CAAC,QAAQ,EACxB,KAAK,EAAE,CAAC,CAAC,KAAK,EACd,UAAU,EAAE,KAAK,EAAE,OAAO,EAC1B,QAAQ,EAAE,YAAY,CAAC,QAAQ,GAC/B,CACH,GACD,CACH,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { ButtonProps, StackProps } from "@mui/material";
|
|
2
|
+
import { CSSProperties } from "react";
|
|
3
|
+
import { FieldPath, FieldValues, SubmitErrorHandler, SubmitHandler, UseFormReturn } from "react-hook-form";
|
|
4
|
+
export type TOption<T = any> = {
|
|
5
|
+
icon?: React.ReactNode;
|
|
6
|
+
label: string;
|
|
7
|
+
value: T;
|
|
8
|
+
};
|
|
9
|
+
type FileInputComponent = React.ReactNode | React.ElementType;
|
|
10
|
+
export interface ICustomFieldBase<T extends string> {
|
|
11
|
+
label: string;
|
|
12
|
+
name: T;
|
|
13
|
+
required?: boolean;
|
|
14
|
+
otherProps?: any;
|
|
15
|
+
span?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface ITextField<T extends string> extends ICustomFieldBase<T> {
|
|
18
|
+
type: "text" | "number" | "password";
|
|
19
|
+
}
|
|
20
|
+
export interface ITextareaField<T extends string> extends ICustomFieldBase<T> {
|
|
21
|
+
type: "textarea";
|
|
22
|
+
}
|
|
23
|
+
export interface ISelectField<T extends string> extends ICustomFieldBase<T> {
|
|
24
|
+
type: "single-select" | "multi-select";
|
|
25
|
+
list: TOption[];
|
|
26
|
+
}
|
|
27
|
+
export interface IDateField<T extends string> extends ICustomFieldBase<T> {
|
|
28
|
+
type: "date";
|
|
29
|
+
}
|
|
30
|
+
export interface IFileField<T extends string> extends ICustomFieldBase<T> {
|
|
31
|
+
type: "file";
|
|
32
|
+
fileInputComponent?: FileInputComponent;
|
|
33
|
+
}
|
|
34
|
+
export interface ISwitchField<T extends string> extends ICustomFieldBase<T> {
|
|
35
|
+
type: "switch";
|
|
36
|
+
}
|
|
37
|
+
export interface ICheckboxGroupField<T extends string> extends ICustomFieldBase<T> {
|
|
38
|
+
type: "checkbox-group";
|
|
39
|
+
list: TOption[];
|
|
40
|
+
}
|
|
41
|
+
export interface IRadioGroupField<T extends string> extends ICustomFieldBase<T> {
|
|
42
|
+
type: "radio-group";
|
|
43
|
+
list: TOption[];
|
|
44
|
+
}
|
|
45
|
+
export interface ICustomComponentField<T extends string> extends ICustomFieldBase<T> {
|
|
46
|
+
type: "custom";
|
|
47
|
+
component: React.ComponentType<CustomComponentProps>;
|
|
48
|
+
}
|
|
49
|
+
export type ICustomField<T extends string> = ITextField<T> | ITextareaField<T> | ISelectField<T> | IDateField<T> | IFileField<T> | ISwitchField<T> | ICheckboxGroupField<T> | IRadioGroupField<T> | ICustomComponentField<T>;
|
|
50
|
+
export type IFieldGroup<TFormValues extends FieldValues = FieldValues> = ICustomField<FieldPath<TFormValues>>[][];
|
|
51
|
+
export interface ICustomForm<T extends FieldValues> {
|
|
52
|
+
fieldsGroups: IFieldGroup<T>;
|
|
53
|
+
onSubmit: [SubmitHandler<T>, SubmitErrorHandler<T>?];
|
|
54
|
+
formControl: UseFormReturn<T>;
|
|
55
|
+
actionButtonsPlacement?: CSSProperties["justifyContent"];
|
|
56
|
+
submitButton?: ButtonProps | boolean;
|
|
57
|
+
resetButton?: ButtonProps | boolean;
|
|
58
|
+
layout?: StackProps["direction"];
|
|
59
|
+
otherProps?: StackProps;
|
|
60
|
+
}
|
|
61
|
+
export interface CustomComponentProps {
|
|
62
|
+
value: any;
|
|
63
|
+
onChange: (value: any) => void;
|
|
64
|
+
[key: string]: any;
|
|
65
|
+
}
|
|
66
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ButtonProps, StackProps } from "@mui/material";
|
|
2
|
+
import { CSSProperties } from "react";
|
|
2
3
|
import { FieldPath, FieldValues, SubmitErrorHandler, SubmitHandler, UseFormReturn } from "react-hook-form";
|
|
3
4
|
export type TOption<T = any> = {
|
|
4
5
|
icon?: React.ReactNode;
|
|
@@ -51,7 +52,7 @@ export interface ICustomForm<T extends FieldValues> {
|
|
|
51
52
|
fieldsGroups: IFieldGroup<T>;
|
|
52
53
|
onSubmit: [SubmitHandler<T>, SubmitErrorHandler<T>?];
|
|
53
54
|
formControl: UseFormReturn<T>;
|
|
54
|
-
actionButtonsPlacement?:
|
|
55
|
+
actionButtonsPlacement?: CSSProperties["justifyContent"];
|
|
55
56
|
submitButton?: ButtonProps | boolean;
|
|
56
57
|
resetButton?: ButtonProps | boolean;
|
|
57
58
|
layout?: StackProps["direction"];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mui-custom-form",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A versatile React form component utilizing MUI components and react-hook-form.",
|
|
5
5
|
"main": "dist/CustomForm.js",
|
|
6
6
|
"types": "dist/CustomForm.d.ts",
|
|
@@ -27,24 +27,24 @@
|
|
|
27
27
|
],
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@emotion/react": "^11.14.0",
|
|
30
|
-
"@emotion/styled": "^11.14.
|
|
31
|
-
"@mui/x-date-pickers": "^
|
|
32
|
-
"date-fns": "^4.
|
|
33
|
-
"dayjs": "^1.11.
|
|
30
|
+
"@emotion/styled": "^11.14.1",
|
|
31
|
+
"@mui/x-date-pickers": "^9.7.0",
|
|
32
|
+
"date-fns": "^4.4.0",
|
|
33
|
+
"dayjs": "^1.11.21",
|
|
34
34
|
"moment": "^2.30.1",
|
|
35
35
|
"react": "^18.0.0 || ^19.0.0",
|
|
36
36
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
37
37
|
"react-hook-form": "^7.56.3"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/node": "^
|
|
40
|
+
"@types/node": "^24.13.2",
|
|
41
41
|
"@types/react": "^18.0.0 || ^19.0.0",
|
|
42
42
|
"@types/react-dom": "^18.0.0 || ^19.0.0",
|
|
43
|
-
"typescript": "^
|
|
43
|
+
"typescript": "^6.0.3"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@mui/icons-material": "^
|
|
47
|
-
"@mui/material": "^
|
|
48
|
-
"react-hook-form": "^7.
|
|
46
|
+
"@mui/icons-material": "^9.1.1",
|
|
47
|
+
"@mui/material": "^9.1.2",
|
|
48
|
+
"react-hook-form": "^7.80.0"
|
|
49
49
|
}
|
|
50
50
|
}
|