shadcn-zod-formkit 1.17.0 → 1.18.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.d.mts CHANGED
@@ -203,6 +203,7 @@ interface Props$4<T extends Record<string, any>> {
203
203
  fields: Array<FieldProps<T> | FieldProps<T>[]>;
204
204
  record?: Partial<T>;
205
205
  onSubmit?: (resp: FormResp<T>) => void;
206
+ onClick?: (resp: FormResp<T>) => void;
206
207
  extraValidations?: ((schema: ZodObject<any>) => ZodObject<any>)[];
207
208
  withErrorsAlert?: boolean;
208
209
  errorAlertPosition?: alertPositionType;
@@ -212,7 +213,7 @@ interface Props$4<T extends Record<string, any>> {
212
213
  children?: ReactNode;
213
214
  childrenHeader?: ReactNode;
214
215
  }
215
- declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onSubmit, extraValidations, children, childrenHeader, showIcon, showFormHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, submitBtnLabel, }: Props$4<T>) => react_jsx_runtime.JSX.Element;
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;
216
217
 
217
218
  declare const DynamicFormExample: () => react_jsx_runtime.JSX.Element;
218
219
  declare const mockFields: Array<FieldProps | FieldProps[]>;
package/dist/index.d.ts CHANGED
@@ -203,6 +203,7 @@ interface Props$4<T extends Record<string, any>> {
203
203
  fields: Array<FieldProps<T> | FieldProps<T>[]>;
204
204
  record?: Partial<T>;
205
205
  onSubmit?: (resp: FormResp<T>) => void;
206
+ onClick?: (resp: FormResp<T>) => void;
206
207
  extraValidations?: ((schema: ZodObject<any>) => ZodObject<any>)[];
207
208
  withErrorsAlert?: boolean;
208
209
  errorAlertPosition?: alertPositionType;
@@ -212,7 +213,7 @@ interface Props$4<T extends Record<string, any>> {
212
213
  children?: ReactNode;
213
214
  childrenHeader?: ReactNode;
214
215
  }
215
- declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onSubmit, extraValidations, children, childrenHeader, showIcon, showFormHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, submitBtnLabel, }: Props$4<T>) => react_jsx_runtime.JSX.Element;
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;
216
217
 
217
218
  declare const DynamicFormExample: () => react_jsx_runtime.JSX.Element;
218
219
  declare const mockFields: Array<FieldProps | FieldProps[]>;
package/dist/index.mjs CHANGED
@@ -5582,10 +5582,11 @@ var DynamicForm = ({
5582
5582
  readOnly = false,
5583
5583
  record = {},
5584
5584
  onSubmit,
5585
+ onClick,
5585
5586
  extraValidations,
5586
5587
  children,
5587
5588
  childrenHeader,
5588
- showIcon = true,
5589
+ showIcon = false,
5589
5590
  showFormHeader = true,
5590
5591
  withErrorsAlert = true,
5591
5592
  errorAlertPosition = "up",
@@ -5606,24 +5607,25 @@ var DynamicForm = ({
5606
5607
  }, [initialValues, form]);
5607
5608
  const handleSubmit = (data) => {
5608
5609
  if (readOnly) return;
5609
- try {
5610
- startTransition(async () => {
5611
- const resp = { data, form };
5612
- onSubmit?.(resp);
5613
- });
5614
- } catch (error) {
5615
- console.error("Ocurri\xF3 un error al enviar el formulario.", error);
5616
- }
5610
+ startTransition(() => {
5611
+ const resp = { data, form };
5612
+ onSubmit?.(resp);
5613
+ });
5614
+ };
5615
+ const handleClick = async () => {
5616
+ if (!onClick) return;
5617
+ const isValid2 = await form.trigger();
5618
+ if (!isValid2) return;
5619
+ const data = form.getValues();
5620
+ const resp = { data, form };
5621
+ onClick(resp);
5617
5622
  };
5618
5623
  const formContent = /* @__PURE__ */ jsxs("div", { children: [
5619
5624
  showFormHeader && /* @__PURE__ */ jsxs(CardTitle, { className: "flex flex-row items-center gap-2 p-2 border-b", children: [
5620
5625
  /* @__PURE__ */ jsxs("div", { className: "flex flex-row items-center gap-2 w-full", children: [
5621
5626
  showIcon && /* @__PURE__ */ jsx(Pencil, { className: "h-5 w-5" }),
5622
5627
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
5623
- /* @__PURE__ */ jsxs(CardTitle, { className: "text-xl", children: [
5624
- formTitle,
5625
- " "
5626
- ] }),
5628
+ /* @__PURE__ */ jsx("div", { className: "text-xl", children: formTitle }),
5627
5629
  formSubTitle && /* @__PURE__ */ jsx(CardDescription, { children: formSubTitle })
5628
5630
  ] })
5629
5631
  ] }),
@@ -5640,13 +5642,23 @@ var DynamicForm = ({
5640
5642
  /* @__PURE__ */ jsx(FormFieldsGrid, { fields, form, readOnly }),
5641
5643
  children && /* @__PURE__ */ jsx("div", { className: "flex flex-row items-center gap-2 w-full h-full", children })
5642
5644
  ] }),
5643
- !readOnly && /* @__PURE__ */ jsx("div", { className: "flex flex-row gap-2 justify-end items-end", children: /* @__PURE__ */ jsx(Button, { type: "submit", size: "lg", className: submitBtnClass, disabled: isPending, children: isPending ? /* @__PURE__ */ jsxs(Fragment, { children: [
5644
- /* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 mr-2 animate-spin" }),
5645
- "Guardando..."
5646
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
5647
- /* @__PURE__ */ jsx(Save, { className: "h-4 w-4 mr-2" }),
5648
- submitBtnLabel
5649
- ] }) }) })
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
+ ) })
5650
5662
  ]
5651
5663
  }
5652
5664
  ) }),