mui-custom-form 1.1.2 → 1.1.4
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/README.md +1 -1
- package/dist/CustomForm.js +17 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -189,7 +189,7 @@ const Fields = z.object({
|
|
|
189
189
|
.array(z.enum(HOBBIES), { required_error: "Hobbies are required" })
|
|
190
190
|
.nonempty("Please choose at least one hobby"),
|
|
191
191
|
birthDate: z.date({ required_error: "Birthdate is required" }),
|
|
192
|
-
file: z.instanceof(
|
|
192
|
+
file: z.instanceof(FileList).optional(),
|
|
193
193
|
});
|
|
194
194
|
|
|
195
195
|
type FieldTypes = z.infer<typeof Fields>;
|
package/dist/CustomForm.js
CHANGED
|
@@ -76,7 +76,7 @@ var CustomForm = function (_a) {
|
|
|
76
76
|
"Upload File",
|
|
77
77
|
react_1.default.createElement("input", __assign({ type: "file", hidden: true, onChange: function (e) {
|
|
78
78
|
var fileValue = e.target.files && e.target.files.length > 0
|
|
79
|
-
? e.target.files
|
|
79
|
+
? e.target.files
|
|
80
80
|
: undefined;
|
|
81
81
|
setValue(field.name, fileValue);
|
|
82
82
|
} }, field.otherProps)))));
|
|
@@ -135,8 +135,23 @@ var CustomForm = function (_a) {
|
|
|
135
135
|
};
|
|
136
136
|
var submitButtonProps = submitButton && submitButton !== true ? submitButton : {};
|
|
137
137
|
var resetButtonProps = resetButton && resetButton !== true ? resetButton : {};
|
|
138
|
+
// Function to calculate spans dynamically
|
|
139
|
+
var calculateSpan = function (fields) {
|
|
140
|
+
var totalDefinedSpan = fields.reduce(function (acc, field) { return acc + (field.span || 0); }, 0);
|
|
141
|
+
var autoSpanFields = fields.filter(function (field) { return !field.span; }).length;
|
|
142
|
+
var remainingSpan = 12 - totalDefinedSpan;
|
|
143
|
+
var calculatedSpan = autoSpanFields > 0 ? Math.floor(remainingSpan / autoSpanFields) : 12;
|
|
144
|
+
return { calculatedSpan: calculatedSpan, autoSpanFields: autoSpanFields };
|
|
145
|
+
};
|
|
138
146
|
return (react_1.default.createElement(material_1.Stack, __assign({ component: "form", onSubmit: formControl.handleSubmit(onSubmit[0], onSubmit[1]), noValidate: true, direction: layout }, otherProps, { spacing: 3 }),
|
|
139
|
-
fieldsGroups.map(function (fields, rowIndex) {
|
|
147
|
+
fieldsGroups.map(function (fields, rowIndex) {
|
|
148
|
+
var _a = calculateSpan(fields), calculatedSpan = _a.calculatedSpan, autoSpanFields = _a.autoSpanFields;
|
|
149
|
+
return (react_1.default.createElement(material_1.Grid2, { container: true, key: rowIndex, spacing: 2, className: "debug" }, fields.map(function (field, fieldIndex) { return (react_1.default.createElement(material_1.Grid2, { key: fieldIndex, size: field.span
|
|
150
|
+
? field.span
|
|
151
|
+
: autoSpanFields > 0
|
|
152
|
+
? calculatedSpan
|
|
153
|
+
: 12 }, renderField(field))); })));
|
|
154
|
+
}),
|
|
140
155
|
react_1.default.createElement(material_1.Stack, { direction: "row", justifyContent: actionButtonsPlacement || "flex-end", spacing: 2 },
|
|
141
156
|
resetButton && (react_1.default.createElement(material_1.Button, __assign({ type: "reset", variant: "contained", onClick: function () { return reset(); } }, resetButtonProps), "Reset")),
|
|
142
157
|
submitButton && (react_1.default.createElement(material_1.Button, __assign({ type: "submit", variant: "contained" }, submitButtonProps), "Submit")))));
|
package/package.json
CHANGED