shadcn-zod-formkit 1.4.0 → 1.5.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/index.cjs +103 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.mjs +104 -4
- package/dist/index.mjs.map +1 -1
- package/dist/shadcn-zod-formkit-1.5.0.tgz +0 -0
- package/package.json +1 -1
- package/dist/shadcn-zod-formkit-1.4.0.tgz +0 -0
package/dist/index.cjs
CHANGED
|
@@ -265,9 +265,11 @@ var InputTypes = /* @__PURE__ */ ((InputTypes2) => {
|
|
|
265
265
|
InputTypes2["BUTTON_GROUP"] = "button_group";
|
|
266
266
|
InputTypes2["CURRENCY"] = "currency";
|
|
267
267
|
InputTypes2["KEY_VALUE"] = "key_value";
|
|
268
|
+
InputTypes2["REPEATER"] = "repeater";
|
|
268
269
|
return InputTypes2;
|
|
269
270
|
})(InputTypes || {});
|
|
270
271
|
var inputFieldComp = [
|
|
272
|
+
"repeater" /* REPEATER */,
|
|
271
273
|
"key_value" /* KEY_VALUE */,
|
|
272
274
|
"currency" /* CURRENCY */,
|
|
273
275
|
"button_group" /* BUTTON_GROUP */,
|
|
@@ -4217,6 +4219,100 @@ var FieldRadioGroup = ({ input, form, isSubmitting }) => {
|
|
|
4217
4219
|
);
|
|
4218
4220
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: formField });
|
|
4219
4221
|
};
|
|
4222
|
+
var RepeaterInput = class extends BaseInput {
|
|
4223
|
+
render() {
|
|
4224
|
+
const { input, form, isSubmitting } = this;
|
|
4225
|
+
return /* @__PURE__ */ jsxRuntime.jsx(FieldRepeater, { form, input, isSubmitting });
|
|
4226
|
+
}
|
|
4227
|
+
};
|
|
4228
|
+
var FieldRepeater = ({ form, input, isSubmitting }) => {
|
|
4229
|
+
const { control } = form;
|
|
4230
|
+
const { fields, append, remove } = reactHookForm.useFieldArray({
|
|
4231
|
+
control,
|
|
4232
|
+
name: input.name
|
|
4233
|
+
});
|
|
4234
|
+
const canAdd = !input.maxItems || fields.length < input.maxItems;
|
|
4235
|
+
const canRemove = fields.length > (input.minItems ?? 0);
|
|
4236
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4237
|
+
FormField,
|
|
4238
|
+
{
|
|
4239
|
+
control,
|
|
4240
|
+
name: input.name,
|
|
4241
|
+
render: () => /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: input.className, children: [
|
|
4242
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
|
|
4243
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "space-y-3", children: [
|
|
4244
|
+
fields.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4245
|
+
"div",
|
|
4246
|
+
{
|
|
4247
|
+
className: "border p-3 rounded-md flex flex-col gap-3",
|
|
4248
|
+
children: [
|
|
4249
|
+
input.repeaterFields?.map((fieldGroup, groupIndex) => {
|
|
4250
|
+
const group = Array.isArray(fieldGroup) ? fieldGroup : [fieldGroup];
|
|
4251
|
+
const cols = group.length;
|
|
4252
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4253
|
+
"div",
|
|
4254
|
+
{
|
|
4255
|
+
className: `grid gap-3 grid-cols-${cols}`,
|
|
4256
|
+
children: group.map((subField) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
4257
|
+
FormField,
|
|
4258
|
+
{
|
|
4259
|
+
control,
|
|
4260
|
+
name: `${input.name}.${index}.${subField.name}`,
|
|
4261
|
+
render: ({ field, fieldState }) => /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: "flex-1", children: [
|
|
4262
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: subField.label }),
|
|
4263
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4264
|
+
Input,
|
|
4265
|
+
{
|
|
4266
|
+
placeholder: subField.placeHolder,
|
|
4267
|
+
disabled: subField.disabled || isSubmitting,
|
|
4268
|
+
...field
|
|
4269
|
+
}
|
|
4270
|
+
) }),
|
|
4271
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormMessage, { children: fieldState.error?.message })
|
|
4272
|
+
] })
|
|
4273
|
+
},
|
|
4274
|
+
`${input.name}.${index}.${subField.name}`
|
|
4275
|
+
))
|
|
4276
|
+
},
|
|
4277
|
+
groupIndex
|
|
4278
|
+
);
|
|
4279
|
+
}),
|
|
4280
|
+
canRemove && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4281
|
+
Button,
|
|
4282
|
+
{
|
|
4283
|
+
type: "button",
|
|
4284
|
+
variant: "destructive",
|
|
4285
|
+
size: "icon",
|
|
4286
|
+
onClick: () => remove(index),
|
|
4287
|
+
className: "self-end",
|
|
4288
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { size: 18 })
|
|
4289
|
+
}
|
|
4290
|
+
)
|
|
4291
|
+
]
|
|
4292
|
+
},
|
|
4293
|
+
item.id
|
|
4294
|
+
)),
|
|
4295
|
+
canAdd && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4296
|
+
Button,
|
|
4297
|
+
{
|
|
4298
|
+
type: "button",
|
|
4299
|
+
variant: "secondary",
|
|
4300
|
+
onClick: () => append({}),
|
|
4301
|
+
disabled: isSubmitting,
|
|
4302
|
+
className: "w-full",
|
|
4303
|
+
children: [
|
|
4304
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Plus, { size: 16, className: "mr-2" }),
|
|
4305
|
+
"Agregar"
|
|
4306
|
+
]
|
|
4307
|
+
}
|
|
4308
|
+
)
|
|
4309
|
+
] }) }),
|
|
4310
|
+
input.description && /* @__PURE__ */ jsxRuntime.jsx(FormDescription, { children: input.description }),
|
|
4311
|
+
/* @__PURE__ */ jsxRuntime.jsx(FormMessage, {})
|
|
4312
|
+
] })
|
|
4313
|
+
}
|
|
4314
|
+
);
|
|
4315
|
+
};
|
|
4220
4316
|
var SelectInput = class extends BaseInput {
|
|
4221
4317
|
render() {
|
|
4222
4318
|
const { input, form, isSubmitting } = this;
|
|
@@ -4744,6 +4840,7 @@ var inputMap = {
|
|
|
4744
4840
|
["button_group" /* BUTTON_GROUP */]: ButtonGroupInput,
|
|
4745
4841
|
["currency" /* CURRENCY */]: CurrencyInput,
|
|
4746
4842
|
["key_value" /* KEY_VALUE */]: KeyValueListInput,
|
|
4843
|
+
["repeater" /* REPEATER */]: RepeaterInput,
|
|
4747
4844
|
//ToDos: ============================================================
|
|
4748
4845
|
["slider" /* SLIDER */]: SliderInput,
|
|
4749
4846
|
//ToDo: // PENDIENTE ... VISUALMENTE NO SE VE BIEN.!!!
|
|
@@ -4835,6 +4932,11 @@ var getFieldLabel = (fieldErrorKey, fields) => {
|
|
|
4835
4932
|
const findedField = fields.find((field) => field.name == fieldErrorKey);
|
|
4836
4933
|
return findedField?.label ?? fieldErrorKey;
|
|
4837
4934
|
};
|
|
4935
|
+
var FormFieldsGrid = ({ fields, form, isPending, className = "", gap = "gap-2" }) => {
|
|
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) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full px-2", children: InputFactory.create(field, form, isPending) }, subIdx)) }, `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
|
+
) });
|
|
4939
|
+
};
|
|
4838
4940
|
var DynamicForm = ({
|
|
4839
4941
|
formTitle,
|
|
4840
4942
|
formSubTitle,
|
|
@@ -4877,9 +4979,7 @@ var DynamicForm = ({
|
|
|
4877
4979
|
] }),
|
|
4878
4980
|
withErrorsAlert && errorAlertPosition == "up" && /* @__PURE__ */ jsxRuntime.jsx(FormErrorsAlert, { formState: form.formState, fields }),
|
|
4879
4981
|
/* @__PURE__ */ jsxRuntime.jsx(Form, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: form.handleSubmit(handleSubmit), className: "flex flex-col gap-2", children: [
|
|
4880
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full grid grid-cols-1", children:
|
|
4881
|
-
(input, idx) => Array.isArray(input) ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "w-full flex flex-row justify-between py-3", children: input.map((field, subIdx) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full px-2", children: InputFactory.create(field, form, isPending) }, subIdx)) }, `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}`)
|
|
4882
|
-
) }),
|
|
4982
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full grid grid-cols-1", children: /* @__PURE__ */ jsxRuntime.jsx(FormFieldsGrid, { fields, form }) }),
|
|
4883
4983
|
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row gap-2 justify-end items-end justify-items-end", children: /* @__PURE__ */ jsxRuntime.jsx(Button, { type: "submit", size: "lg", className: submitBtnClass, disabled: isPending, children: isPending ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4884
4984
|
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-4 w-4 mr-2 animate-spin" }),
|
|
4885
4985
|
submitBtnLabel ?? "Saving..."
|