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.d.mts CHANGED
@@ -81,6 +81,7 @@ declare const inputFieldComp: InputTypes[];
81
81
  interface FieldProps<T = Record<string, any>> {
82
82
  name: keyof T;
83
83
  label: string;
84
+ onChange?: (...event: any[]) => void;
84
85
  tabLabelField?: string;
85
86
  childrenPosition?: 'up' | 'down';
86
87
  children?: ReactNode | ((item: any, index: number) => ReactNode);
@@ -137,6 +138,13 @@ interface ListConfig {
137
138
  selectedList?: InputOption[];
138
139
  sortable?: boolean;
139
140
  }
141
+ interface BtnConfig {
142
+ label: string;
143
+ btnType: 'submit' | 'button';
144
+ onClick: () => void;
145
+ variant?: "default" | "link" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined;
146
+ disabled?: boolean;
147
+ }
140
148
  interface InputOption {
141
149
  id: number | string;
142
150
  name: string;
@@ -212,8 +220,9 @@ interface Props$4<T extends Record<string, any>> {
212
220
  submitBtnClass?: string;
213
221
  children?: ReactNode;
214
222
  childrenHeader?: ReactNode;
223
+ listBtnConfig?: BtnConfig[];
215
224
  }
216
- declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onSubmit, onClick, extraValidations, children, childrenHeader, showIcon, showFormHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, submitBtnLabel, }: Props$4<T>) => react_jsx_runtime.JSX.Element;
225
+ declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onSubmit, onClick, extraValidations, children, childrenHeader, showIcon, showFormHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, listBtnConfig, submitBtnLabel, }: Props$4<T>) => react_jsx_runtime.JSX.Element;
217
226
 
218
227
  declare const DynamicFormExample: () => react_jsx_runtime.JSX.Element;
219
228
  declare const mockFields: Array<FieldProps | FieldProps[]>;
