shadcn-zod-formkit 1.28.0 → 1.29.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
@@ -4780,21 +4780,7 @@ var TextInputGroup = class extends BaseInput {
4780
4780
  }
4781
4781
  };
4782
4782
  var FieldTextGroup = ({ form, input, isSubmitting }) => {
4783
- const groupConfig = input.inputGroupConfig;
4784
- const infoTooltip = input?.infoTooltip;
4785
- const autoValidate = groupConfig?.autoValidIcons ?? input.zodType ? true : false;
4786
- const iconValidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleCheck, { style: { color: "#00bf3e" } });
4787
- const iconInvalidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleX, { style: { color: "#ff8080" } });
4788
- const iconLoadingState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "animate-spin", style: { color: "#1e90ff" } });
4789
- const iconsRight = groupConfig?.iconsRight ?? [];
4790
- const iconsLeft = groupConfig?.iconsLeft ?? [];
4791
- const textLeft = groupConfig?.textLeft;
4792
- const textRight = groupConfig?.textRight;
4793
4783
  const [isValid2, setIsValid] = React3.useState(isValidField(input, form));
4794
- const [showPassword, setShowPassword] = React3.useState(false);
4795
- const isPasswordField = input.keyboardType === "password" /* PASSWORD */;
4796
- const isNumberField = input.keyboardType === "number" /* NUMBER */;
4797
- const showInputGroupAddons = iconsRight.length > 0 || textRight || autoValidate || infoTooltip || isPasswordField;
4798
4784
  const formField = /* @__PURE__ */ jsxRuntime.jsx(
4799
4785
  FormField,
4800
4786
  {
@@ -4804,51 +4790,13 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
4804
4790
  setIsValid(isValidField(input, form));
4805
4791
  return /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: input.className, children: [
4806
4792
  /* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
4807
- /* @__PURE__ */ jsxRuntime.jsx(FormControl, { className: "shadow-lg", children: /* @__PURE__ */ jsxRuntime.jsxs(InputGroup, { children: [
4808
- (iconsLeft.length > 0 || textLeft) && /* @__PURE__ */ jsxRuntime.jsxs(InputGroupAddon, { children: [
4809
- textLeft && /* @__PURE__ */ jsxRuntime.jsx(InputGroupText, { children: textLeft }),
4810
- iconsLeft.map((IconComponent, index) => /* @__PURE__ */ jsxRuntime.jsx(IconComponent, { size: 20 }, index))
4811
- ] }),
4812
- /* @__PURE__ */ jsxRuntime.jsx(
4813
- InputGroupInput,
4814
- {
4815
- placeholder: input.placeHolder,
4816
- disabled: input.disabled || isSubmitting,
4817
- onBlur: field.onBlur,
4818
- name: field.name,
4819
- ref: field.ref,
4820
- type: isPasswordField && !showPassword ? "password" : isNumberField ? "number" : "text",
4821
- value: field.value ?? "",
4822
- onChange: (e) => {
4823
- let value = e.target.value;
4824
- if (isNumberField) {
4825
- value = e.target.value === "" ? "" : Number(e.target.value);
4826
- }
4827
- field.onChange(value);
4828
- isValidField(input, form);
4829
- handleOnChage(value, input, field);
4830
- }
4831
- }
4832
- ),
4833
- showInputGroupAddons && /* @__PURE__ */ jsxRuntime.jsxs(InputGroupAddon, { align: "inline-end", children: [
4834
- infoTooltip && /* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { children: [
4835
- /* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Info, { size: 20 }) }),
4836
- /* @__PURE__ */ jsxRuntime.jsx(TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: infoTooltip }) })
4837
- ] }),
4838
- textRight && /* @__PURE__ */ jsxRuntime.jsx(InputGroupText, { children: textRight }),
4839
- iconsRight.map((IconComponent, index) => /* @__PURE__ */ jsxRuntime.jsx(IconComponent, { size: 20 }, index)),
4840
- isPasswordField && /* @__PURE__ */ jsxRuntime.jsx(
4841
- "button",
4842
- {
4843
- type: "button",
4844
- onClick: () => setShowPassword(!showPassword),
4845
- className: "p-1",
4846
- children: showPassword ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.EyeOff, { size: 20 }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Eye, { size: 20 })
4847
- }
4848
- ),
4849
- autoValidate && /* @__PURE__ */ jsxRuntime.jsx("div", { children: isSubmitting ? iconLoadingState : isValid2 ? iconValidState : iconInvalidState })
4850
- ] })
4851
- ] }) }),
4793
+ /* @__PURE__ */ jsxRuntime.jsx(FormControl, { className: "shadow-lg", children: CustomInputGroup({
4794
+ input,
4795
+ isSubmitting,
4796
+ field,
4797
+ form,
4798
+ isValid: isValid2
4799
+ }) }),
4852
4800
  input.description && /* @__PURE__ */ jsxRuntime.jsx(FormDescription, { children: input.description }),
