shadcn-zod-formkit 1.25.0 → 1.26.1

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,11 +1,11 @@
1
- import { ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, CheckIcon, XIcon, MinusIcon, GripVerticalIcon, ChevronUpIcon, CalendarIcon, EyeOff, Eye, Loader2, Save, Pencil, Plus, MessageCircleWarning, Info, CircleCheck, CircleX, Trash2, ChevronsUpDown, Check, Upload, GripVertical, SearchIcon, CircleIcon } from 'lucide-react';
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';
2
2
  import { InfoCircledIcon } from '@radix-ui/react-icons';
3
3
  import { cva } from 'class-variance-authority';
4
4
  import { twMerge } from 'tailwind-merge';
5
5
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
6
6
  import * as React3 from 'react';
7
- import React3__default, { useState, useEffect, useTransition, useMemo, useRef } from 'react';
8
- import { FormProvider, Controller, useFormContext, useFormState, useForm, useFieldArray } from 'react-hook-form';
7
+ import React3__default, { useMemo, useState, useEffect, useRef, useTransition } from 'react';
8
+ import { FormProvider, Controller, useFormContext, useFormState, useFieldArray, useForm } from 'react-hook-form';
9
9
  import * as AccordionPrimitive from '@radix-ui/react-accordion';
10
10
  import { Slot } from '@radix-ui/react-slot';
11
11
  import { getDefaultClassNames, DayPicker } from 'react-day-picker';
@@ -29,7 +29,7 @@ import { Command as Command$1 } from 'cmdk';
29
29
  import * as TabsPrimitive from '@radix-ui/react-tabs';
30
30
  import * as SliderPrimitive from '@radix-ui/react-slider';
31
31
  import { useSensors, useSensor, PointerSensor, KeyboardSensor, DndContext, closestCenter } from '@dnd-kit/core';
32
- import { sortableKeyboardCoordinates, SortableContext, verticalListSortingStrategy, arrayMove, useSortable } from '@dnd-kit/sortable';
32
+ import { sortableKeyboardCoordinates, SortableContext, verticalListSortingStrategy, useSortable, arrayMove } from '@dnd-kit/sortable';
33
33
  import { CSS } from '@dnd-kit/utilities';
34
34
  import z2 from 'zod';
35
35
  import { zodResolver } from '@hookform/resolvers/zod';
@@ -195,9 +195,17 @@ var entitiesToGroupedOption = (data, optionValue = "name") => {
195
195
  return entities;
196
196
  };
197
197
  var handleOnChage = (event, input, field) => {
198
- console.log("\u{1F680} ~ handleOnChage ~ event:", event);
199
198
  if (event) field?.onChange(event);
200
- input.onChange?.(event);
199
+ input.onChange?.(event, input.form?.getValues());
200
+ };
201
+ var isValidField = (input, form, defaultValue) => {
202
+ const value = defaultValue ?? form.getValues(input.name);
203
+ const fieldState = form.getFieldState(input.name);
204
+ if (input.zodType) {
205
+ const result = input.zodType.safeParse(value);
206
+ return result.success;
207
+ }
208
+ return !fieldState.error && value !== void 0 && value !== "";
201
209
  };
202
210
 
203
211
  // src/components/custom/form/inputs/base/definitions.ts
@@ -931,7 +939,54 @@ function Separator({
931
939
  }
932
940
  );
933
941
  }
