shadcn-zod-formkit 1.18.0 → 1.19.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 CHANGED
@@ -1815,22 +1815,17 @@ var FieldButtonGroup = ({ input, form, isSubmitting }) => {
1815
1815
  form.setValue(input.name, value, { shouldValidate: true });
1816
1816
  };
1817
1817
  const selectedValue = form.watch(input.name);
1818
- return (
1819
- // <div className="flex flex-col gap-1 w-full">
1820
- // <label className="font-semibold">{input.label}</label>
1821
- // <div className="flex flex-wrap gap-2">
1822
- /* @__PURE__ */ jsxRuntime.jsx(ButtonGroup, { children: options.map((option) => /* @__PURE__ */ jsxRuntime.jsx(
1823
- Button,
1824
- {
1825
- type: "button",
1826
- variant: selectedValue === option.value ? "default" : "outline",
1827
- onClick: () => handleSelect(option.value),
1828
- disabled: isSubmitting,
1829
- children: option.label ?? option.name
1830
- },
1831
- option.value
1832
- )) })
1833
- );
1818
+ return /* @__PURE__ */ jsxRuntime.jsx(ButtonGroup, { children: options.map((option) => /* @__PURE__ */ jsxRuntime.jsx(
1819
+ Button,
1820
+ {
1821
+ type: "button",
1822
+ variant: selectedValue === option.value ? "default" : "outline",
1823
+ onClick: () => handleSelect(option.value),
1824
+ disabled: isSubmitting,
1825
+ children: option.label ?? option.name
1826
+ },
1827
+ option.value
1828
+ )) });
1834
1829
  };
1835
1830
  var CheckListInput = class extends BaseInput {
1836
1831
  render() {
@@ -4378,7 +4373,8 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
4378
4373
  return !fieldState.error && value !== void 0 && value !== "";
4379
4374
  });
4380
4375
  const [showPassword, setShowPassword] = React3.useState(false);
4381
- const isPasswordField = input.keyboardType === "password";
4376
+ const isPasswordField = input.keyboardType === "password" /* PASSWORD */;
4377
+ const isNumberField = input.keyboardType === "number" /* NUMBER */;
4382
4378
  const showInputGroupAddons = iconsRight.length > 0 || textRight || autoValidate || infoTooltip || isPasswordField;
4383
4379
  const formField = /* @__PURE__ */ jsxRuntime.jsx(
4384
4380
  FormField,
@@ -4400,8 +4396,18 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
4400
4396
  {
4401
4397
  placeholder: input.placeHolder,
4402
4398
  disabled: input.disabled || isSubmitting,
4403
- ...field,
4404
- type: isPasswordField && !showPassword ? "password" : "text"
4399
+ onBlur: field.onBlur,
4400
+ name: field.name,
4401
+ ref: field.ref,
4402
+ type: isPasswordField && !showPassword ? "password" : isNumberField ? "number" : "text",
4403
+ value: field.value ?? "",
4404
+ onChange: (e) => {
4405
+ let value = e.target.value;
4406
+ if (isNumberField) {
4407
+ value = e.target.value === "" ? "" : Number(e.target.value);
4408
+ }
4409
+ field.onChange(value);
4410
+ }
4405
4411
  }
4406
4412
  ),
4407
4413
  showInputGroupAddons && /* @__PURE__ */ jsxRuntime.jsxs(InputGroupAddon, { align: "inline-end", children: [
@@ -5629,8 +5635,8 @@ var DynamicForm = ({
5629
5635
  withErrorsAlert = true,
5630
5636
  errorAlertPosition = "up",
5631
5637
  withCard = false,
5632
- // btnType = 'submit',
5633
5638
  submitBtnClass = "",
5639
+ listBtnConfig = [],
5634
5640
  submitBtnLabel = "Guardar"
5635
5641
  }) => {
5636
5642
  const [isPending, startTransition] = React3.useTransition();
@@ -5646,24 +5652,25 @@ var DynamicForm = ({
5646
5652
  }, [initialValues, form]);
5647
5653
  const handleSubmit = (data) => {
5648
5654
  if (readOnly) return;
5649
- try {
5650
- startTransition(async () => {
5651
- const resp = { data, form };
5652
- onSubmit?.(resp);
5653
- });
5654
- } catch (error) {
5655
- console.error("Ocurri\xF3 un error al enviar el formulario.", error);
5656
- }
5655
+ startTransition(() => {
5656
+ const resp = { data, form };
5657
+ onSubmit?.(resp);
5658
+ });
5659
+ };
5660
+ const handleClick = async () => {
5661
+ if (!onClick) return;
5662
+ const isValid2 = await form.trigger();
5663
+ if (!isValid2) return;
5664
+ const data = form.getValues();
5665
+ const resp = { data, form };
5666
+ onClick(resp);
5657
5667
  };
5658
5668
  const formContent = /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
5659
5669
  showFormHeader && /* @__PURE__ */ jsxRuntime.jsxs(CardTitle, { className: "flex flex-row items-center gap-2 p-2 border-b", children: [
5660
5670
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-row items-center gap-2 w-full", children: [
5661
5671
  showIcon && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pencil, { className: "h-5 w-5" }),
5662
5672
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
5663
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-xl", children: [
5664
- formTitle,
5665
- " "
5666
- ] }),
5673
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xl", children: formTitle }),
5667
5674
  formSubTitle && /* @__PURE__ */ jsxRuntime.jsx(CardDescription, { children: formSubTitle })
5668
5675
  ] })
5669
5676
  ] }),
@@ -5680,13 +5687,38 @@ var DynamicForm = ({
5680
5687
  /* @__PURE__ */ jsxRuntime.jsx(FormFieldsGrid, { fields, form, readOnly }),
5681
5688
  children && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row items-center gap-2 w-full h-full", children })
5682
5689
  ] }),
5683
- !readOnly && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row gap-2 justify-end items-end", children: /* @__PURE__ */ jsxRuntime.jsx(Button, { type: onClick ? "button" : "submit", size: "lg", className: submitBtnClass, disabled: isPending, onClick, children: isPending ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5684
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-4 w-4 mr-2 animate-spin" }),
5685
- "Guardando..."
5686
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5687
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Save, { className: "h-4 w-4 mr-2" }),
5688
- submitBtnLabel
5689
- ] }) }) })
5690
+ /* @__PURE__ */ jsxRuntime.jsxs(ButtonGroup, { className: "flex flex-row w-full", children: [
5691
+ listBtnConfig.map((btn, key) => /* @__PURE__ */ jsxRuntime.jsx(
5692
+ Button,
5693
+ {
5694
+ type: btn.btnType,
5695
+ size: "lg",
5696
+ className: submitBtnClass,
5697
+ variant: btn.variant,
5698
+ onClick: btn.onClick,
5699
+ disabled: btn.disabled,
5700
+ children: btn.label
5701
+ },
5702
+ key
5703
+ )),
5704
+ !readOnly && /* @__PURE__ */ jsxRuntime.jsx(
5705
+ Button,
5706
+ {
5707
+ type: onClick ? "button" : "submit",
5708
+ size: "lg",
5709
+ className: submitBtnClass,
5710
+ disabled: isPending,
5711
+ onClick: onClick ? handleClick : void 0,
5712
+ children: isPending ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5713
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-4 w-4 mr-2 animate-spin" }),
5714
+ "Guardando..."
5715
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5716
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Save, { className: "h-4 w-4 mr-2" }),
5717
+ submitBtnLabel
5718
+ ] })
5719
+ }
5720
+ )
5721
+ ] })
5690
5722
  ]
5691
5723
  }
5692
5724
  ) }),