shadcn-zod-formkit 1.28.0 → 1.30.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
@@ -2221,6 +2221,8 @@ var ColorInput = class extends BaseInput {
2221
2221
  }
2222
2222
  };
2223
2223
  var PRESET_COLORS = [
2224
+ "#800000",
2225
+ // Maroon
2224
2226
  "#ef4444",
2225
2227
  // red
2226
2228
  "#f97316",
@@ -2229,16 +2231,26 @@ var PRESET_COLORS = [
2229
2231
  // yellow
2230
2232
  "#22c55e",
2231
2233
  // green
2234
+ "#00FF00",
2235
+ // lime
2236
+ "#00FFFF",
2237
+ // Aqua
2232
2238
  "#06b6d4",
2233
2239
  // cyan
2234
2240
  "#3b82f6",
2235
2241
  // blue
2236
2242
  "#8b5cf6",
2237
2243
  // purple
2244
+ "#800080",
2245
+ // purple
2246
+ "#FF00FF",
2247
+ // Fuchsia
2238
2248
  "#ec4899",
2239
2249
  // pink
2240
2250
  "#64748b",
2241
2251
  // slate
2252
+ "#808080",
2253
+ // Gray
2242
2254
  "#000000"
2243
2255
  // black
2244
2256
  ];
@@ -4564,6 +4576,111 @@ var FieldFileMultiUpload = ({ input, form, isSubmitting }) => {
4564
4576
  );
4565
4577
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: formField });
4566
4578
  };
