shadcn-zod-formkit 1.18.1 → 1.20.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
@@ -1806,31 +1806,29 @@ function ButtonGroup({
1806
1806
  var ButtonGroupInput = class extends BaseInput {
1807
1807
  render() {
1808
1808
  const { input, form, isSubmitting } = this;
1809
- return /* @__PURE__ */ jsxRuntime.jsx(FieldButtonGroup, { input, form, isSubmitting });
1809
+ const className = input.className;
1810
+ return /* @__PURE__ */ jsxRuntime.jsx(FieldButtonGroup, { input, form, isSubmitting, className });
1810
1811
  }
1811
1812
  };
1812
- var FieldButtonGroup = ({ input, form, isSubmitting }) => {
1813
+ var FieldButtonGroup = ({ input, form, isSubmitting, className = "w-full flex-1" }) => {
1813
1814
  const options = (input.listConfig?.list ?? []).filter((option) => "name" in option);
1814
1815
  const handleSelect = (value) => {
1815
1816
  form.setValue(input.name, value, { shouldValidate: true });
1817
+ if (input.listConfig?.onOptionChange) input.listConfig.onOptionChange(value);
1816
1818
  };
1817
1819
  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
- );
1820
+ return /* @__PURE__ */ jsxRuntime.jsx(ButtonGroup, { className: "flex flex-row w-full", children: options.map((option) => /* @__PURE__ */ jsxRuntime.jsx(
1821
+ Button,
1822
+ {
1823
+ type: "button",
1824
+ className,
1825
+ variant: selectedValue === option.value ? "default" : "outline",
1826
+ onClick: () => handleSelect(option.value),
1827
+ disabled: isSubmitting,
1828
+ children: option.label ?? option.name
1829
+ },
1830
+ option.value
1831
+ )) });
1834
1832
  };
1835
1833
  var CheckListInput = class extends BaseInput {
1836
1834
  render() {
@@ -4020,7 +4018,6 @@ var FieldFile = ({ form, input, isSubmitting }) => {
4020
4018
  if (file) {
4021
4019
  const objectUrl = URL.createObjectURL(file);
4022
4020
  setPreview(objectUrl);
4023
- console.log("\u{1F680} ~ handleFileChange ~ objectUrl:", objectUrl);
4024
4021
  } else {
4025
4022
  setPreview(null);
4026
4023
  }
@@ -4378,7 +4375,8 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
4378
4375
  return !fieldState.error && value !== void 0 && value !== "";
4379
4376
  });
4380
4377
  const [showPassword, setShowPassword] = React3.useState(false);
4381
- const isPasswordField = input.keyboardType === "password";
4378
+ const isPasswordField = input.keyboardType === "password" /* PASSWORD */;
4379
+ const isNumberField = input.keyboardType === "number" /* NUMBER */;
4382
4380
  const showInputGroupAddons = iconsRight.length > 0 || textRight || autoValidate || infoTooltip || isPasswordField;
4383
4381
  const formField = /* @__PURE__ */ jsxRuntime.jsx(
4384
4382
  FormField,
@@ -4400,8 +4398,18 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
4400
4398
  {
4401
4399
  placeholder: input.placeHolder,
4402
4400
  disabled: input.disabled || isSubmitting,
4403
- ...field,
4404
- type: isPasswordField && !showPassword ? "password" : "text"
4401
+ onBlur: field.onBlur,
4402
+ name: field.name,
4403
+ ref: field.ref,
4404
+ type: isPasswordField && !showPassword ? "password" : isNumberField ? "number" : "text",
4405
+ value: field.value ?? "",
4406
+ onChange: (e) => {
4407
+ let value = e.target.value;
4408
+ if (isNumberField) {
4409
+ value = e.target.value === "" ? "" : Number(e.target.value);
4410
+ }
4411
+ field.onChange(value);
4412
+ }
4405
4413
  }
4406
4414
  ),
4407
4415
  showInputGroupAddons && /* @__PURE__ */ jsxRuntime.jsxs(InputGroupAddon, { align: "inline-end", children: [
@@ -5630,6 +5638,7 @@ var DynamicForm = ({
5630
5638
  errorAlertPosition = "up",
5631
5639
  withCard = false,
5632
5640
  submitBtnClass = "",
5641
+ listBtnConfig = [],
5633
5642
  submitBtnLabel = "Guardar"
5634
5643
  }) => {
5635
5644
  const [isPending, startTransition] = React3.useTransition();
@@ -5680,23 +5689,38 @@ var DynamicForm = ({
5680
5689
  /* @__PURE__ */ jsxRuntime.jsx(FormFieldsGrid, { fields, form, readOnly }),
5681
5690
  children && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row items-center gap-2 w-full h-full", children })
5682
5691
  ] }),
5683
- !readOnly && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row gap-2 justify-end items-end", children: /* @__PURE__ */ jsxRuntime.jsx(
5684
- Button,
5685
- {
5686
- type: onClick ? "button" : "submit",
5687
- size: "lg",
5688
- className: submitBtnClass,
5689
- disabled: isPending,
5690
- onClick: onClick ? handleClick : void 0,
5691
- children: isPending ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5692
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-4 w-4 mr-2 animate-spin" }),
5693
- "Guardando..."
5694
- ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5695
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Save, { className: "h-4 w-4 mr-2" }),
5696
- submitBtnLabel
5697
- ] })
5698
- }
5699
- ) })
5692
+ /* @__PURE__ */ jsxRuntime.jsxs(ButtonGroup, { className: "flex flex-row w-full", children: [
5693
+ listBtnConfig.map((btn, key) => /* @__PURE__ */ jsxRuntime.jsx(
5694
+ Button,
5695
+ {
5696
+ type: btn.btnType,
5697
+ size: "lg",
5698
+ className: submitBtnClass,
5699
+ variant: btn.variant,
5700
+ onClick: btn.onClick,
5701
+ disabled: btn.disabled,
5702
+ children: btn.label
5703
+ },
5704
+ key
5705
+ )),
5706
+ !readOnly && /* @__PURE__ */ jsxRuntime.jsx(
5707
+ Button,
5708
+ {
5709
+ type: onClick ? "button" : "submit",
5710
+ size: "lg",
5711
+ className: submitBtnClass,
5712
+ disabled: isPending,
5713
+ onClick: onClick ? handleClick : void 0,
5714
+ children: isPending ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5715
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-4 w-4 mr-2 animate-spin" }),
5716
+ "Guardando..."
5717
+ ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5718
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Save, { className: "h-4 w-4 mr-2" }),
5719
+ submitBtnLabel
5720
+ ] })
5721
+ }
5722
+ )
5723
+ ] })
5700
5724
  ]
5701
5725
  }
5702
5726
  ) }),