shadcn-zod-formkit 1.13.0 → 1.15.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 +50 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +7 -4
- package/dist/index.d.ts +7 -4
- package/dist/index.mjs +50 -18
- package/dist/index.mjs.map +1 -1
- package/dist/shadcn-zod-formkit-1.15.0.tgz +0 -0
- package/package.json +1 -1
- package/dist/shadcn-zod-formkit-1.13.0.tgz +0 -0
package/dist/index.d.mts
CHANGED
|
@@ -80,6 +80,8 @@ declare const inputFieldComp: InputTypes[];
|
|
|
80
80
|
interface FieldProps<T = Record<string, any>> {
|
|
81
81
|
name: keyof T;
|
|
82
82
|
label: string;
|
|
83
|
+
childrenPosition?: 'up' | 'down';
|
|
84
|
+
children?: ReactNode | ((item: any, index: number) => ReactNode);
|
|
83
85
|
defaultValue?: any;
|
|
84
86
|
repeaterFields?: Array<FieldProps | FieldProps[]>;
|
|
85
87
|
minItems?: number;
|
|
@@ -173,12 +175,11 @@ declare enum TextInputType {
|
|
|
173
175
|
PASSWORD = "password"
|
|
174
176
|
}
|
|
175
177
|
|
|
176
|
-
declare abstract class BaseInput
|
|
178
|
+
declare abstract class BaseInput {
|
|
177
179
|
protected readonly input: FieldProps;
|
|
178
180
|
protected readonly form: UseFormReturn;
|
|
179
181
|
protected readonly isSubmitting?: boolean | undefined;
|
|
180
|
-
|
|
181
|
-
constructor(input: FieldProps, form: UseFormReturn, isSubmitting?: boolean | undefined, children?: ReactNode | ((item: T, index: number) => ReactNode));
|
|
182
|
+
constructor(input: FieldProps, form: UseFormReturn, isSubmitting?: boolean | undefined);
|
|
182
183
|
abstract render(): JSX.Element;
|
|
183
184
|
}
|
|
184
185
|
declare const entityToInputOption: (entitiy: any, name?: string, description?: string, groupedLabel?: string) => InputOption;
|
|
@@ -204,8 +205,10 @@ interface Props$4<T extends Record<string, any>> {
|
|
|
204
205
|
withCard?: boolean;
|
|
205
206
|
submitBtnLabel?: string;
|
|
206
207
|
submitBtnClass?: string;
|
|
208
|
+
children?: ReactNode;
|
|
209
|
+
childrenHeader?: ReactNode;
|
|
207
210
|
}
|
|
208
|
-
declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onSubmit, extraValidations, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, submitBtnLabel, }: Props$4<T>) => react_jsx_runtime.JSX.Element;
|
|
211
|
+
declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onSubmit, extraValidations, children, childrenHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, submitBtnLabel, }: Props$4<T>) => react_jsx_runtime.JSX.Element;
|
|
209
212
|
|
|
210
213
|
declare const DynamicFormExample: () => react_jsx_runtime.JSX.Element;
|
|
211
214
|
declare const mockFields: Array<FieldProps | FieldProps[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -80,6 +80,8 @@ declare const inputFieldComp: InputTypes[];
|
|
|
80
80
|
interface FieldProps<T = Record<string, any>> {
|
|
81
81
|
name: keyof T;
|
|
82
82
|
label: string;
|
|
83
|
+
childrenPosition?: 'up' | 'down';
|
|
84
|
+
children?: ReactNode | ((item: any, index: number) => ReactNode);
|
|
83
85
|
defaultValue?: any;
|
|
84
86
|
repeaterFields?: Array<FieldProps | FieldProps[]>;
|
|
85
87
|
minItems?: number;
|
|
@@ -173,12 +175,11 @@ declare enum TextInputType {
|
|
|
173
175
|
PASSWORD = "password"
|
|
174
176
|
}
|
|
175
177
|
|
|
176
|
-
declare abstract class BaseInput
|
|
178
|
+
declare abstract class BaseInput {
|
|
177
179
|
protected readonly input: FieldProps;
|
|
178
180
|
protected readonly form: UseFormReturn;
|
|
179
181
|
protected readonly isSubmitting?: boolean | undefined;
|
|
180
|
-
|
|
181
|
-
constructor(input: FieldProps, form: UseFormReturn, isSubmitting?: boolean | undefined, children?: ReactNode | ((item: T, index: number) => ReactNode));
|
|
182
|
+
constructor(input: FieldProps, form: UseFormReturn, isSubmitting?: boolean | undefined);
|
|
182
183
|
abstract render(): JSX.Element;
|
|
183
184
|
}
|
|
184
185
|
declare const entityToInputOption: (entitiy: any, name?: string, description?: string, groupedLabel?: string) => InputOption;
|
|
@@ -204,8 +205,10 @@ interface Props$4<T extends Record<string, any>> {
|
|
|
204
205
|
withCard?: boolean;
|
|
205
206
|
submitBtnLabel?: string;
|
|
206
207
|
submitBtnClass?: string;
|
|
208
|
+
children?: ReactNode;
|
|
209
|
+
childrenHeader?: ReactNode;
|
|
207
210
|
}
|
|
208
|
-
declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onSubmit, extraValidations, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, submitBtnLabel, }: Props$4<T>) => react_jsx_runtime.JSX.Element;
|
|
211
|
+
declare const DynamicForm: <T extends Record<string, any>>({ formTitle, formSubTitle, fields, readOnly, record, onSubmit, extraValidations, children, childrenHeader, withErrorsAlert, errorAlertPosition, withCard, submitBtnClass, submitBtnLabel, }: Props$4<T>) => react_jsx_runtime.JSX.Element;
|
|
209
212
|
|
|
210
213
|
declare const DynamicFormExample: () => react_jsx_runtime.JSX.Element;
|
|
211
214
|
declare const mockFields: Array<FieldProps | FieldProps[]>;
|
package/dist/index.mjs
CHANGED
|
@@ -159,11 +159,10 @@ var validationMessages = {
|
|
|
159
159
|
|
|
160
160
|
// src/components/custom/form/inputs/base/base-input.ts
|
|
161
161
|
var BaseInput = class {
|
|
162
|
-
constructor(input, form, isSubmitting
|
|
162
|
+
constructor(input, form, isSubmitting) {
|
|
163
163
|
this.input = input;
|
|
164
164
|
this.form = form;
|
|
165
165
|
this.isSubmitting = isSubmitting;
|
|
166
|
-
this.children = children;
|
|
167
166
|
}
|
|
168
167
|
};
|
|
169
168
|
var entityToInputOption = (entitiy, name = "name", description = "description", groupedLabel) => ({
|
|
@@ -5366,6 +5365,7 @@ var getFieldLabel = (fieldErrorKey, fields) => {
|
|
|
5366
5365
|
const foundField = fields.find((field) => field.name === fieldErrorKey);
|
|
5367
5366
|
return foundField?.label ?? fieldErrorKey;
|
|
5368
5367
|
};
|
|
5368
|
+
var isRenderableChild = (c) => c !== void 0 && c !== null && typeof c !== "function";
|
|
5369
5369
|
var FormFieldsGrid = ({
|
|
5370
5370
|
fields,
|
|
5371
5371
|
form,
|
|
@@ -5375,23 +5375,44 @@ var FormFieldsGrid = ({
|
|
|
5375
5375
|
gap = "gap-2"
|
|
5376
5376
|
}) => {
|
|
5377
5377
|
return /* @__PURE__ */ jsx("div", { className: `w-full grid grid-cols-1 ${gap} ${className}`, children: fields.map(
|
|
5378
|
-
(
|
|
5379
|
-
"
|
|
5378
|
+
(inputOrGroup, idx) => Array.isArray(inputOrGroup) ? /* @__PURE__ */ jsx(
|
|
5379
|
+
"div",
|
|
5380
5380
|
{
|
|
5381
|
-
className: "w-full flex flex-row
|
|
5382
|
-
children:
|
|
5383
|
-
|
|
5384
|
-
|
|
5381
|
+
className: "w-full flex flex-row items-start gap-4 py-3",
|
|
5382
|
+
children: inputOrGroup.map((field, subIdx) => {
|
|
5383
|
+
const fieldCopy = {
|
|
5384
|
+
...field,
|
|
5385
|
+
disabled: readOnly ? true : field.disabled
|
|
5386
|
+
};
|
|
5387
|
+
const renderInlineChild = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
|
|
5388
|
+
const renderInlineChildDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
|
|
5389
|
+
return /* @__PURE__ */ jsxs("div", { className: "w-full px-2", children: [
|
|
5390
|
+
renderInlineChild && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children }),
|
|
5391
|
+
InputFactory.create(fieldCopy, form, isPending),
|
|
5392
|
+
renderInlineChildDown && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children })
|
|
5393
|
+
] }, `field-${idx}-${subIdx}`);
|
|
5385
5394
|
})
|
|
5386
5395
|
},
|
|
5387
5396
|
`field-group-${idx}`
|
|
5388
5397
|
) : /* @__PURE__ */ jsx(
|
|
5389
|
-
"
|
|
5398
|
+
"div",
|
|
5390
5399
|
{
|
|
5391
5400
|
className: "flex flex-col justify-between py-3 w-full px-2",
|
|
5392
|
-
children:
|
|
5401
|
+
children: (() => {
|
|
5402
|
+
const fieldCopy = {
|
|
5403
|
+
...inputOrGroup,
|
|
5404
|
+
disabled: readOnly ? true : inputOrGroup.disabled
|
|
5405
|
+
};
|
|
5406
|
+
const renderUp = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
|
|
5407
|
+
const renderDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
|
|
5408
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
5409
|
+
renderUp && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children }),
|
|
5410
|
+
InputFactory.create(fieldCopy, form, isPending),
|
|
5411
|
+
renderDown && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children })
|
|
5412
|
+
] });
|
|
5413
|
+
})()
|
|
5393
5414
|
},
|
|
5394
|
-
`field-
|
|
5415
|
+
`field-single-${idx}`
|
|
5395
5416
|
)
|
|
5396
5417
|
) });
|
|
5397
5418
|
};
|
|
@@ -5403,6 +5424,8 @@ var DynamicForm = ({
|
|
|
5403
5424
|
record = {},
|
|
5404
5425
|
onSubmit,
|
|
5405
5426
|
extraValidations,
|
|
5427
|
+
children,
|
|
5428
|
+
childrenHeader,
|
|
5406
5429
|
withErrorsAlert = true,
|
|
5407
5430
|
errorAlertPosition = "up",
|
|
5408
5431
|
withCard = false,
|
|
@@ -5432,12 +5455,18 @@ var DynamicForm = ({
|
|
|
5432
5455
|
}
|
|
5433
5456
|
};
|
|
5434
5457
|
const formContent = /* @__PURE__ */ jsxs("div", { children: [
|
|
5435
|
-
/* @__PURE__ */ jsxs(CardTitle, { className: "flex items-center gap-2 p-2 border-b", children: [
|
|
5436
|
-
/* @__PURE__ */
|
|
5437
|
-
|
|
5438
|
-
/* @__PURE__ */
|
|
5439
|
-
|
|
5440
|
-
|
|
5458
|
+
/* @__PURE__ */ jsxs(CardTitle, { className: "flex flex-row items-center gap-2 p-2 border-b", children: [
|
|
5459
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-row items-center gap-2 w-full", children: [
|
|
5460
|
+
/* @__PURE__ */ jsx(Pencil, { className: "h-5 w-5" }),
|
|
5461
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
5462
|
+
/* @__PURE__ */ jsxs(CardTitle, { className: "text-xl", children: [
|
|
5463
|
+
formTitle,
|
|
5464
|
+
" "
|
|
5465
|
+
] }),
|
|
5466
|
+
formSubTitle && /* @__PURE__ */ jsx(CardDescription, { children: formSubTitle })
|
|
5467
|
+
] })
|
|
5468
|
+
] }),
|
|
5469
|
+
childrenHeader && /* @__PURE__ */ jsx("div", { className: "flex flex-row items-center gap-2 w-full h-full", children: childrenHeader })
|
|
5441
5470
|
] }),
|
|
5442
5471
|
withErrorsAlert && errorAlertPosition === "up" && /* @__PURE__ */ jsx(FormErrorsAlert, { formState: form.formState, fields }),
|
|
5443
5472
|
/* @__PURE__ */ jsx(Form, { ...form, children: /* @__PURE__ */ jsxs(
|
|
@@ -5446,7 +5475,10 @@ var DynamicForm = ({
|
|
|
5446
5475
|
onSubmit: form.handleSubmit(handleSubmit),
|
|
5447
5476
|
className: `flex flex-col gap-2 ${readOnly ? "opacity-70 pointer-events-none select-none" : ""}`,
|
|
5448
5477
|
children: [
|
|
5449
|
-
/* @__PURE__ */
|
|
5478
|
+
/* @__PURE__ */ jsxs("div", { className: "w-full grid grid-cols-1", children: [
|
|
5479
|
+
/* @__PURE__ */ jsx(FormFieldsGrid, { fields, form, readOnly }),
|
|
5480
|
+
children && /* @__PURE__ */ jsx("div", { className: "flex flex-row items-center gap-2 w-full h-full", children })
|
|
5481
|
+
] }),
|
|
5450
5482
|
!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: [
|
|
5451
5483
|
/* @__PURE__ */ jsx(Loader2, { className: "h-4 w-4 mr-2 animate-spin" }),
|
|
5452
5484
|
"Guardando..."
|