shadcn-zod-formkit 1.29.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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, CheckIcon, XIcon, MinusIcon, CircleIcon, GripVerticalIcon, ChevronUpIcon, SearchIcon, ChevronsUpDown, Check, CalendarIcon, EyeOff, Eye, Upload, Trash2, Plus, Info, GripVertical, Loader2, Save, Pencil, Search, MessageCircleWarning, CircleCheck, CircleX } from 'lucide-react';
1
+ import { ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, CheckIcon, XIcon, MinusIcon, CircleIcon, GripVerticalIcon, ChevronUpIcon, SearchIcon, ChevronsUpDown, Check, CalendarIcon, EyeOff, Eye, Upload, Info, Trash2, Plus, GripVertical, Loader2, Save, Pencil, Search, MessageCircleWarning, CircleCheck, CircleX } from 'lucide-react';
2
2
  import { InfoCircledIcon } from '@radix-ui/react-icons';
3
3
  import { cva } from 'class-variance-authority';
4
4
  import { twMerge } from 'tailwind-merge';
@@ -2184,6 +2184,8 @@ var ColorInput = class extends BaseInput {
2184
2184
  }
2185
2185
  };
2186
2186
  var PRESET_COLORS = [
2187
+ "#800000",
2188
+ // Maroon
2187
2189
  "#ef4444",
2188
2190
  // red
2189
2191
  "#f97316",
@@ -2192,16 +2194,26 @@ var PRESET_COLORS = [
2192
2194
  // yellow
2193
2195
  "#22c55e",
2194
2196
  // green
2197
+ "#00FF00",
2198
+ // lime
2199
+ "#00FFFF",
2200
+ // Aqua
2195
2201
  "#06b6d4",
2196
2202
  // cyan
2197
2203
  "#3b82f6",
2198
2204
  // blue
2199
2205
  "#8b5cf6",
2200
2206
  // purple
2207
+ "#800080",
2208
+ // purple
2209
+ "#FF00FF",
2210
+ // Fuchsia
2201
2211
  "#ec4899",
2202
2212
  // pink
2203
2213
  "#64748b",
2204
2214
  // slate
2215
+ "#808080",
2216
+ // Gray
2205
2217
  "#000000"
2206
2218
  // black
2207
2219
  ];
@@ -4527,6 +4539,111 @@ var FieldFileMultiUpload = ({ input, form, isSubmitting }) => {
4527
4539
  );
4528
4540
  return /* @__PURE__ */ jsx(Fragment, { children: formField });
4529
4541
  };