4579
+ var TextInputGroup = class extends BaseInput {
4580
+ render() {
4581
+ const { input, form, isSubmitting } = this;
4582
+ return /* @__PURE__ */ jsxRuntime.jsx(FieldTextGroup, { input, form, isSubmitting });
4583
+ }
4584
+ };
4585
+ var FieldTextGroup = ({ form, input, isSubmitting }) => {
4586
+ const [isValid2, setIsValid] = React3.useState(isValidField(input, form));
4587
+ const formField = /* @__PURE__ */ jsxRuntime.jsx(
4588
+ FormField,
4589
+ {
4590
+ control: form.control,
4591
+ name: input.name,
4592
+ render: ({ field }) => {
4593
+ setIsValid(isValidField(input, form));
4594
+ return /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: input.className, children: [
4595
+ /* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
4596
+ /* @__PURE__ */ jsxRuntime.jsx(FormControl, { className: "shadow-lg", children: CustomInputGroup({
4597
+ input,
4598
+ isSubmitting,
4599
+ field,
4600
+ form,
4601
+ isValid: isValid2
4602
+ }) }),
4603
+ input.description && /* @__PURE__ */ jsxRuntime.jsx(FormDescription, { children: input.description }),
4604
+ /* @__PURE__ */ jsxRuntime.jsx(FormMessage, {})
4605
+ ] });
4606
+ }
4607
+ },
4608
+ input.name
4609
+ );
4610
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: formField });
4611
+ };
4612
+ var CustomInputGroup = ({
4613
+ value,
4614
+ input,
4615
+ field,
4616
+ form,
4617
+ isSubmitting,
4618
+ onChange,
4619
+ isValid: isValid2
4620
+ }) => {
4621
+ const groupConfig = input.inputGroupConfig;
4622
+ const infoTooltip = input?.infoTooltip;
4623
+ const autoValidate = groupConfig?.autoValidIcons ?? input.zodType ? true : false;
4624
+ const iconValidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleCheck, { style: { color: "#00bf3e" } });
4625
+ const iconInvalidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleX, { style: { color: "#ff8080" } });
4626
+ const iconLoadingState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "animate-spin", style: { color: "#1e90ff" } });
4627
+ const iconsRight = groupConfig?.iconsRight ?? [];
4628
+ const iconsLeft = groupConfig?.iconsLeft ?? [];
4629
+ const textLeft = groupConfig?.textLeft;
4630
+ const textRight = groupConfig?.textRight;
4631
+ const [showPassword, setShowPassword] = React3.useState(false);
4632
+ const isPasswordField = input.keyboardType === "password" /* PASSWORD */;
4633
+ const isNumberField = input.keyboardType === "number" /* NUMBER */;
4634
+ const showInputGroupAddons = iconsRight.length > 0 || textRight || autoValidate || infoTooltip || isPasswordField;
4635
+ return /* @__PURE__ */ jsxRuntime.jsxs(InputGroup, { children: [
4636
+ (iconsLeft.length > 0 || textLeft) && /* @__PURE__ */ jsxRuntime.jsxs(InputGroupAddon, { children: [
4637
+ textLeft && /* @__PURE__ */ jsxRuntime.jsx(InputGroupText, { children: textLeft }),
4638
+ iconsLeft.map((IconComponent, index) => /* @__PURE__ */ jsxRuntime.jsx(IconComponent, { size: 20 }, index))
4639
+ ] }),
4640
+ /* @__PURE__ */ jsxRuntime.jsx(
4641
+ InputGroupInput,
4642
+ {
4643
+ placeholder: input.placeHolder,
4644
+ disabled: input.disabled || isSubmitting,
4645
+ onBlur: field?.onBlur,
4646
+ name: field?.name,
4647
+ ref: field?.ref,
4648
+ type: isPasswordField && !showPassword ? "password" : isNumberField ? "number" : "text",
4649
+ value: field?.value ?? value ?? "",
4650
+ onChange: (e) => {
4651
+ if (onChange) {
4652
+ onChange(e);
4653
+ }
4654
+ let value2 = e.target.value;
4655
+ if (isNumberField) {
4656
+ value2 = e.target.value === "" ? "" : Number(e.target.value);
4657
+ }
4658
+ field?.onChange(value2);
4659
+ isValidField(input, form);
4660
+ handleOnChage(value2, input, field);
4661
+ }
4662
+ }
4663
+ ),
4664
+ showInputGroupAddons && /* @__PURE__ */ jsxRuntime.jsxs(InputGroupAddon, { align: "inline-end", children: [
4665
+ infoTooltip && /* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { children: [
4666
+ /* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Info, { size: 20 }) }),
4667
+ /* @__PURE__ */ jsxRuntime.jsx(TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: infoTooltip }) })
4668
+ ] }),
4669
+ textRight && /* @__PURE__ */ jsxRuntime.jsx(InputGroupText, { children: textRight }),
4670
+ iconsRight.map((IconComponent, index) => /* @__PURE__ */ jsxRuntime.jsx(IconComponent, { size: 20 }, index)),
4671
+ isPasswordField && /* @__PURE__ */ jsxRuntime.jsx(
4672
+ "button",
4673
+ {
4674
+ type: "button",
4675
+ onClick: () => setShowPassword(!showPassword),
4676
+ className: "p-1",
4677
+ children: showPassword ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.EyeOff, { size: 20 }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Eye, { size: 20 })
4678
+ }
4679
+ ),
4680
+ autoValidate && /* @__PURE__ */ jsxRuntime.jsx("div", { children: isSubmitting ? iconLoadingState : isValid2 ? iconValidState : iconInvalidState })
4681
+ ] })
4682
+ ] });
4683
+ };
4567
4684
  var KeyValueListInput = class extends BaseInput {
4568
4685
  render() {
4569
4686
  const { input, form, isSubmitting } = this;
@@ -4620,27 +4737,31 @@ var FieldKeyValueList = ({ form, input, isSubmitting }) => {
4620
4737
  children: [
4621
4738
  /* @__PURE__ */ jsxRuntime.jsxs(ButtonGroup, { className: "w-full", children: [
4622
4739
  /* @__PURE__ */ jsxRuntime.jsx(ButtonGroupText, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(LabelPrimitive.Label, { htmlFor: "key", children: "Key" }) }),
4623
- /* @__PURE__ */ jsxRuntime.jsx(InputGroup, { children: /* @__PURE__ */ jsxRuntime.jsx(
4624
- InputGroupInput,
4740
+ /* @__PURE__ */ jsxRuntime.jsx(
4741
+ CustomInputGroup,
4625
4742
  {
4626
- placeholder: "Key",
4743
+ autoValidate: true,
4627
4744
  value: pair.key,
4628
- disabled: isSubmitting,
4745
+ input,
4746
+ isValid: pair.key.trim() != "",
4747
+ isSubmitting,
4629
4748
  onChange: (e) => handleChange(index, "key", e.target.value),
4630
- className: "flex-1"
4749
+ form
4631
4750
  }
4632
- ) })
4751
+ )
4633
4752
  ] }),
4634
4753
  /* @__PURE__ */ jsxRuntime.jsxs(ButtonGroup, { className: "w-full", children: [
4635
4754
  /* @__PURE__ */ jsxRuntime.jsx(ButtonGroupText, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(LabelPrimitive.Label, { htmlFor: "value", children: "Value" }) }),
4636
4755
  /* @__PURE__ */ jsxRuntime.jsx(InputGroup, { children: /* @__PURE__ */ jsxRuntime.jsx(
4637
- InputGroupInput,
4756
+ CustomInputGroup,
4638
4757
  {
4639
- placeholder: "Value",
4758
+ autoValidate: true,
4640
4759
  value: pair.value,
4641
- disabled: isSubmitting,
4760
+ input,
4761
+ isValid: pair.value.trim() != "",
4762
+ isSubmitting,
4642
4763
  onChange: (e) => handleChange(index, "value", e.target.value),
4643
- className: "flex-1"
4764
+ form
4644
4765
  }
4645
4766
  ) })
4646
4767
  ] }),
@@ -4773,91 +4894,6 @@ var FieldMultiSelect = ({ form, input, isSubmitting }) => {
4773
4894
  input.name
4774
4895
  );
4775
4896
  };
4776
- var TextInputGroup = class extends BaseInput {
4777
- render() {
4778
- const { input, form, isSubmitting } = this;
4779
- return /* @__PURE__ */ jsxRuntime.jsx(FieldTextGroup, { input, form, isSubmitting });
4780
- }
4781
- };
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
- 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
- const formField = /* @__PURE__ */ jsxRuntime.jsx(
4799
- FormField,
4800
- {
4801
- control: form.control,
4802
- name: input.name,
4803
- render: ({ field }) => {
4804
- setIsValid(isValidField(input, form));
4805
- return /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: input.className, children: [
4806
- /* @__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
- ] }) }),
4852
- input.description && /* @__PURE__ */ jsxRuntime.jsx(FormDescription, { children: input.description }),
4853
- /* @__PURE__ */ jsxRuntime.jsx(FormMessage, {})
4854
- ] });
4855
- }
4856
- },
4857
- input.name
4858
- );
4859
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: formField });
4860
- };
4861
4897
  var NumberInput = class extends BaseInput {
4862
4898
  render() {
4863
4899
  const { input, form, isSubmitting } = this;
@@ -4970,6 +5006,10 @@ var FieldRepeater = ({ form, input, isSubmitting }) => {
4970
5006
  });
4971
5007
  const canAdd = !input.maxItems || fields.length < input.maxItems;
4972
5008
  const canRemove = fields.length > (input.minItems ?? 0);
5009
+ const [isValid2, setIsValid] = React3.useState(isValidField(input, form));
5010
+ React3.useEffect(() => {
5011
+ setIsValid(isValidField(input, form));
5012
+ }, [input]);
4973
5013
  return /* @__PURE__ */ jsxRuntime.jsx(
4974
5014
  FormField,
4975
5015
  {
@@ -4989,7 +5029,7 @@ var FieldRepeater = ({ form, input, isSubmitting }) => {
4989
5029
  return /* @__PURE__ */ jsxRuntime.jsx(
4990
5030
  "div",
4991
5031
  {
4992
- className: `grid gap-3 grid-cols-${cols}`,
5032
+ className: `grid gap-1 grid-cols-${cols}`,
4993
5033
  children: group.map((subField) => /* @__PURE__ */ jsxRuntime.jsx(
4994
5034
  FormField,
4995
5035
  {
@@ -4998,11 +5038,14 @@ var FieldRepeater = ({ form, input, isSubmitting }) => {
4998
5038
  render: ({ field, fieldState }) => /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: "flex-1", children: [
4999
5039
  /* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: subField.label }),
5000
5040
  /* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(
5001
- Input,
5041
+ CustomInputGroup,
5002
5042
  {
5003
- placeholder: subField.placeHolder,
5004
- disabled: subField.disabled || isSubmitting,
5005
- ...field
5043
+ autoValidate: true,
5044
+ value: field.value,
5045
+ input: subField,
5046
+ isValid: isValid2,
5047
+ field,
5048
+ form
5006
5049
  }
5007
5050
  ) }),
5008
5051
  /* @__PURE__ */ jsxRuntime.jsx(FormMessage, { children: fieldState.error?.message })
@@ -5607,6 +5650,10 @@ var StringValueListInput = class extends BaseInput {
5607
5650
  var FieldStringValueList = ({ form, input, isSubmitting }) => {
5608
5651
  const fieldName = input.name;
5609
5652
  const withAddBtn = input.withAddBtn ?? false;
5653
+ const [isValid2, setIsValid] = React3.useState(isValidField(input, form));
5654
+ React3.useEffect(() => {
5655
+ setIsValid(isValidField(input, form));
5656
+ }, [input]);
5610
5657
  React3.useEffect(() => {
5611
5658
  const current = form.getValues(fieldName);
5612
5659
  if (!Array.isArray(current)) {
@@ -5634,7 +5681,7 @@ var FieldStringValueList = ({ form, input, isSubmitting }) => {
5634
5681
  {
5635
5682
  control: form.control,
5636
5683
  name: fieldName,
5637
- render: () => {
5684
+ render: (field) => {
5638
5685
  const items = form.watch(fieldName) || [];
5639
5686
  return /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: input.className, children: [
5640
5687
  /* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
@@ -5647,12 +5694,14 @@ var FieldStringValueList = ({ form, input, isSubmitting }) => {
5647
5694
  className: "flex items-center gap-4 py-2",
5648
5695
  children: [
5649
5696
  /* @__PURE__ */ jsxRuntime.jsx(
5650
- Input,
5697
+ CustomInputGroup,
5651
5698
  {
5652
- placeholder: `Item ${index + 1}`,
5699
+ autoValidate: true,
5653
5700
  value,
5654
- disabled: isSubmitting,
5655
- onChange: (e) => handleChange(index, e.target.value)
5701
+ input,
5702
+ isValid: isValid2,
5703
+ onChange: (e) => handleChange(index, e.target.value),
5704
+ form
5656
5705
  }
5657
5706
  ),
5658
5707
  input.isRemovebleOption && /* @__PURE__ */ jsxRuntime.jsx(
@@ -6638,6 +6687,7 @@ exports.CommandSeparator = CommandSeparator;
6638
6687
  exports.CommandShortcut = CommandShortcut;
6639
6688
  exports.CurrencyInput = CurrencyInput;
6640
6689
  exports.CustomAlert = CustomAlert;
6690
+ exports.CustomInputGroup = CustomInputGroup;
6641
6691
  exports.DateInput = DateInput;
6642
6692
  exports.DateTimeInput = DateTimeInput;
6643
6693
  exports.Dialog = Dialog;