@@ -311,14 +320,14 @@ declare function AlertTitle({ className, ...props }: React$1.ComponentProps<"div
311
320
  declare function AlertDescription({ className, ...props }: React$1.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
312
321
 
313
322
  declare const badgeVariants: (props?: ({
314
- variant?: "default" | "destructive" | "secondary" | "outline" | null | undefined;
323
+ variant?: "default" | "destructive" | "outline" | "secondary" | null | undefined;
315
324
  } & class_variance_authority_types.ClassProp) | undefined) => string;
316
325
  declare function Badge({ className, variant, asChild, ...props }: React$1.ComponentProps<"span"> & VariantProps<typeof badgeVariants> & {
317
326
  asChild?: boolean;
318
327
  }): react_jsx_runtime.JSX.Element;
319
328
 
320
329
  declare const buttonVariants: (props?: ({
321
- variant?: "default" | "destructive" | "link" | "secondary" | "outline" | "ghost" | null | undefined;
330
+ variant?: "default" | "destructive" | "link" | "outline" | "secondary" | "ghost" | null | undefined;
322
331
  size?: "default" | "sm" | "lg" | "icon" | "icon-sm" | "icon-lg" | null | undefined;
323
332
  } & class_variance_authority_types.ClassProp) | undefined) => string;
324
333
  declare function Button({ className, variant, size, asChild, ...props }: React$1.ComponentProps<"button"> & VariantProps<typeof buttonVariants> & {
@@ -438,4 +447,4 @@ declare function TooltipContent({ className, sideOffset, children, ...props }: R
438
447
 
439
448
  declare function cn(...inputs: ClassValue[]): string;
440
449
 
441
- export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, Button, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CheckListInput, Checkbox, ColorCnInput, type ColorCompProps, ColorInput, CustomAlert, DateInput, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DynamicForm, DynamicFormExample, type FieldProps, FileInput, Form, FormControl, FormDescription, FormErrorsAlert, FormField, FormItem, FormLabel, FormMessage, type FormResp, type GroupedOption, GroupedSwitchInput, GroupedSwitches, Input, InputFactory, InputList, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, type InputOption, type InputSetup, InputTypes, Label, NumberInput, OTPInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, type Props, 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, getDefaultValues, getDynamicSchema, getFieldLabel, inputFieldComp, mockFields, useFormField, validationMessages };
450
+ export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, type BtnConfig, Button, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CheckListInput, Checkbox, ColorCnInput, type ColorCompProps, ColorInput, CustomAlert, DateInput, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DynamicForm, DynamicFormExample, type FieldProps, FileInput, Form, FormControl, FormDescription, FormErrorsAlert, FormField, FormItem, FormLabel, FormMessage, type FormResp, type GroupedOption, GroupedSwitchInput, GroupedSwitches, Input, InputFactory, InputList, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, type InputOption, type InputSetup, InputTypes, Label, NumberInput, OTPInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, type Props, 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, getDefaultValues, getDynamicSchema, getFieldLabel, inputFieldComp, mockFields, useFormField, validationMessages };
package/dist/index.d.ts CHANGED
@@ -81,6 +81,7 @@ declare const inputFieldComp: InputTypes[];
81
81
  interface FieldProps<T = Record<string, any>> {
82
82
  name: keyof T;
83
83
  label: string;
84
+ onChange?: (...event: any[]) => void;
84
85
  tabLabelField?: string;
85
86
  childrenPosition?: 'up' | 'down';
86
87
  children?: ReactNode | ((item: any, index: number) => ReactNode);
@@ -137,6 +138,13 @@ interface ListConfig {
137
138
  selectedList?: InputOption[];
138
139
  sortable?: boolean;
139
140
  }
141
+ interface BtnConfig {
142
+ label: string;
143
+ btnType: 'submit' | 'button';
144
+ onClick: () => void;
145
+ variant?: "default" | "link" | "destructive" | "outline" | "secondary" | "ghost" | null | undefined;
146
+ disabled?: boolean;
147
+ }
140
148
  interface InputOption {
141
149
  id: number | string;
142
150
  name: string;
@@ -212,8 +220,9 @@ interface Props$4<T extends Record<string, any>> {
212
220
  submitBtnClass?: string;
213
221
  children?: ReactNode;
214
222
  childrenHeader?: ReactNode;
223
+ listBtnConfig?: BtnConfig[];
215
224
  }
216
- declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onSubmit, onClick, extraValidations, children, childrenHeader, showIcon, showFormHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, submitBtnLabel, }: Props$4<T>) => react_jsx_runtime.JSX.Element;
225
+ declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onSubmit, onClick, extraValidations, children, childrenHeader, showIcon, showFormHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, listBtnConfig, submitBtnLabel, }: Props$4<T>) => react_jsx_runtime.JSX.Element;
217
226
 
218
227
  declare const DynamicFormExample: () => react_jsx_runtime.JSX.Element;
219
228
  declare const mockFields: Array<FieldProps | FieldProps[]>;
@@ -311,14 +320,14 @@ declare function AlertTitle({ className, ...props }: React$1.ComponentProps<"div
311
320
  declare function AlertDescription({ className, ...props }: React$1.ComponentProps<"div">): react_jsx_runtime.JSX.Element;
312
321
 
313
322
  declare const badgeVariants: (props?: ({
314
- variant?: "default" | "destructive" | "secondary" | "outline" | null | undefined;
323
+ variant?: "default" | "destructive" | "outline" | "secondary" | null | undefined;
315
324
  } & class_variance_authority_types.ClassProp) | undefined) => string;
316
325
  declare function Badge({ className, variant, asChild, ...props }: React$1.ComponentProps<"span"> & VariantProps<typeof badgeVariants> & {
317
326
  asChild?: boolean;
318
327
  }): react_jsx_runtime.JSX.Element;
319
328
 
320
329
  declare const buttonVariants: (props?: ({
321
- variant?: "default" | "destructive" | "link" | "secondary" | "outline" | "ghost" | null | undefined;
330
+ variant?: "default" | "destructive" | "link" | "outline" | "secondary" | "ghost" | null | undefined;
322
331
  size?: "default" | "sm" | "lg" | "icon" | "icon-sm" | "icon-lg" | null | undefined;
323
332
  } & class_variance_authority_types.ClassProp) | undefined) => string;
324
333
  declare function Button({ className, variant, size, asChild, ...props }: React$1.ComponentProps<"button"> & VariantProps<typeof buttonVariants> & {
@@ -438,4 +447,4 @@ declare function TooltipContent({ className, sideOffset, children, ...props }: R
438
447
 
439
448
  declare function cn(...inputs: ClassValue[]): string;
440
449
 
441
- export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, Button, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CheckListInput, Checkbox, ColorCnInput, type ColorCompProps, ColorInput, CustomAlert, DateInput, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DynamicForm, DynamicFormExample, type FieldProps, FileInput, Form, FormControl, FormDescription, FormErrorsAlert, FormField, FormItem, FormLabel, FormMessage, type FormResp, type GroupedOption, GroupedSwitchInput, GroupedSwitches, Input, InputFactory, InputList, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, type InputOption, type InputSetup, InputTypes, Label, NumberInput, OTPInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, type Props, 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, getDefaultValues, getDynamicSchema, getFieldLabel, inputFieldComp, mockFields, useFormField, validationMessages };
450
+ export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertTitle, Badge, BaseInput, type BtnConfig, Button, Calendar, CalendarDayButton, Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CheckListInput, Checkbox, ColorCnInput, type ColorCompProps, ColorInput, CustomAlert, DateInput, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DynamicForm, DynamicFormExample, type FieldProps, FileInput, Form, FormControl, FormDescription, FormErrorsAlert, FormField, FormItem, FormLabel, FormMessage, type FormResp, type GroupedOption, GroupedSwitchInput, GroupedSwitches, Input, InputFactory, InputList, InputOTP, InputOTPGroup, InputOTPSeparator, InputOTPSlot, type InputOption, type InputSetup, InputTypes, Label, NumberInput, OTPInput, Popover, PopoverAnchor, PopoverContent, PopoverTrigger, type Props, 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, getDefaultValues, getDynamicSchema, getFieldLabel, inputFieldComp, mockFields, useFormField, validationMessages };
package/dist/index.mjs CHANGED
@@ -1768,31 +1768,29 @@ function ButtonGroup({
1768
1768
  var ButtonGroupInput = class extends BaseInput {
1769
1769
  render() {
1770
1770
  const { input, form, isSubmitting } = this;
1771
- return /* @__PURE__ */ jsx(FieldButtonGroup, { input, form, isSubmitting });
1771
+ const className = input.className;
1772
+ return /* @__PURE__ */ jsx(FieldButtonGroup, { input, form, isSubmitting, className });
1772
1773
  }
1773
1774
  };
1774
- var FieldButtonGroup = ({ input, form, isSubmitting }) => {
1775
+ var FieldButtonGroup = ({ input, form, isSubmitting, className = "w-full flex-1" }) => {
1775
1776
  const options = (input.listConfig?.list ?? []).filter((option) => "name" in option);
1776
1777
  const handleSelect = (value) => {
1777
1778
  form.setValue(input.name, value, { shouldValidate: true });
1779
+ if (input.listConfig?.onOptionChange) input.listConfig.onOptionChange(value);
1778
1780
  };
1779
1781
  const selectedValue = form.watch(input.name);
1780
- return (
1781
- // <div className="flex flex-col gap-1 w-full">
1782
- // <label className="font-semibold">{input.label}</label>
1783
- // <div className="flex flex-wrap gap-2">
1784
- /* @__PURE__ */ jsx(ButtonGroup, { children: options.map((option) => /* @__PURE__ */ jsx(
1785
- Button,
1786
- {
1787
- type: "button",
1788
- variant: selectedValue === option.value ? "default" : "outline",
1789
- onClick: () => handleSelect(option.value),
1790
- disabled: isSubmitting,
1791
- children: option.label ?? option.name
1792
- },
1793
- option.value
1794
- )) })
1795
- );
1782
+ return /* @__PURE__ */ jsx(ButtonGroup, { className: "flex flex-row w-full", children: options.map((option) => /* @__PURE__ */ jsx(
1783
+ Button,
1784
+ {
1785
+ type: "button",
1786
+ className,
1787
+ variant: selectedValue === option.value ? "default" : "outline",
1788
+ onClick: () => handleSelect(option.value),
1789
+ disabled: isSubmitting,
1790
+ children: option.label ?? option.name
1791
+ },
1792
+ option.value
1793
+ )) });
1796
1794
  };
1797
1795
  var CheckListInput = class extends BaseInput {
1798
1796
  render() {
@@ -3982,7 +3980,6 @@ var FieldFile = ({ form, input, isSubmitting }) => {
3982
3980
  if (file) {
3983
3981
  const objectUrl = URL.createObjectURL(file);
3984
3982
  setPreview(objectUrl);
3985
- console.log("\u{1F680} ~ handleFileChange ~ objectUrl:", objectUrl);
3986
3983
  } else {
3987
3984
  setPreview(null);
3988
3985
  }
@@ -4340,7 +4337,8 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
4340
4337
  return !fieldState.error && value !== void 0 && value !== "";
4341
4338
  });
4342
4339
  const [showPassword, setShowPassword] = useState(false);
4343
- const isPasswordField = input.keyboardType === "password";
4340
+ const isPasswordField = input.keyboardType === "password" /* PASSWORD */;
4341
+ const isNumberField = input.keyboardType === "number" /* NUMBER */;
4344
4342
  const showInputGroupAddons = iconsRight.length > 0 || textRight || autoValidate || infoTooltip || isPasswordField;
4345
4343
  const formField = /* @__PURE__ */ jsx(
4346
4344
  FormField,
@@ -4362,8 +4360,18 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
4362
4360
  {
4363
4361
  placeholder: input.placeHolder,
4364
4362
  disabled: input.disabled || isSubmitting,
4365
- ...field,
4366
- type: isPasswordField && !showPassword ? "password" : "text"
4363
+ onBlur: field.onBlur,
4364
+ name: field.name,
4365
+ ref: field.ref,
4366
+ type: isPasswordField && !showPassword ? "password" : isNumberField ? "number" : "text",
4367
+ value: field.value ?? "",
4368
+ onChange: (e) => {
4369
+ let value = e.target.value;
4370
+ if (isNumberField) {
4371
+ value = e.target.value === "" ? "" : Number(e.target.value);
4372
+ }
4373
+ field.onChange(value);
4374
+ }
4367
4375
  }
4368
4376
  ),
4369
4377
  showInputGroupAddons && /* @__PURE__ */ jsxs(InputGroupAddon, { align: "inline-end", children: [
@@ -5592,6 +5600,7 @@ var DynamicForm = ({
5592
5600
  errorAlertPosition = "up",
5593
5601
  withCard = false,
5594
5602
  submitBtnClass = "",
5603
+ listBtnConfig = [],
5595
5604
  submitBtnLabel = "Guardar"
5596
5605
  }) => {
5597
5606
  const [isPending, startTransition] = useTransition();
@@ -5642,23 +5651,38 @@ var DynamicForm = ({
5642
5651
  /* @__PURE__ */ jsx(FormFieldsGrid, { fields, form, readOnly }),
5643
5652
  children && /* @__PURE__ */ jsx("div", { className: "flex flex-row items-center gap-2 w-full h-full", children })
5644
5653
  ] }),
5645
- !readOnly && /* @__PURE__ */ jsx("div", { className: "flex flex-row gap-2 justify-end items-end", children: /* @__PURE__ */ jsx(
5646
- Button,
5647
- {
5648
- type: onClick ? "button" : "submit",
5649
- size: "lg",
5650
- className: submitBtnClass,
5651
- disabled: isPending,
5652
- onClick: onClick ? handleClick : void 0,
5653
- children: isPending ? /* @__PURE__ */ jsxs(Fragment, { children: [
5654
- /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 mr-2 animate-spin" }),
5655
- "Guardando..."
5656
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
5657
- /* @__PURE__ */ jsx(Save, { className: "h-4 w-4 mr-2" }),
5658
- submitBtnLabel
5659
- ] })
5660
- }
5661
- ) })
5654
+ /* @__PURE__ */ jsxs(ButtonGroup, { className: "flex flex-row w-full", children: [
5655
+ listBtnConfig.map((btn, key) => /* @__PURE__ */ jsx(
5656
+ Button,
5657
+ {
5658
+ type: btn.btnType,
5659
+ size: "lg",
5660
+ className: submitBtnClass,
5661
+ variant: btn.variant,
5662
+ onClick: btn.onClick,
5663
+ disabled: btn.disabled,
5664
+ children: btn.label
5665
+ },
5666
+ key
5667
+ )),
5668
+ !readOnly && /* @__PURE__ */ jsx(
5669
+ Button,
5670
+ {
5671
+ type: onClick ? "button" : "submit",
5672
+ size: "lg",
5673
+ className: submitBtnClass,
5674
+ disabled: isPending,
5675
+ onClick: onClick ? handleClick : void 0,
5676
+ children: isPending ? /* @__PURE__ */ jsxs(Fragment, { children: [
5677
+ /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 mr-2 animate-spin" }),
5678
+ "Guardando..."
5679
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
5680
+ /* @__PURE__ */ jsx(Save, { className: "h-4 w-4 mr-2" }),
5681
+ submitBtnLabel
5682
+ ] })
5683
+ }
5684
+ )
5685
+ ] })
5662
5686
  ]
5663
5687
  }
5664
5688
  ) }),