shadcn-zod-formkit 1.5.0 → 1.7.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/README.md +2 -1
- package/dist/index.cjs +35 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.mjs +36 -23
- package/dist/index.mjs.map +1 -1
- package/dist/shadcn-zod-formkit-1.7.0.tgz +0 -0
- package/package.json +1 -1
- package/dist/shadcn-zod-formkit-1.5.0.tgz +0 -0
package/README.md
CHANGED
|
@@ -116,7 +116,8 @@ const mockFields: Array<FieldProps |FieldProps[]> = [
|
|
|
116
116
|
| **Upload Multi File** | `InputTypes.FILE_MULTI_UPLOAD` |
|
|
117
117
|
| **Button Group** | `InputTypes.BUTTON_GROUP` |
|
|
118
118
|
| **Input Currency** | `InputTypes.CURRENCY` |
|
|
119
|
-
| **Input Key Value** | `InputTypes.KEY_VALUE`
|
|
119
|
+
| **Input Key Value** | `InputTypes.KEY_VALUE` |
|
|
120
|
+
| **Input Repeater** | `InputTypes.REPEATER` |
|
|
120
121
|
|
|
121
122
|
|
|
122
123
|
|
package/dist/index.cjs
CHANGED
|
@@ -4932,23 +4932,27 @@ var getFieldLabel = (fieldErrorKey, fields) => {
|
|
|
4932
4932
|
const findedField = fields.find((field) => field.name == fieldErrorKey);
|
|
4933
4933
|
return findedField?.label ?? fieldErrorKey;
|
|
4934
4934
|
};
|
|
4935
|
-
var FormFieldsGrid = ({ fields, form, isPending, className = "", gap = "gap-2" }) => {
|
|
4935
|
+
var FormFieldsGrid = ({ fields, form, isPending, readOnly, className = "", gap = "gap-2" }) => {
|
|
4936
4936
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fields.map(
|
|
4937
|
-
(input, idx) => Array.isArray(input) ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "w-full flex flex-row justify-between py-3", children: input.map((field, subIdx) =>
|
|
4937
|
+
(input, idx) => Array.isArray(input) ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "w-full flex flex-row justify-between py-3", children: input.map((field, subIdx) => {
|
|
4938
|
+
if (readOnly) field.disabled = readOnly;
|
|
4939
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full px-2", children: InputFactory.create(field, form, isPending) }, subIdx);
|
|
4940
|
+
}) }, `field-group-${idx}`) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex flex-col justify-between py-3 w-full px-2", children: InputFactory.create(input, form, isPending) }, `field-group-${idx}`)
|
|
4938
4941
|
) });
|
|
4939
4942
|
};
|
|
4940
4943
|
var DynamicForm = ({
|
|
4941
4944
|
formTitle,
|
|
4942
4945
|
formSubTitle,
|
|
4943
4946
|
fields,
|
|
4947
|
+
readOnly = false,
|
|
4944
4948
|
record = {},
|
|
4945
4949
|
onSubmit,
|
|
4946
4950
|
extraValidations,
|
|
4947
|
-
withCard = false,
|
|
4948
4951
|
withErrorsAlert = true,
|
|
4949
4952
|
errorAlertPosition = "up",
|
|
4953
|
+
withCard = false,
|
|
4950
4954
|
submitBtnClass = "",
|
|
4951
|
-
submitBtnLabel = "
|
|
4955
|
+
submitBtnLabel = "Guardar"
|
|
4952
4956
|
}) => {
|
|
4953
4957
|
const [isPending, startTransition] = React3.useTransition();
|
|
4954
4958
|
const schema = React3.useMemo(() => getDynamicSchema(fields, extraValidations), [fields, extraValidations]);
|
|
@@ -4958,14 +4962,13 @@ var DynamicForm = ({
|
|
|
4958
4962
|
defaultValues
|
|
4959
4963
|
});
|
|
4960
4964
|
React3.useEffect(() => {
|
|
4961
|
-
console.log("\u{1F501} Redibuja cuando cambian los fields o los valores por defecto");
|
|
4962
4965
|
form.reset(defaultValues);
|
|
4963
|
-
}, []);
|
|
4966
|
+
}, [defaultValues, form]);
|
|
4964
4967
|
const handleSubmit = (data) => {
|
|
4968
|
+
if (readOnly) return;
|
|
4965
4969
|
try {
|
|
4966
4970
|
startTransition(async () => {
|
|
4967
4971
|
const resp = { data, form };
|
|
4968
|
-
await new Promise((resolve) => setTimeout(resolve, 3e3));
|
|
4969
4972
|
onSubmit?.(resp);
|
|
4970
4973
|
});
|
|
4971
4974
|
} catch (error) {
|
|
@@ -4973,22 +4976,32 @@ var DynamicForm = ({
|
|
|
4973
4976
|
}
|
|
4974
4977
|
};
|
|
4975
4978
|
const formContent = /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
4976
|
-
/* @__PURE__ */ jsxRuntime.jsxs(CardTitle, { className: "flex
|
|
4977
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.
|
|
4978
|
-
|
|
4979
|
+
/* @__PURE__ */ jsxRuntime.jsxs(CardTitle, { className: "flex items-center gap-2 p-2 border-b", children: [
|
|
4980
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pencil, { className: "h-5 w-5" }),
|
|
4981
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
|
|
4982
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { children: formTitle }),
|
|
4983
|
+
formSubTitle && /* @__PURE__ */ jsxRuntime.jsx(CardDescription, { children: formSubTitle })
|
|
4984
|
+
] })
|
|
4979
4985
|
] }),
|
|
4980
|
-
withErrorsAlert && errorAlertPosition
|
|
4981
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4986
|
+
withErrorsAlert && errorAlertPosition === "up" && /* @__PURE__ */ jsxRuntime.jsx(FormErrorsAlert, { formState: form.formState, fields }),
|
|
4987
|
+
/* @__PURE__ */ jsxRuntime.jsx(Form, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4988
|
+
"form",
|
|
4989
|
+
{
|
|
4990
|
+
onSubmit: form.handleSubmit(handleSubmit),
|
|
4991
|
+
className: `flex flex-col gap-2 ${readOnly ? "opacity-70 pointer-events-none select-none" : ""}`,
|
|
4992
|
+
children: [
|
|
4993
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full grid grid-cols-1", children: /* @__PURE__ */ jsxRuntime.jsx(FormFieldsGrid, { fields, form, readOnly }) }),
|
|
4994
|
+
!readOnly && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row gap-2 justify-end items-end", children: /* @__PURE__ */ jsxRuntime.jsx(Button, { type: "submit", size: "lg", className: submitBtnClass, disabled: isPending, children: isPending ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4995
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-4 w-4 mr-2 animate-spin" }),
|
|
4996
|
+
"Guardando..."
|
|
4997
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4998
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Save, { className: "h-4 w-4 mr-2" }),
|
|
4999
|
+
submitBtnLabel
|
|
5000
|
+
] }) }) })
|
|
5001
|
+
]
|
|
5002
|
+
}
|
|
5003
|
+
) }),
|
|
5004
|
+
withErrorsAlert && errorAlertPosition === "down" && /* @__PURE__ */ jsxRuntime.jsx(FormErrorsAlert, { formState: form.formState, fields })
|
|
4992
5005
|
] });
|
|
4993
5006
|
if (!withCard) return formContent;
|
|
4994
5007
|
return /* @__PURE__ */ jsxRuntime.jsx(Card, { children: /* @__PURE__ */ jsxRuntime.jsx(CardContent, { children: formContent }) });
|