934
- cva(
942
+ function FieldSet({ className, ...props }) {
943
+ return /* @__PURE__ */ jsx(
944
+ "fieldset",
945
+ {
946
+ "data-slot": "field-set",
947
+ className: cn(
948
+ "flex flex-col gap-6",
949
+ "has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3",
950
+ className
951
+ ),
952
+ ...props
953
+ }
954
+ );
955
+ }
956
+ function FieldLegend({
957
+ className,
958
+ variant = "legend",
959
+ ...props
960
+ }) {
961
+ return /* @__PURE__ */ jsx(
962
+ "legend",
963
+ {
964
+ "data-slot": "field-legend",
965
+ "data-variant": variant,
966
+ className: cn(
967
+ "mb-3 font-medium",
968
+ "data-[variant=legend]:text-base",
969
+ "data-[variant=label]:text-sm",
970
+ className
971
+ ),
972
+ ...props
973
+ }
974
+ );
975
+ }
976
+ function FieldGroup({ className, ...props }) {
977
+ return /* @__PURE__ */ jsx(
978
+ "div",
979
+ {
980
+ "data-slot": "field-group",
981
+ className: cn(
982
+ "group/field-group @container/field-group flex w-full flex-col gap-7 data-[slot=checkbox-group]:gap-3 [&>[data-slot=field-group]]:gap-4",
983
+ className
984
+ ),
985
+ ...props
986
+ }
987
+ );
988
+ }
989
+ var fieldVariants = cva(
935
990
  "group/field flex w-full gap-3 data-[invalid=true]:text-destructive",
936
991
  {
937
992
  variants: {
@@ -954,6 +1009,147 @@ cva(
954
1009
  }
955
1010
  }
956
1011
  );
1012
+ function Field({
1013
+ className,
1014
+ orientation = "vertical",
1015
+ ...props
1016
+ }) {
1017
+ return /* @__PURE__ */ jsx(
1018
+ "div",
1019
+ {
1020
+ role: "group",
1021
+ "data-slot": "field",
1022
+ "data-orientation": orientation,
1023
+ className: cn(fieldVariants({ orientation }), className),
1024
+ ...props
1025
+ }
1026
+ );
1027
+ }
1028
+ function FieldContent({ className, ...props }) {
1029
+ return /* @__PURE__ */ jsx(
1030
+ "div",
1031
+ {
1032
+ "data-slot": "field-content",
1033
+ className: cn(
1034
+ "group/field-content flex flex-1 flex-col gap-1.5 leading-snug",
1035
+ className
1036
+ ),
1037
+ ...props
1038
+ }
1039
+ );
1040
+ }
1041
+ function FieldLabel({
1042
+ className,
1043
+ ...props
1044
+ }) {
1045
+ return /* @__PURE__ */ jsx(
1046
+ Label,
1047
+ {
1048
+ "data-slot": "field-label",
1049
+ className: cn(
1050
+ "group/field-label peer/field-label flex w-fit gap-2 leading-snug group-data-[disabled=true]/field:opacity-50",
1051
+ "has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col has-[>[data-slot=field]]:rounded-md has-[>[data-slot=field]]:border [&>*]:data-[slot=field]:p-4",
1052
+ "has-data-[state=checked]:bg-primary/5 has-data-[state=checked]:border-primary dark:has-data-[state=checked]:bg-primary/10",
1053
+ className
1054
+ ),
1055
+ ...props
1056
+ }
1057
+ );
1058
+ }
1059
+ function FieldTitle({ className, ...props }) {
1060
+ return /* @__PURE__ */ jsx(
1061
+ "div",
1062
+ {
1063
+ "data-slot": "field-label",
1064
+ className: cn(
1065
+ "flex w-fit items-center gap-2 text-sm leading-snug font-medium group-data-[disabled=true]/field:opacity-50",
1066
+ className
1067
+ ),
1068
+ ...props
1069
+ }
1070
+ );
1071
+ }
1072
+ function FieldDescription({ className, ...props }) {
1073
+ return /* @__PURE__ */ jsx(
1074
+ "p",
1075
+ {
1076
+ "data-slot": "field-description",
1077
+ className: cn(
1078
+ "text-muted-foreground text-sm leading-normal font-normal group-has-[[data-orientation=horizontal]]/field:text-balance",
1079
+ "last:mt-0 nth-last-2:-mt-1 [[data-variant=legend]+&]:-mt-1.5",
1080
+ "[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4",
1081
+ className
1082
+ ),
1083
+ ...props
1084
+ }
1085
+ );
1086
+ }
1087
+ function FieldSeparator({
1088
+ children,
1089
+ className,
1090
+ ...props
1091
+ }) {
1092
+ return /* @__PURE__ */ jsxs(
1093
+ "div",
1094
+ {
1095
+ "data-slot": "field-separator",
1096
+ "data-content": !!children,
1097
+ className: cn(
1098
+ "relative -my-2 h-5 text-sm group-data-[variant=outline]/field-group:-mb-2",
1099
+ className
1100
+ ),
1101
+ ...props,
1102
+ children: [
1103
+ /* @__PURE__ */ jsx(Separator, { className: "absolute inset-0 top-1/2" }),
1104
+ children && /* @__PURE__ */ jsx(
1105
+ "span",
1106
+ {
1107
+ className: "bg-background text-muted-foreground relative mx-auto block w-fit px-2",
1108
+ "data-slot": "field-separator-content",
1109
+ children
1110
+ }
1111
+ )
1112
+ ]
1113
+ }
1114
+ );
1115
+ }
1116
+ function FieldError({
1117
+ className,
1118
+ children,
1119
+ errors,
1120
+ ...props
1121
+ }) {
1122
+ const content = useMemo(() => {
1123
+ if (children) {
1124
+ return children;
1125
+ }
1126
+ if (!errors?.length) {
1127
+ return null;
1128
+ }
1129
+ const uniqueErrors = [
1130
+ ...new Map(errors.map((error) => [error?.message, error])).values()
1131
+ ];
1132
+ if (uniqueErrors?.length == 1) {
1133
+ return uniqueErrors[0]?.message;
1134
+ }
1135
+ return /* @__PURE__ */ jsx("ul", { className: "ml-4 flex list-disc flex-col gap-1", children: uniqueErrors.map(
1136
+ (error, index) => error?.message && /* @__PURE__ */ jsx("li", { children: error.message }, index)
1137
+ ) });
1138
+ }, [children, errors]);
1139
+ if (!content) {
1140
+ return null;
1141
+ }
1142
+ return /* @__PURE__ */ jsx(
1143
+ "div",
1144
+ {
1145
+ role: "alert",
1146
+ "data-slot": "field-error",
1147
+ className: cn("text-destructive text-sm font-normal", className),
1148
+ ...props,
1149
+ children: content
1150
+ }
1151
+ );
1152
+ }
957
1153
  var Form = FormProvider;
958
1154
  var FormFieldContext = React3.createContext(
959
1155
  {}
@@ -1145,7 +1341,7 @@ function InputGroupAddon({
1145
1341
  }
1146
1342
  );
1147
1343
  }
1148
- cva(
1344
+ var inputGroupButtonVariants = cva(
1149
1345
  "text-sm shadow-none flex gap-2 items-center",
1150
1346
  {
1151
1347
  variants: {
@@ -1161,6 +1357,24 @@ cva(
1161
1357
  }
1162
1358
  }
1163
1359
  );
1360
+ function InputGroupButton({
1361
+ className,
1362
+ type = "button",
1363
+ variant = "ghost",
1364
+ size = "xs",
1365
+ ...props
1366
+ }) {
1367
+ return /* @__PURE__ */ jsx(
1368
+ Button,
1369
+ {
1370
+ type,
1371
+ "data-size": size,
1372
+ variant,
1373
+ className: cn(inputGroupButtonVariants({ size }), className),
1374
+ ...props
1375
+ }
1376
+ );
1377
+ }
1164
1378
  function InputGroupText({ className, ...props }) {
1165
1379
  return /* @__PURE__ */ jsx(
1166
1380
  "span",
@@ -1189,6 +1403,22 @@ function InputGroupInput({
1189
1403
  }
1190
1404
  );
1191
1405
  }
1406
+ function InputGroupTextarea({
1407
+ className,
1408
+ ...props
1409
+ }) {
1410
+ return /* @__PURE__ */ jsx(
1411
+ Textarea,
1412
+ {
1413
+ "data-slot": "input-group-control",
1414
+ className: cn(
1415
+ "flex-1 resize-none rounded-none border-0 bg-transparent py-3 shadow-none focus-visible:ring-0 dark:bg-transparent",
1416
+ className
1417
+ ),
1418
+ ...props
1419
+ }
1420
+ );
1421
+ }
1192
1422
  function InputOTP({
1193
1423
  className,
1194
1424
  containerClassName,
@@ -1787,6 +2017,41 @@ function ButtonGroup({
1787
2017
  }
1788
2018
  );
1789
2019
  }
2020
+ function ButtonGroupText({
2021
+ className,
2022
+ asChild = false,
2023
+ ...props
2024
+ }) {
2025
+ const Comp = asChild ? Slot : "div";
2026
+ return /* @__PURE__ */ jsx(
2027
+ Comp,
2028
+ {
2029
+ className: cn(
2030
+ "bg-muted flex items-center gap-2 rounded-md border px-4 text-sm font-medium shadow-xs [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
2031
+ className
2032
+ ),
2033
+ ...props
2034
+ }
2035
+ );
2036
+ }
2037
+ function ButtonGroupSeparator({
2038
+ className,
2039
+ orientation = "vertical",
2040
+ ...props
2041
+ }) {
2042
+ return /* @__PURE__ */ jsx(
2043
+ Separator,
2044
+ {
2045
+ "data-slot": "button-group-separator",
2046
+ orientation,
2047
+ className: cn(
2048
+ "bg-input relative !m-0 self-stretch data-[orientation=vertical]:h-auto",
2049
+ className
2050
+ ),
2051
+ ...props
2052
+ }
2053
+ );
2054
+ }
1790
2055
  var ButtonGroupInput = class extends BaseInput {
1791
2056
  render() {
1792
2057
  const { input, form, isSubmitting } = this;
@@ -1814,7 +2079,7 @@ var FieldButtonGroup = ({ input, form, isSubmitting, className = "w-full flex-1"
1814
2079
  disabled: isSubmitting,
1815
2080
  children: option.label ?? option.name
1816
2081
  },
1817
- key
2082
+ `${input.name}-${key}-btn-g`
1818
2083
  )) });
1819
2084
  };
1820
2085
  var CheckListInput = class extends BaseInput {
@@ -1990,6 +2255,29 @@ function Command({
1990
2255
  }
1991
2256
  );
1992
2257
  }
2258
+ function CommandDialog({
2259
+ title = "Command Palette",
2260
+ description = "Search for a command to run...",
2261
+ children,
2262
+ className,
2263
+ showCloseButton = true,
2264
+ ...props
2265
+ }) {
2266
+ return /* @__PURE__ */ jsxs(Dialog, { ...props, children: [
2267
+ /* @__PURE__ */ jsxs(DialogHeader, { className: "sr-only", children: [
2268
+ /* @__PURE__ */ jsx(DialogTitle, { children: title }),
2269
+ /* @__PURE__ */ jsx(DialogDescription, { children: description })
2270
+ ] }),
2271
+ /* @__PURE__ */ jsx(
2272
+ DialogContent,
2273
+ {
2274
+ className: cn("overflow-hidden p-0", className),
2275
+ showCloseButton,
2276
+ children: /* @__PURE__ */ jsx(Command, { className: "[&_[cmdk-group-heading]]:text-muted-foreground **:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5", children })
2277
+ }
2278
+ )
2279
+ ] });
2280
+ }
1993
2281
  function CommandInput({
1994
2282
  className,
1995
2283
  ...props
@@ -2060,6 +2348,19 @@ function CommandGroup({
2060
2348
  }
2061
2349
  );
2062
2350
  }
2351
+ function CommandSeparator({
2352
+ className,
2353
+ ...props
2354
+ }) {
2355
+ return /* @__PURE__ */ jsx(
2356
+ Command$1.Separator,
2357
+ {
2358
+ "data-slot": "command-separator",
2359
+ className: cn("bg-border -mx-1 h-px", className),
2360
+ ...props
2361
+ }
2362
+ );
2363
+ }
2063
2364
  function CommandItem({
2064
2365
  className,
2065
2366
  ...props
@@ -2076,6 +2377,22 @@ function CommandItem({
2076
2377
  }
2077
2378
  );
2078
2379
  }
2380
+ function CommandShortcut({
2381
+ className,
2382
+ ...props
2383
+ }) {
2384
+ return /* @__PURE__ */ jsx(
2385
+ "span",
2386
+ {
2387
+ "data-slot": "command-shortcut",
2388
+ className: cn(
2389
+ "text-muted-foreground ml-auto text-xs tracking-widest",
2390
+ className
2391
+ ),
2392
+ ...props
2393
+ }
2394
+ );
2395
+ }
2079
2396
  var ComboboxInput = class extends BaseInput {
2080
2397
  render() {
2081
2398
  const { input, form, isSubmitting } = this;
@@ -3857,60 +4174,82 @@ function cleanEscapedString(input) {
3857
4174
  var DateInput = class extends BaseInput {
3858
4175
  render() {
3859
4176
  const { input, form, isSubmitting } = this;
3860
- const formField = /* @__PURE__ */ jsx(
3861
- FormField,
3862
- {
3863
- control: form.control,
3864
- name: input.name,
3865
- render: ({ field }) => {
3866
- const [date, setDate] = React3.useState(
3867
- field.value ? new Date(field.value) : void 0
3868
- );
3869
- React3.useEffect(() => {
3870
- if (field.value && !date) {
3871
- setDate(new Date(field.value));
3872
- }
3873
- }, [field.value]);
3874
- const handleSelect = (selectedDate) => {
3875
- setDate(selectedDate);
3876
- handleOnChage(selectedDate, input, field);
3877
- };
3878
- return /* @__PURE__ */ jsxs(FormItem, { children: [
3879
- /* @__PURE__ */ jsx(FormLabel, { children: /* @__PURE__ */ jsx("b", { children: input.label }) }),
3880
- /* @__PURE__ */ jsxs(Popover, { children: [
3881
- /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsxs(
3882
- Button,
3883
- {
3884
- variant: "outline",
3885
- className: cn(
3886
- "w-full justify-start text-left font-normal",
3887
- !date && "text-muted-foreground"
3888
- ),
3889
- children: [
4177
+ return /* @__PURE__ */ jsx(FieldTimeInput, { input, form, isSubmitting });
4178
+ }
4179
+ };
4180
+ var FieldTimeInput = ({ form, input, isSubmitting }) => {
4181
+ const [isValid2, setIsValid] = useState(isValidField(input, form));
4182
+ const groupConfig = input.inputGroupConfig;
4183
+ const autoValidate = groupConfig?.autoValidIcons ?? input.zodType ? true : false;
4184
+ const iconValidState = /* @__PURE__ */ jsx(CircleCheck, { style: { color: "#00bf3e" } });
4185
+ const iconInvalidState = /* @__PURE__ */ jsx(CircleX, { style: { color: "#ff8080" } });
4186
+ const iconLoadingState = /* @__PURE__ */ jsx(Loader2, { className: "animate-spin", style: { color: "#1e90ff" } });
4187
+ const iconsRight = groupConfig?.iconsRight ?? [];
4188
+ groupConfig?.iconsLeft ?? [];
4189
+ groupConfig?.textLeft;
4190
+ const textRight = groupConfig?.textRight;
4191
+ const formField = /* @__PURE__ */ jsx(
4192
+ FormField,
4193
+ {
4194
+ control: form.control,
4195
+ name: input.name,
4196
+ render: ({ field }) => {
4197
+ setIsValid(isValidField(input, form));
4198
+ const [date, setDate] = React3.useState(
4199
+ field.value ? new Date(field.value) : void 0
4200
+ );
4201
+ React3.useEffect(() => {
4202
+ if (field.value && !date) {
4203
+ setDate(new Date(field.value));
4204
+ setIsValid(isValidField(input, form));
4205
+ }
4206
+ }, [field.value]);
4207
+ const handleSelect = (selectedDate) => {
4208
+ setDate(selectedDate);
4209
+ handleOnChage(selectedDate, input, field);
4210
+ };
4211
+ return /* @__PURE__ */ jsxs(FormItem, { children: [
4212
+ /* @__PURE__ */ jsx(FormLabel, { children: /* @__PURE__ */ jsx("b", { children: input.label }) }),
4213
+ /* @__PURE__ */ jsxs(Popover, { children: [
4214
+ /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(InputGroup, { className: "flex flex-row gap-1", children: /* @__PURE__ */ jsxs(
4215
+ Button,
4216
+ {
4217
+ variant: "outline",
4218
+ className: cn(
4219
+ "w-full justify-start text-left py-0.5 ",
4220
+ !date && "text-muted-foreground"
4221
+ ),
4222
+ children: [
4223
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-1 items-center gap-1 justify-start text-left ", children: [
3890
4224
  /* @__PURE__ */ jsx(CalendarIcon, {}),
3891
4225
  date ? format(date, "PPP") : /* @__PURE__ */ jsx("span", { children: input.placeHolder ?? "Fecha" })
3892
- ]
3893
- }
3894
- ) }) }),
3895
- /* @__PURE__ */ jsx(PopoverContent, { className: "w-auto p-0", children: /* @__PURE__ */ jsx(
3896
- Calendar,
3897
- {
3898
- mode: "single",
3899
- selected: date,
3900
- onSelect: handleSelect,
3901
- initialFocus: true
3902
- }
3903
- ) })
3904
- ] }),
3905
- /* @__PURE__ */ jsx(FormDescription, { children: input.description }),
3906
- /* @__PURE__ */ jsx(FormMessage, {})
3907
- ] });
3908
- }
3909
- },
3910
- input.name
3911
- );
3912
- return /* @__PURE__ */ jsx(Fragment, { children: formField });
3913
- }
4226
+ ] }),
4227
+ (iconsRight.length > 0 || textRight || autoValidate) && /* @__PURE__ */ jsxs(Fragment, { children: [
4228
+ textRight && /* @__PURE__ */ jsx(InputGroupText, { children: textRight }),
4229
+ iconsRight.map((IconComponent, index) => /* @__PURE__ */ jsx(IconComponent, { size: 24, className: "w-6! h-6!" }, index)),
4230
+ autoValidate && /* @__PURE__ */ jsx("div", { children: isSubmitting ? iconLoadingState : isValid2 ? iconValidState : iconInvalidState })
4231
+ ] })
4232
+ ]
4233
+ }
4234
+ ) }) }) }),
4235
+ /* @__PURE__ */ jsx(PopoverContent, { className: "w-auto p-0", children: /* @__PURE__ */ jsx(
4236
+ Calendar,
4237
+ {
4238
+ mode: "single",
4239
+ selected: date,
4240
+ onSelect: handleSelect,
4241
+ initialFocus: true
4242
+ }
4243
+ ) })
4244
+ ] }),
4245
+ /* @__PURE__ */ jsx(FormDescription, { children: input.description }),
4246
+ /* @__PURE__ */ jsx(FormMessage, {})
4247
+ ] });
4248
+ }
4249
+ },
4250
+ input.name
4251
+ );
4252
+ return /* @__PURE__ */ jsx(Fragment, { children: formField });
3914
4253
  };
