shadcn-zod-formkit 1.30.1 → 1.31.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 +63 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +3 -7
- package/dist/index.d.ts +3 -7
- package/dist/index.mjs +63 -41
- package/dist/index.mjs.map +1 -1
- package/dist/shadcn-zod-formkit-1.31.0.tgz +0 -0
- package/package.json +1 -1
- package/dist/shadcn-zod-formkit-1.30.1.tgz +0 -0
package/dist/index.d.mts
CHANGED
|
@@ -88,6 +88,7 @@ type FieldConfig<T, RT = Record<string, any>> = FieldProps<T, RT> | FieldConfig<
|
|
|
88
88
|
interface FieldProps<T = Record<string, any>, RT = Record<string, any>> {
|
|
89
89
|
name: keyof T;
|
|
90
90
|
label: string;
|
|
91
|
+
showWhen?: (values: Record<string, any>) => boolean;
|
|
91
92
|
step?: number;
|
|
92
93
|
withAddBtn?: boolean;
|
|
93
94
|
form?: UseFormReturn<any>;
|
|
@@ -242,8 +243,9 @@ interface Props$i<T extends Record<string, any>> {
|
|
|
242
243
|
children?: ReactNode;
|
|
243
244
|
childrenHeader?: ReactNode;
|
|
244
245
|
listBtnConfig?: BtnConfig[];
|
|
246
|
+
debug?: boolean;
|
|
245
247
|
}
|
|
246
|
-
declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onAnyFieldChange, onSubmit, onClick, extraValidations, children, childrenHeader, showIcon, showFormHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, listBtnConfig, submitBtnLabel, submitBtnLabelSubmiting, withFormWrapper, btnGroupDirection, withSubmitBtn }: Props$i<T>) => react_jsx_runtime.JSX.Element;
|
|
248
|
+
declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onAnyFieldChange, onSubmit, onClick, extraValidations, children, childrenHeader, showIcon, showFormHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, listBtnConfig, submitBtnLabel, submitBtnLabelSubmiting, withFormWrapper, btnGroupDirection, withSubmitBtn, debug }: Props$i<T>) => react_jsx_runtime.JSX.Element;
|
|
247
249
|
|
|
248
250
|
interface Props$h<T> {
|
|
249
251
|
onSubmit?: (resp: FormResp<T>) => void;
|
|
@@ -263,12 +265,6 @@ interface Props$g<T extends Record<string, any> = Record<string, any>> {
|
|
|
263
265
|
className?: string;
|
|
264
266
|
gap?: string;
|
|
265
267
|
}
|
|
266
|
-
/**
|
|
267
|
-
* 📋 FormFieldsGrid
|
|
268
|
-
* Componente reutilizable para renderizar campos en una cuadrícula flexible.
|
|
269
|
-
* - Si un elemento del arreglo es un solo FieldProps → muestra en una línea.
|
|
270
|
-
* - Si es un arreglo de FieldProps → los muestra en una misma fila.
|
|
271
|
-
*/
|
|
272
268
|
declare const FormFieldsGrid: <T extends Record<string, any> = Record<string, any>>({ fields, form, isPending, readOnly, className, gap, }: Props$g<T>) => JSX.Element;
|
|
273
269
|
|
|
274
270
|
interface Props$f<T extends FieldValues = Record<string, any>> {
|
package/dist/index.d.ts
CHANGED
|
@@ -88,6 +88,7 @@ type FieldConfig<T, RT = Record<string, any>> = FieldProps<T, RT> | FieldConfig<
|
|
|
88
88
|
interface FieldProps<T = Record<string, any>, RT = Record<string, any>> {
|
|
89
89
|
name: keyof T;
|
|
90
90
|
label: string;
|
|
91
|
+
showWhen?: (values: Record<string, any>) => boolean;
|
|
91
92
|
step?: number;
|
|
92
93
|
withAddBtn?: boolean;
|
|
93
94
|
form?: UseFormReturn<any>;
|
|
@@ -242,8 +243,9 @@ interface Props$i<T extends Record<string, any>> {
|
|
|
242
243
|
children?: ReactNode;
|
|
243
244
|
childrenHeader?: ReactNode;
|
|
244
245
|
listBtnConfig?: BtnConfig[];
|
|
246
|
+
debug?: boolean;
|
|
245
247
|
}
|
|
246
|
-
declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onAnyFieldChange, onSubmit, onClick, extraValidations, children, childrenHeader, showIcon, showFormHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, listBtnConfig, submitBtnLabel, submitBtnLabelSubmiting, withFormWrapper, btnGroupDirection, withSubmitBtn }: Props$i<T>) => react_jsx_runtime.JSX.Element;
|
|
248
|
+
declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onAnyFieldChange, onSubmit, onClick, extraValidations, children, childrenHeader, showIcon, showFormHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, listBtnConfig, submitBtnLabel, submitBtnLabelSubmiting, withFormWrapper, btnGroupDirection, withSubmitBtn, debug }: Props$i<T>) => react_jsx_runtime.JSX.Element;
|
|
247
249
|
|
|
248
250
|
interface Props$h<T> {
|
|
249
251
|
onSubmit?: (resp: FormResp<T>) => void;
|
|
@@ -263,12 +265,6 @@ interface Props$g<T extends Record<string, any> = Record<string, any>> {
|
|
|
263
265
|
className?: string;
|
|
264
266
|
gap?: string;
|
|
265
267
|
}
|
|
266
|
-
/**
|
|
267
|
-
* 📋 FormFieldsGrid
|
|
268
|
-
* Componente reutilizable para renderizar campos en una cuadrícula flexible.
|
|
269
|
-
* - Si un elemento del arreglo es un solo FieldProps → muestra en una línea.
|
|
270
|
-
* - Si es un arreglo de FieldProps → los muestra en una misma fila.
|
|
271
|
-
*/
|
|
272
268
|
declare const FormFieldsGrid: <T extends Record<string, any> = Record<string, any>>({ fields, form, isPending, readOnly, className, gap, }: Props$g<T>) => JSX.Element;
|
|
273
269
|
|
|
274
270
|
interface Props$f<T extends FieldValues = Record<string, any>> {
|
package/dist/index.mjs
CHANGED
|
@@ -6129,6 +6129,16 @@ var getFieldLabel = (fieldErrorKey, fields) => {
|
|
|
6129
6129
|
return foundField?.label ?? fieldErrorKey;
|
|
6130
6130
|
};
|
|
6131
6131
|
var isRenderableChild = (c) => c !== void 0 && c !== null && typeof c !== "function";
|
|
6132
|
+
var shouldShowField = (field, values) => {
|
|
6133
|
+
if (typeof field.showWhen === "function") {
|
|
6134
|
+
try {
|
|
6135
|
+
return !!field.showWhen(values);
|
|
6136
|
+
} catch {
|
|
6137
|
+
return true;
|
|
6138
|
+
}
|
|
6139
|
+
}
|
|
6140
|
+
return true;
|
|
6141
|
+
};
|
|
6132
6142
|
var FormFieldsGrid = ({
|
|
6133
6143
|
fields,
|
|
6134
6144
|
form,
|
|
@@ -6137,47 +6147,54 @@ var FormFieldsGrid = ({
|
|
|
6137
6147
|
className = "",
|
|
6138
6148
|
gap = "gap-2"
|
|
6139
6149
|
}) => {
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
|
|
6158
|
-
|
|
6159
|
-
|
|
6160
|
-
|
|
6150
|
+
const values = form.watch();
|
|
6151
|
+
return /* @__PURE__ */ jsx("div", { className: `w-full grid grid-cols-1 ${gap} ${className}`, children: fields.map((inputOrGroup, idx) => {
|
|
6152
|
+
if (Array.isArray(inputOrGroup)) {
|
|
6153
|
+
const visibleFields = inputOrGroup.filter(
|
|
6154
|
+
(f) => shouldShowField(f, values)
|
|
6155
|
+
);
|
|
6156
|
+
if (visibleFields.length === 0) return null;
|
|
6157
|
+
return /* @__PURE__ */ jsx(
|
|
6158
|
+
"div",
|
|
6159
|
+
{
|
|
6160
|
+
className: "w-full flex flex-row items-start gap-4 py-3",
|
|
6161
|
+
children: visibleFields.map((field, subIdx) => {
|
|
6162
|
+
const fieldCopy2 = {
|
|
6163
|
+
...field,
|
|
6164
|
+
disabled: readOnly ? true : field.disabled
|
|
6165
|
+
};
|
|
6166
|
+
const renderUp2 = fieldCopy2.childrenPosition !== "down" && isRenderableChild(fieldCopy2.children);
|
|
6167
|
+
const renderDown2 = fieldCopy2.childrenPosition === "down" && isRenderableChild(fieldCopy2.children);
|
|
6168
|
+
return /* @__PURE__ */ jsxs("div", { className: "w-full px-2", children: [
|
|
6169
|
+
renderUp2 && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy2.children }),
|
|
6170
|
+
InputFactory.create(fieldCopy2, form, isPending),
|
|
6171
|
+
renderDown2 && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy2.children })
|
|
6172
|
+
] }, `field-${idx}-${subIdx}`);
|
|
6173
|
+
})
|
|
6174
|
+
},
|
|
6175
|
+
`field-group-${idx}`
|
|
6176
|
+
);
|
|
6177
|
+
}
|
|
6178
|
+
if (!shouldShowField(inputOrGroup, values)) return null;
|
|
6179
|
+
const fieldCopy = {
|
|
6180
|
+
...inputOrGroup,
|
|
6181
|
+
disabled: readOnly ? true : inputOrGroup.disabled
|
|
6182
|
+
};
|
|
6183
|
+
const renderUp = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
|
|
6184
|
+
const renderDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
|
|
6185
|
+
return /* @__PURE__ */ jsxs(
|
|
6161
6186
|
"div",
|
|
6162
6187
|
{
|
|
6163
6188
|
className: "flex flex-col justify-between py-3 w-full px-2",
|
|
6164
|
-
children:
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
const renderUp = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
|
|
6170
|
-
const renderDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
|
|
6171
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
6172
|
-
renderUp && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children }),
|
|
6173
|
-
InputFactory.create(fieldCopy, form, isPending),
|
|
6174
|
-
renderDown && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children })
|
|
6175
|
-
] });
|
|
6176
|
-
})()
|
|
6189
|
+
children: [
|
|
6190
|
+
renderUp && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children }),
|
|
6191
|
+
InputFactory.create(fieldCopy, form, isPending),
|
|
6192
|
+
renderDown && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children })
|
|
6193
|
+
]
|
|
6177
6194
|
},
|
|
6178
6195
|
`field-single-${idx}`
|
|
6179
|
-
)
|
|
6180
|
-
) });
|
|
6196
|
+
);
|
|
6197
|
+
}) });
|
|
6181
6198
|
};
|
|
6182
6199
|
var DynamicForm = ({
|
|
6183
6200
|
formTitle,
|
|
@@ -6202,7 +6219,8 @@ var DynamicForm = ({
|
|
|
6202
6219
|
submitBtnLabelSubmiting = "Guardando...",
|
|
6203
6220
|
withFormWrapper = true,
|
|
6204
6221
|
btnGroupDirection = "flex-end",
|
|
6205
|
-
withSubmitBtn = true
|
|
6222
|
+
withSubmitBtn = true,
|
|
6223
|
+
debug = false
|
|
6206
6224
|
}) => {
|
|
6207
6225
|
const [isPending, startTransition] = useTransition();
|
|
6208
6226
|
const schema = useMemo(() => {
|
|
@@ -6229,7 +6247,7 @@ var DynamicForm = ({
|
|
|
6229
6247
|
if (!onClick) return;
|
|
6230
6248
|
const isValid2 = await form.trigger();
|
|
6231
6249
|
if (!isValid2) return;
|
|
6232
|
-
const data = form.
|
|
6250
|
+
const data = form.watch();
|
|
6233
6251
|
const resp = { data, form };
|
|
6234
6252
|
onClick(resp);
|
|
6235
6253
|
};
|
|
@@ -6314,13 +6332,17 @@ var DynamicForm = ({
|
|
|
6314
6332
|
if (!withCard) return formContent;
|
|
6315
6333
|
return /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(CardContent, { children: formContent }) });
|
|
6316
6334
|
};
|
|
6317
|
-
var FormWrapper = ({ form, handleSubmit, children, readOnly }) => {
|
|
6318
|
-
|
|
6335
|
+
var FormWrapper = ({ form, handleSubmit, children, readOnly, debug }) => {
|
|
6336
|
+
const allValues = form.watch();
|
|
6337
|
+
return /* @__PURE__ */ jsx(Form, { ...form, children: /* @__PURE__ */ jsxs(
|
|
6319
6338
|
"form",
|
|
6320
6339
|
{
|
|
6321
6340
|
onSubmit: form.handleSubmit(handleSubmit),
|
|
6322
6341
|
className: `flex flex-col gap-2 ${readOnly ? "opacity-70 pointer-events-none select-none" : ""}`,
|
|
6323
|
-
children
|
|
6342
|
+
children: [
|
|
6343
|
+
children,
|
|
6344
|
+
debug && /* @__PURE__ */ jsx("pre", { className: "mt-4 p-3 bg-muted text-xs rounded", children: JSON.stringify(allValues, null, 2) })
|
|
6345
|
+
]
|
|
6324
6346
|
}
|
|
6325
6347
|
) });
|
|
6326
6348
|
};
|