4853
4801
  /* @__PURE__ */ jsxRuntime.jsx(FormMessage, {})
4854
4802
  ] });
@@ -4858,6 +4806,78 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
4858
4806
  );
4859
4807
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: formField });
4860
4808
  };
4809
+ var CustomInputGroup = ({
4810
+ value,
4811
+ input,
4812
+ field,
4813
+ form,
4814
+ isSubmitting,
4815
+ onChange,
4816
+ isValid: isValid2
4817
+ }) => {
4818
+ const groupConfig = input.inputGroupConfig;
4819
+ const infoTooltip = input?.infoTooltip;
4820
+ const autoValidate = groupConfig?.autoValidIcons ?? input.zodType ? true : false;
4821
+ const iconValidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleCheck, { style: { color: "#00bf3e" } });
4822
+ const iconInvalidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleX, { style: { color: "#ff8080" } });
4823
+ const iconLoadingState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "animate-spin", style: { color: "#1e90ff" } });
4824
+ const iconsRight = groupConfig?.iconsRight ?? [];
4825
+ const iconsLeft = groupConfig?.iconsLeft ?? [];
4826
+ const textLeft = groupConfig?.textLeft;
4827
+ const textRight = groupConfig?.textRight;
4828
+ const [showPassword, setShowPassword] = React3.useState(false);
4829
+ const isPasswordField = input.keyboardType === "password" /* PASSWORD */;
4830
+ const isNumberField = input.keyboardType === "number" /* NUMBER */;
4831
+ const showInputGroupAddons = iconsRight.length > 0 || textRight || autoValidate || infoTooltip || isPasswordField;
4832
+ return /* @__PURE__ */ jsxRuntime.jsxs(InputGroup, { children: [
4833
+ (iconsLeft.length > 0 || textLeft) && /* @__PURE__ */ jsxRuntime.jsxs(InputGroupAddon, { children: [
4834
+ textLeft && /* @__PURE__ */ jsxRuntime.jsx(InputGroupText, { children: textLeft }),
4835
+ iconsLeft.map((IconComponent, index) => /* @__PURE__ */ jsxRuntime.jsx(IconComponent, { size: 20 }, index))
4836
+ ] }),
4837
+ /* @__PURE__ */ jsxRuntime.jsx(
4838
+ InputGroupInput,
4839
+ {
4840
+ placeholder: input.placeHolder,
4841
+ disabled: input.disabled || isSubmitting,
4842
+ onBlur: field?.onBlur,
4843
+ name: field?.name,
4844
+ ref: field?.ref,
4845
+ type: isPasswordField && !showPassword ? "password" : isNumberField ? "number" : "text",
4846
+ value: field?.value ?? value ?? "",
4847
+ onChange: (e) => {
4848
+ if (onChange) {
4849
+ onChange(e);
4850
+ }
4851
+ let value2 = e.target.value;
4852
+ if (isNumberField) {
4853
+ value2 = e.target.value === "" ? "" : Number(e.target.value);
4854
+ }
4855
+ field?.onChange(value2);
4856
+ isValidField(input, form);
4857
+ handleOnChage(value2, input, field);
4858
+ }
4859
+ }
4860
+ ),
4861
+ showInputGroupAddons && /* @__PURE__ */ jsxRuntime.jsxs(InputGroupAddon, { align: "inline-end", children: [
4862
+ infoTooltip && /* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { children: [
4863
+ /* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Info, { size: 20 }) }),
4864
+ /* @__PURE__ */ jsxRuntime.jsx(TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: infoTooltip }) })
4865
+ ] }),
4866
+ textRight && /* @__PURE__ */ jsxRuntime.jsx(InputGroupText, { children: textRight }),
4867
+ iconsRight.map((IconComponent, index) => /* @__PURE__ */ jsxRuntime.jsx(IconComponent, { size: 20 }, index)),
4868
+ isPasswordField && /* @__PURE__ */ jsxRuntime.jsx(
4869
+ "button",
4870
+ {
4871
+ type: "button",
4872
+ onClick: () => setShowPassword(!showPassword),
4873
+ className: "p-1",
4874
+ children: showPassword ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.EyeOff, { size: 20 }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Eye, { size: 20 })
4875
+ }
4876
+ ),
4877
+ autoValidate && /* @__PURE__ */ jsxRuntime.jsx("div", { children: isSubmitting ? iconLoadingState : isValid2 ? iconValidState : iconInvalidState })
4878
+ ] })
4879
+ ] });
4880
+ };
4861
4881
  var NumberInput = class extends BaseInput {
4862
4882
  render() {
4863
4883
  const { input, form, isSubmitting } = this;
@@ -5607,6 +5627,10 @@ var StringValueListInput = class extends BaseInput {
5607
5627
  var FieldStringValueList = ({ form, input, isSubmitting }) => {
5608
5628
  const fieldName = input.name;
5609
5629
  const withAddBtn = input.withAddBtn ?? false;
5630
+ const [isValid2, setIsValid] = React3.useState(isValidField(input, form));
5631
+ React3.useEffect(() => {
5632
+ setIsValid(isValidField(input, form));
5633
+ }, [input]);
5610
5634
  React3.useEffect(() => {
5611
5635
  const current = form.getValues(fieldName);
5612
5636
  if (!Array.isArray(current)) {
@@ -5634,7 +5658,7 @@ var FieldStringValueList = ({ form, input, isSubmitting }) => {
5634
5658
  {
5635
5659
  control: form.control,
5636
5660
  name: fieldName,
5637
- render: () => {
5661
+ render: (field) => {
5638
5662
  const items = form.watch(fieldName) || [];
5639
5663
  return /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: input.className, children: [
5640
5664
  /* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
@@ -5647,12 +5671,14 @@ var FieldStringValueList = ({ form, input, isSubmitting }) => {
5647
5671
  className: "flex items-center gap-4 py-2",
5648
5672
  children: [
5649
5673
  /* @__PURE__ */ jsxRuntime.jsx(
5650
- Input,
5674
+ CustomInputGroup,
5651
5675
  {
5652
- placeholder: `Item ${index + 1}`,
5676
+ autoValidate: true,
5653
5677
  value,
5654
- disabled: isSubmitting,
5655
- onChange: (e) => handleChange(index, e.target.value)
5678
+ input,
5679
+ isValid: isValid2,
5680
+ onChange: (e) => handleChange(index, e.target.value),
5681
+ form
5656
5682
  }
5657
5683
  ),
5658
5684
  input.isRemovebleOption && /* @__PURE__ */ jsxRuntime.jsx(
@@ -6638,6 +6664,7 @@ exports.CommandSeparator = CommandSeparator;
6638
6664
  exports.CommandShortcut = CommandShortcut;
6639
6665
  exports.CurrencyInput = CurrencyInput;
6640
6666
  exports.CustomAlert = CustomAlert;
6667
+ exports.CustomInputGroup = CustomInputGroup;
6641
6668
  exports.DateInput = DateInput;
6642
6669
  exports.DateTimeInput = DateTimeInput;
6643
6670
  exports.Dialog = Dialog;