shadcn-zod-formkit 1.6.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 +30 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.mjs +31 -16
- 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.6.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,15 +4932,19 @@ 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,
|
|
@@ -4948,7 +4952,7 @@ var DynamicForm = ({
|
|
|
4948
4952
|
errorAlertPosition = "up",
|
|
4949
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]);
|
|
@@ -4961,6 +4965,7 @@ var DynamicForm = ({
|
|
|
4961
4965
|
form.reset(defaultValues);
|
|
4962
4966
|
}, [defaultValues, form]);
|
|
4963
4967
|
const handleSubmit = (data) => {
|
|
4968
|
+
if (readOnly) return;
|
|
4964
4969
|
try {
|
|
4965
4970
|
startTransition(async () => {
|
|
4966
4971
|
const resp = { data, form };
|
|
@@ -4972,20 +4977,30 @@ var DynamicForm = ({
|
|
|
4972
4977
|
};
|
|
4973
4978
|
const formContent = /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
4974
4979
|
/* @__PURE__ */ jsxRuntime.jsxs(CardTitle, { className: "flex items-center gap-2 p-2 border-b", children: [
|
|
4975
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.
|
|
4976
|
-
|
|
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
|
+
] })
|
|
4977
4985
|
] }),
|
|
4978
4986
|
withErrorsAlert && errorAlertPosition === "up" && /* @__PURE__ */ jsxRuntime.jsx(FormErrorsAlert, { formState: form.formState, fields }),
|
|
4979
|
-
/* @__PURE__ */ jsxRuntime.jsx(Form, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
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
|
+
) }),
|
|
4989
5004
|
withErrorsAlert && errorAlertPosition === "down" && /* @__PURE__ */ jsxRuntime.jsx(FormErrorsAlert, { formState: form.formState, fields })
|
|
4990
5005
|
] });
|
|
4991
5006
|
if (!withCard) return formContent;
|