3915
4254
  var DateTimeInput = class extends BaseInput {
3916
4255
  render() {
@@ -3920,7 +4259,7 @@ var DateTimeInput = class extends BaseInput {
3920
4259
  };
3921
4260
  var FieldDateTimeInput = ({ form, input, isSubmitting }) => {
3922
4261
  const groupConfig = input.inputGroupConfig;
3923
- const autoValidate = groupConfig?.autoValidIcons;
4262
+ const autoValidate = groupConfig?.autoValidIcons ?? input.zodType ? true : false;
3924
4263
  const iconValidState = /* @__PURE__ */ jsx(CircleCheck, { style: { color: "#00bf3e" } });
3925
4264
  const iconInvalidState = /* @__PURE__ */ jsx(CircleX, { style: { color: "#ff8080" } });
3926
4265
  const iconLoadingState = /* @__PURE__ */ jsx(Loader2, { className: "animate-spin", style: { color: "#1e90ff" } });
@@ -3971,7 +4310,7 @@ var FieldDateTimeInput = ({ form, input, isSubmitting }) => {
3971
4310
  ),
3972
4311
  (iconsRight.length > 0 || textRight || autoValidate) && /* @__PURE__ */ jsxs(InputGroupAddon, { align: "inline-end", children: [
3973
4312
  textRight && /* @__PURE__ */ jsx(InputGroupText, { children: textRight }),
3974
- iconsRight.map((IconComponent, index) => /* @__PURE__ */ jsx(IconComponent, { size: 20 }, index)),
4313
+ iconsRight.map((IconComponent, index) => /* @__PURE__ */ jsx(IconComponent, { size: 24 }, index)),
3975
4314
  autoValidate && /* @__PURE__ */ jsx("div", { children: isSubmitting ? iconLoadingState : isValid2 ? iconValidState : iconInvalidState })
3976
4315
  ] })
3977
4316
  ] }) }),