4542
+ var TextInputGroup = class extends BaseInput {
4543
+ render() {
4544
+ const { input, form, isSubmitting } = this;
4545
+ return /* @__PURE__ */ jsx(FieldTextGroup, { input, form, isSubmitting });
4546
+ }
4547
+ };
4548
+ var FieldTextGroup = ({ form, input, isSubmitting }) => {
4549
+ const [isValid2, setIsValid] = useState(isValidField(input, form));
4550
+ const formField = /* @__PURE__ */ jsx(
4551
+ FormField,
4552
+ {
4553
+ control: form.control,
4554
+ name: input.name,
4555
+ render: ({ field }) => {
4556
+ setIsValid(isValidField(input, form));
4557
+ return /* @__PURE__ */ jsxs(FormItem, { className: input.className, children: [
4558
+ /* @__PURE__ */ jsx(FormLabel, { children: /* @__PURE__ */ jsx("b", { children: input.label }) }),
4559
+ /* @__PURE__ */ jsx(FormControl, { className: "shadow-lg", children: CustomInputGroup({
4560
+ input,
4561
+ isSubmitting,
4562
+ field,
4563
+ form,
4564
+ isValid: isValid2
4565
+ }) }),
4566
+ input.description && /* @__PURE__ */ jsx(FormDescription, { children: input.description }),
4567
+ /* @__PURE__ */ jsx(FormMessage, {})
4568
+ ] });
4569
+ }
4570
+ },
4571
+ input.name
4572
+ );
4573
+ return /* @__PURE__ */ jsx(Fragment, { children: formField });
4574
+ };
4575
+ var CustomInputGroup = ({
4576
+ value,
4577
+ input,
4578
+ field,
4579
+ form,
4580
+ isSubmitting,
4581
+ onChange,
4582
+ isValid: isValid2
4583
+ }) => {
4584
+ const groupConfig = input.inputGroupConfig;
4585
+ const infoTooltip = input?.infoTooltip;
4586
+ const autoValidate = groupConfig?.autoValidIcons ?? input.zodType ? true : false;
4587
+ const iconValidState = /* @__PURE__ */ jsx(CircleCheck, { style: { color: "#00bf3e" } });
4588
+ const iconInvalidState = /* @__PURE__ */ jsx(CircleX, { style: { color: "#ff8080" } });
4589
+ const iconLoadingState = /* @__PURE__ */ jsx(Loader2, { className: "animate-spin", style: { color: "#1e90ff" } });
4590
+ const iconsRight = groupConfig?.iconsRight ?? [];
4591
+ const iconsLeft = groupConfig?.iconsLeft ?? [];
4592
+ const textLeft = groupConfig?.textLeft;
4593
+ const textRight = groupConfig?.textRight;
4594
+ const [showPassword, setShowPassword] = useState(false);
4595
+ const isPasswordField = input.keyboardType === "password" /* PASSWORD */;
4596
+ const isNumberField = input.keyboardType === "number" /* NUMBER */;
4597
+ const showInputGroupAddons = iconsRight.length > 0 || textRight || autoValidate || infoTooltip || isPasswordField;
4598
+ return /* @__PURE__ */ jsxs(InputGroup, { children: [
4599
+ (iconsLeft.length > 0 || textLeft) && /* @__PURE__ */ jsxs(InputGroupAddon, { children: [
4600
+ textLeft && /* @__PURE__ */ jsx(InputGroupText, { children: textLeft }),
4601
+ iconsLeft.map((IconComponent, index) => /* @__PURE__ */ jsx(IconComponent, { size: 20 }, index))
4602
+ ] }),
4603
+ /* @__PURE__ */ jsx(
4604
+ InputGroupInput,
4605
+ {
4606
+ placeholder: input.placeHolder,
4607
+ disabled: input.disabled || isSubmitting,
4608
+ onBlur: field?.onBlur,
4609
+ name: field?.name,
4610
+ ref: field?.ref,
4611
+ type: isPasswordField && !showPassword ? "password" : isNumberField ? "number" : "text",
4612
+ value: field?.value ?? value ?? "",
4613
+ onChange: (e) => {
4614
+ if (onChange) {
4615
+ onChange(e);
4616
+ }
4617
+ let value2 = e.target.value;
4618
+ if (isNumberField) {
4619
+ value2 = e.target.value === "" ? "" : Number(e.target.value);
4620
+ }
4621
+ field?.onChange(value2);
4622
+ isValidField(input, form);
4623
+ handleOnChage(value2, input, field);
4624
+ }
4625
+ }
4626
+ ),
4627
+ showInputGroupAddons && /* @__PURE__ */ jsxs(InputGroupAddon, { align: "inline-end", children: [
4628
+ infoTooltip && /* @__PURE__ */ jsxs(Tooltip, { children: [
4629
+ /* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(Info, { size: 20 }) }),
4630
+ /* @__PURE__ */ jsx(TooltipContent, { children: /* @__PURE__ */ jsx("p", { children: infoTooltip }) })
4631
+ ] }),
4632
+ textRight && /* @__PURE__ */ jsx(InputGroupText, { children: textRight }),
4633
+ iconsRight.map((IconComponent, index) => /* @__PURE__ */ jsx(IconComponent, { size: 20 }, index)),
4634
+ isPasswordField && /* @__PURE__ */ jsx(
4635
+ "button",
4636
+ {
4637
+ type: "button",
4638
+ onClick: () => setShowPassword(!showPassword),
4639
+ className: "p-1",
4640
+ children: showPassword ? /* @__PURE__ */ jsx(EyeOff, { size: 20 }) : /* @__PURE__ */ jsx(Eye, { size: 20 })
4641
+ }
4642
+ ),
4643
+ autoValidate && /* @__PURE__ */ jsx("div", { children: isSubmitting ? iconLoadingState : isValid2 ? iconValidState : iconInvalidState })
4644
+ ] })
4645
+ ] });
4646
+ };
4530
4647
  var KeyValueListInput = class extends BaseInput {
4531
4648
  render() {
4532
4649
  const { input, form, isSubmitting } = this;
@@ -4583,27 +4700,31 @@ var FieldKeyValueList = ({ form, input, isSubmitting }) => {
4583
4700
  children: [
4584
4701
  /* @__PURE__ */ jsxs(ButtonGroup, { className: "w-full", children: [
4585
4702
  /* @__PURE__ */ jsx(ButtonGroupText, { asChild: true, children: /* @__PURE__ */ jsx(Label$1, { htmlFor: "key", children: "Key" }) }),
4586
- /* @__PURE__ */ jsx(InputGroup, { children: /* @__PURE__ */ jsx(
4587
- InputGroupInput,
4703
+ /* @__PURE__ */ jsx(
4704
+ CustomInputGroup,
4588
4705
  {
4589
- placeholder: "Key",
4706
+ autoValidate: true,
4590
4707
  value: pair.key,
4591
- disabled: isSubmitting,
4708
+ input,
4709
+ isValid: pair.key.trim() != "",
4710
+ isSubmitting,
4592
4711
  onChange: (e) => handleChange(index, "key", e.target.value),
4593
- className: "flex-1"
4712
+ form
4594
4713
  }
4595
- ) })
4714
+ )
4596
4715
  ] }),
4597
4716
  /* @__PURE__ */ jsxs(ButtonGroup, { className: "w-full", children: [
4598
4717
  /* @__PURE__ */ jsx(ButtonGroupText, { asChild: true, children: /* @__PURE__ */ jsx(Label$1, { htmlFor: "value", children: "Value" }) }),
4599
4718
  /* @__PURE__ */ jsx(InputGroup, { children: /* @__PURE__ */ jsx(
4600
- InputGroupInput,
4719
+ CustomInputGroup,
4601
4720
  {
4602
- placeholder: "Value",
4721
+ autoValidate: true,
4603
4722
  value: pair.value,
4604
- disabled: isSubmitting,
4723
+ input,
4724
+ isValid: pair.value.trim() != "",
4725
+ isSubmitting,
4605
4726
  onChange: (e) => handleChange(index, "value", e.target.value),
4606
- className: "flex-1"
4727
+ form
4607
4728
  }
4608
4729
  ) })
4609
4730
  ] }),
@@ -4736,111 +4857,6 @@ var FieldMultiSelect = ({ form, input, isSubmitting }) => {
4736
4857
  input.name
4737
4858
  );
4738
4859
  };
4739
- var TextInputGroup = class extends BaseInput {
4740
- render() {
4741
- const { input, form, isSubmitting } = this;
4742
- return /* @__PURE__ */ jsx(FieldTextGroup, { input, form, isSubmitting });
4743
- }
4744
- };
4745
- var FieldTextGroup = ({ form, input, isSubmitting }) => {
4746
- const [isValid2, setIsValid] = useState(isValidField(input, form));
4747
- const formField = /* @__PURE__ */ jsx(
4748
- FormField,
4749
- {
4750
- control: form.control,
4751
- name: input.name,
4752
- render: ({ field }) => {
4753
- setIsValid(isValidField(input, form));
4754
- return /* @__PURE__ */ jsxs(FormItem, { className: input.className, children: [
4755
- /* @__PURE__ */ jsx(FormLabel, { children: /* @__PURE__ */ jsx("b", { children: input.label }) }),
4756
- /* @__PURE__ */ jsx(FormControl, { className: "shadow-lg", children: CustomInputGroup({
4757
- input,
4758
- isSubmitting,
4759
- field,
4760
- form,
4761
- isValid: isValid2
4762
- }) }),
4763
- input.description && /* @__PURE__ */ jsx(FormDescription, { children: input.description }),
4764
- /* @__PURE__ */ jsx(FormMessage, {})
4765
- ] });
4766
- }
4767
- },
4768
- input.name
4769
- );
4770
- return /* @__PURE__ */ jsx(Fragment, { children: formField });
4771
- };
4772
- var CustomInputGroup = ({
4773
- value,
4774
- input,
4775
- field,
4776
- form,
4777
- isSubmitting,
4778
- onChange,
4779
- isValid: isValid2
4780
- }) => {
4781
- const groupConfig = input.inputGroupConfig;
4782
- const infoTooltip = input?.infoTooltip;
4783
- const autoValidate = groupConfig?.autoValidIcons ?? input.zodType ? true : false;
4784
- const iconValidState = /* @__PURE__ */ jsx(CircleCheck, { style: { color: "#00bf3e" } });
4785
- const iconInvalidState = /* @__PURE__ */ jsx(CircleX, { style: { color: "#ff8080" } });
4786
- const iconLoadingState = /* @__PURE__ */ jsx(Loader2, { className: "animate-spin", style: { color: "#1e90ff" } });
4787
- const iconsRight = groupConfig?.iconsRight ?? [];
4788
- const iconsLeft = groupConfig?.iconsLeft ?? [];
4789
- const textLeft = groupConfig?.textLeft;
4790
- const textRight = groupConfig?.textRight;
4791
- const [showPassword, setShowPassword] = useState(false);
4792
- const isPasswordField = input.keyboardType === "password" /* PASSWORD */;
4793
- const isNumberField = input.keyboardType === "number" /* NUMBER */;
4794
- const showInputGroupAddons = iconsRight.length > 0 || textRight || autoValidate || infoTooltip || isPasswordField;
4795
- return /* @__PURE__ */ jsxs(InputGroup, { children: [
4796
- (iconsLeft.length > 0 || textLeft) && /* @__PURE__ */ jsxs(InputGroupAddon, { children: [
4797
- textLeft && /* @__PURE__ */ jsx(InputGroupText, { children: textLeft }),
4798
- iconsLeft.map((IconComponent, index) => /* @__PURE__ */ jsx(IconComponent, { size: 20 }, index))
4799
- ] }),
4800
- /* @__PURE__ */ jsx(
4801
- InputGroupInput,
4802
- {
4803
- placeholder: input.placeHolder,
4804
- disabled: input.disabled || isSubmitting,
4805
- onBlur: field?.onBlur,
4806
- name: field?.name,
4807
- ref: field?.ref,
4808
- type: isPasswordField && !showPassword ? "password" : isNumberField ? "number" : "text",
4809
- value: field?.value ?? value ?? "",
4810
- onChange: (e) => {
4811
- if (onChange) {
4812
- onChange(e);
4813
- }
4814
- let value2 = e.target.value;
4815
- if (isNumberField) {
4816
- value2 = e.target.value === "" ? "" : Number(e.target.value);
4817
- }
4818
- field?.onChange(value2);
4819
- isValidField(input, form);
4820
- handleOnChage(value2, input, field);
4821
- }
4822
- }
4823
- ),
4824
- showInputGroupAddons && /* @__PURE__ */ jsxs(InputGroupAddon, { align: "inline-end", children: [
4825
- infoTooltip && /* @__PURE__ */ jsxs(Tooltip, { children: [
4826
- /* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(Info, { size: 20 }) }),
4827
- /* @__PURE__ */ jsx(TooltipContent, { children: /* @__PURE__ */ jsx("p", { children: infoTooltip }) })
4828
- ] }),
4829
- textRight && /* @__PURE__ */ jsx(InputGroupText, { children: textRight }),
4830
- iconsRight.map((IconComponent, index) => /* @__PURE__ */ jsx(IconComponent, { size: 20 }, index)),
4831
- isPasswordField && /* @__PURE__ */ jsx(
4832
- "button",
4833
- {
4834
- type: "button",
4835
- onClick: () => setShowPassword(!showPassword),
4836
- className: "p-1",
4837
- children: showPassword ? /* @__PURE__ */ jsx(EyeOff, { size: 20 }) : /* @__PURE__ */ jsx(Eye, { size: 20 })
4838
- }
4839
- ),
4840
- autoValidate && /* @__PURE__ */ jsx("div", { children: isSubmitting ? iconLoadingState : isValid2 ? iconValidState : iconInvalidState })
4841
- ] })
4842
- ] });
4843
- };
4844
4860
  var NumberInput = class extends BaseInput {
4845
4861
  render() {
4846
4862
  const { input, form, isSubmitting } = this;
@@ -4953,6 +4969,10 @@ var FieldRepeater = ({ form, input, isSubmitting }) => {
4953
4969
  });
4954
4970
  const canAdd = !input.maxItems || fields.length < input.maxItems;
4955
4971
  const canRemove = fields.length > (input.minItems ?? 0);
4972
+ const [isValid2, setIsValid] = useState(isValidField(input, form));
4973
+ useEffect(() => {
4974
+ setIsValid(isValidField(input, form));
4975
+ }, [input]);
4956
4976
  return /* @__PURE__ */ jsx(
4957
4977
  FormField,
4958
4978
  {
@@ -4972,7 +4992,7 @@ var FieldRepeater = ({ form, input, isSubmitting }) => {
4972
4992
  return /* @__PURE__ */ jsx(
4973
4993
  "div",
4974
4994
  {
4975
- className: `grid gap-3 grid-cols-${cols}`,
4995
+ className: `grid gap-1 grid-cols-${cols}`,
4976
4996
  children: group.map((subField) => /* @__PURE__ */ jsx(
4977
4997
  FormField,
4978
4998
  {
@@ -4981,11 +5001,14 @@ var FieldRepeater = ({ form, input, isSubmitting }) => {
4981
5001
  render: ({ field, fieldState }) => /* @__PURE__ */ jsxs(FormItem, { className: "flex-1", children: [
4982
5002
  /* @__PURE__ */ jsx(FormLabel, { children: subField.label }),
4983
5003
  /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(
4984
- Input,
5004
+ CustomInputGroup,
4985
5005
  {
4986
- placeholder: subField.placeHolder,
4987
- disabled: subField.disabled || isSubmitting,
4988
- ...field
5006
+ autoValidate: true,
5007
+ value: field.value,
5008
+ input: subField,
5009
+ isValid: isValid2,
5010
+ field,
5011
+ form
4989
5012
  }
4990
5013
  ) }),
4991
5014
  /* @__PURE__ */ jsx(FormMessage, { children: fieldState.error?.message })