@@ -4294,7 +4633,7 @@ var FieldMultiSelect = ({ form, input, isSubmitting }) => {
4294
4633
  const option = lista.find(
4295
4634
  (item) => getValue(item).toString() === val
4296
4635
  );
4297
- return /* @__PURE__ */ jsx(Badge, { variant: "secondary", children: option?.name ?? val }, val);
4636
+ return /* @__PURE__ */ jsx(Badge, { variant: "secondary", children: option?.name ?? val }, `${input.name}-${val}-ms`);
4298
4637
  }) }) : /* @__PURE__ */ jsx("span", { children: input.placeHolder ?? "Selecciona..." }),
4299
4638
  /* @__PURE__ */ jsx(ChevronsUpDown, { className: "ml-2 h-4 w-4 opacity-50" })
4300
4639
  ]
@@ -4327,7 +4666,7 @@ var FieldMultiSelect = ({ form, input, isSubmitting }) => {
4327
4666
  item.name
4328
4667
  ]
4329
4668
  },
4330
- value
4669
+ `${value}-ms`
4331
4670
  );
4332
4671
  }) })
4333
4672
  ] })
@@ -4349,7 +4688,7 @@ var TextInputGroup = class extends BaseInput {
4349
4688
  var FieldTextGroup = ({ form, input, isSubmitting }) => {
4350
4689
  const groupConfig = input.inputGroupConfig;
4351
4690
  const infoTooltip = input?.infoTooltip;
4352
- const autoValidate = groupConfig?.autoValidIcons;
4691
+ const autoValidate = groupConfig?.autoValidIcons ?? input.zodType ? true : false;
4353
4692
  const iconValidState = /* @__PURE__ */ jsx(CircleCheck, { style: { color: "#00bf3e" } });
4354
4693
  const iconInvalidState = /* @__PURE__ */ jsx(CircleX, { style: { color: "#ff8080" } });
4355
4694
  const iconLoadingState = /* @__PURE__ */ jsx(Loader2, { className: "animate-spin", style: { color: "#1e90ff" } });
@@ -4357,11 +4696,7 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
4357
4696
  const iconsLeft = groupConfig?.iconsLeft ?? [];
4358
4697
  const textLeft = groupConfig?.textLeft;
4359
4698
  const textRight = groupConfig?.textRight;
4360
- const [isValid2, setIsValid] = useState(() => {
4361
- const value = form.getValues(input.name);
4362
- const fieldState = form.getFieldState(input.name);
4363
- return !fieldState.error && value !== void 0 && value !== "";
4364
- });
4699
+ const [isValid2, setIsValid] = useState(isValidField(input, form));
4365
4700
  const [showPassword, setShowPassword] = useState(false);
4366
4701
  const isPasswordField = input.keyboardType === "password" /* PASSWORD */;
4367
4702
  const isNumberField = input.keyboardType === "number" /* NUMBER */;
@@ -4371,9 +4706,8 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
4371
4706
  {
4372
4707
  control: form.control,
4373
4708
  name: input.name,
4374
- render: ({ field, fieldState }) => {
4375
- const validNow = !fieldState.error && field.value !== void 0 && field.value !== "";
4376
- if (validNow !== isValid2) setIsValid(validNow);
4709
+ render: ({ field }) => {
4710
+ setIsValid(isValidField(input, form));
4377
4711
  return /* @__PURE__ */ jsxs(FormItem, { className: input.className, children: [
4378
4712
  /* @__PURE__ */ jsx(FormLabel, { children: /* @__PURE__ */ jsx("b", { children: input.label }) }),
4379
4713
  /* @__PURE__ */ jsx(FormControl, { className: "shadow-lg", children: /* @__PURE__ */ jsxs(InputGroup, { children: [
@@ -4398,6 +4732,7 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
4398
4732
  }
4399
4733
  handleOnChage(value, input, field);
4400
4734
  field.onChange(value);
4735
+ isValidField(input, form);
4401
4736
  }
4402
4737
  }
4403
4738
  ),
@@ -4865,7 +5200,7 @@ var FieldSelect = ({ form, input, isSubmitting }) => {
4865
5200
  }
4866
5201
  ) }) }),
4867
5202
  /* @__PURE__ */ jsxs(SelectContent, { children: [
4868
- lista.map((item) => /* @__PURE__ */ jsx(SelectItem, { value: getValue(item), children: item.name }, item.id)),
5203
+ lista.map((item) => /* @__PURE__ */ jsx(SelectItem, { value: getValue(item), children: item.name }, `${input.name}-${item.id}-s`)),
4869
5204
  lista.length === 0 && !loading && /* @__PURE__ */ jsx("div", { className: "p-2 text-sm text-muted-foreground", children: "No hay opciones disponibles" })
4870
5205
  ] })
4871
5206
  ]
@@ -5475,10 +5810,10 @@ var FieldText = ({ input, form, isSubmitting }) => {
5475
5810
  var TimeInput = class extends BaseInput {
5476
5811
  render() {
5477
5812
  const { input, form, isSubmitting } = this;
5478
- return /* @__PURE__ */ jsx(FieldTimeInput, { input, form, isSubmitting });
5813
+ return /* @__PURE__ */ jsx(FieldTimeInput2, { input, form, isSubmitting });
5479
5814
  }
5480
5815
  };
5481
- var FieldTimeInput = ({ form, input, isSubmitting }) => {
5816
+ var FieldTimeInput2 = ({ form, input, isSubmitting }) => {
5482
5817
  const groupConfig = input.inputGroupConfig;
5483
5818
  const autoValidate = groupConfig?.autoValidIcons;
5484
5819
  const iconValidState = /* @__PURE__ */ jsx(CircleCheck, { style: { color: "#00bf3e" } });
@@ -5586,6 +5921,7 @@ var inputMap = {
5586
5921
  };
5587
5922
  var InputFactory = class {
5588
5923
  static create(input, form, isSubmitting = false) {
5924
+ input.form = form;
5589
5925
  const inputType = input.inputType ?? "text" /* TEXT */;
5590
5926
  const InputClass = inputMap[inputType] ?? TextInput;
5591
5927
  const instance = new InputClass(input, form, isSubmitting);
@@ -5766,7 +6102,7 @@ var DynamicForm = ({
5766
6102
  });
5767
6103
  useEffect(() => {
5768
6104
  form.reset(initialValues);
5769
- }, [initialValues, form]);
6105
+ }, []);
5770
6106
  const handleSubmit = (data) => {
5771
6107
  if (readOnly) return;
5772
6108
  startTransition(() => {
@@ -6047,7 +6383,122 @@ var InputList = ({ handleAddInput, inputsTypes }) => {
6047
6383
  );
6048
6384
  }) });
6049
6385
  };
6386
+ var GenericFilter = ({
6387
+ filters = [],
6388
+ pagination,
6389
+ autoSubmit = false,
6390
+ defaultValues = {},
6391
+ initPage = 1,
6392
+ initLimit = 10,
6393
+ rangeLimit = [10, 25, 50, 100],
6394
+ onChange,
6395
+ withSearch = true,
6396
+ withInitDate = true,
6397
+ withEndDate = true,
6398
+ withActive = true,
6399
+ withLimit = true,
6400
+ wrapInCard = true
6401
+ }) => {
6402
+ const record = {
6403
+ page: initPage,
6404
+ limit: initLimit,
6405
+ ...defaultValues
6406
+ };
6407
+ const [values, setValues] = useState(record);
6408
+ const isFirstRender = useRef(true);
6409
+ useEffect(() => {
6410
+ if (isFirstRender.current) {
6411
+ isFirstRender.current = false;
6412
+ return;
6413
+ }
6414
+ }, [values]);
6415
+ const handleChange = (name, value) => {
6416
+ setValues((prev) => ({ ...prev, [name]: value }));
6417
+ if (autoSubmit && onChange) onChange({ ...values, [name]: value });
6418
+ };
6419
+ const baseFields = [
6420
+ ...withSearch ? [
6421
+ {
6422
+ name: "search",
6423
+ label: "Buscar",
6424
+ inputType: "text_group" /* TEXT_GROUP */,
6425
+ inputGroupConfig: { iconsLeft: [Search] },
6426
+ onChange: (value) => handleChange("search", value)
6427
+ }
6428
+ ] : [],
6429
+ ...withInitDate ? [
6430
+ {
6431
+ name: "initDate",
6432
+ label: "Fecha de Inicio",
6433
+ inputType: "date" /* DATE */,
6434
+ onChange: (value) => handleChange("initDate", value)
6435
+ }
6436
+ ] : [],
6437
+ ...withEndDate ? [
6438
+ {
6439
+ name: "endDate",
6440
+ label: "Fecha Final",
6441
+ inputType: "date" /* DATE */,
6442
+ onChange: (value) => handleChange("endDate", value)
6443
+ }
6444
+ ] : [],
6445
+ ...withActive ? [
6446
+ {
6447
+ wrapInCard: true,
6448
+ name: "active",
6449
+ label: "",
6450
+ inputType: "button_group" /* BUTTON_GROUP */,
6451
+ description: "Estado",
6452
+ listConfig: {
6453
+ list: [
6454
+ { id: 1, name: "Activo", value: true },
6455
+ { id: 2, name: "Inactivo", value: false },
6456
+ { id: 3, name: "Todos", value: void 0 }
6457
+ ],
6458
+ onOptionChange: (item) => {
6459
+ if (Array.isArray(item) && item[0]) handleChange("active", item[0].value);
6460
+ else if (item && "value" in item) handleChange("active", item.value);
6461
+ }
6462
+ }
6463
+ }
6464
+ ] : [],
6465
+ ...withLimit ? [
6466
+ {
6467
+ name: "limit",
6468
+ label: "L\xEDmite por p\xE1gina",
6469
+ inputType: "select" /* SELECT */,
6470
+ listConfig: {
6471
+ list: rangeLimit.map((num) => ({
6472
+ value: String(num),
6473
+ id: num,
6474
+ name: String(num)
6475
+ })),
6476
+ onOptionChange: (item) => handleChange("limit", Number(item?.value ?? 10))
6477
+ }
6478
+ }
6479
+ ] : []
6480
+ ];
6481
+ const fieldsConfig = [
6482
+ ...filters,
6483
+ baseFields
6484
+ ];
6485
+ return /* @__PURE__ */ jsx("div", { className: "flex flex-col md:flex-row md:items-end gap-4 py-3", children: /* @__PURE__ */ jsx("div", { className: "flex-1", children: /* @__PURE__ */ jsx(
6486
+ DynamicForm,
6487
+ {
6488
+ withCard: wrapInCard,
6489
+ withSubmitBtn: !autoSubmit,
6490
+ formTitle: "",
6491
+ submitBtnLabel: "Buscar",
6492
+ fields: fieldsConfig,
6493
+ record: values,
6494
+ showFormHeader: false,
6495
+ onSubmit: ({ data }) => {
6496
+ if (onChange && !autoSubmit) onChange(data);
6497
+ }
6498
+ }
6499
+ ) }) });
6500
+ };
6050
6501
 
6051
- export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, Button, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CheckListInput, Checkbox, ColorCnInput, ColorInput, CustomAlert, DateInput, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DynamicForm, DynamicFormExample, FileInput, Form, FormControl, FormDescription, FormErrorsAlert, FormField, FormItem, FormLabel, FormMessage, GroupedSwitchInput, GroupedSwitches, Input, InputFactory, InputList, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, InputTypes, Label, NumberInput, OTPInput2 as OTPInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, ResizableHandle, ResizablePanel, ResizablePanelGroup, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectInput, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, Switch, SwitchInput, TextAreaInput, TextInput, TextInputType, Textarea, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, buttonVariants, cn, entitiesToGroupedOption, entitiesToInputOption, entityToGroupedOption, entityToInputOption, flattenFields, getDefaultValues, getDynamicSchema, getFieldLabel, handleOnChage, inputFieldComp, mockFields, useFormField, validationMessages };
6502
+ export { Accordion, AccordionContent, AccordionGroupedSwitchInput, AccordionGroupedSwitches, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, Button, ButtonGroup, ButtonGroupInput, ButtonGroupSeparator, ButtonGroupText, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CheckListInput, Checkbox, CheckboxInput, ColorCnInput, ColorInput, ComboboxInput, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, CommandShortcut, CurrencyInput, CustomAlert, DateInput, DateTimeInput, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DynamicForm, DynamicFormExample, Field, FieldButtonGroup, FieldContent, FieldCurrency, FieldDateTimeInput, FieldDescription, FieldError, FieldFileMultiUpload, FieldGroup, FieldKeyValueList, FieldLabel, FieldLegend, FieldRepeater, FieldSeparator, FieldSet, FieldSimpleCheckList, FieldSlider, FieldStringValueList, FieldTextGroup, FieldTimeInput2 as FieldTimeInput, FieldTitle, FileInput, FileMultiUploadInput, Form, FormControl, FormDescription, FormErrorsAlert, FormField, FormFieldsGrid, FormItem, FormLabel, FormMessage, GenericFilter, GroupedSwitchInput, GroupedSwitches, Input, InputFactory, InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText, InputGroupTextarea, InputList, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, InputTypes, KeyValueListInput, Label, MultiSelectInput, NumberInput, OTPInput2 as OTPInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, RadioGroup, RadioGroupInput, RadioGroupItem, RepeaterInput, RepeaterTabsInput, ResizableHandle, ResizablePanel, ResizablePanelGroup, ScrollArea, ScrollBar, Select, SelectContent, SelectGroup, SelectInput, SelectItem, SelectLabel, SelectScrollDownButton, SelectScrollUpButton, SelectSeparator, SelectTrigger, SelectValue, Separator, SimpleCheckListInput, Slider, SliderInput, SortableListInput, StringValueListInput, Switch, SwitchInput, Tabs, TabsContent, TabsList, TabsTrigger, TagInput, TextAreaInput, TextInput, TextInputGroup, TextInputType, Textarea, TimeInput, Toaster, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, badgeVariants, buttonGroupVariants, buttonVariants, cn, entitiesToGroupedOption, entitiesToInputOption, entityToGroupedOption, entityToInputOption, flattenFields, getDefaultValues, getDynamicSchema, getFieldLabel, handleOnChage, inputFieldComp, isValidField, mockFields, useFormField, validationMessages };
6052
6503
  //# sourceMappingURL=index.mjs.map
6053
6504
  //# sourceMappingURL=index.mjs.map