shadcn-zod-formkit 1.30.1 → 1.33.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 +131 -103
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +16 -8
- package/dist/index.d.ts +16 -8
- package/dist/index.mjs +132 -104
- package/dist/index.mjs.map +1 -1
- package/dist/shadcn-zod-formkit-1.33.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,15 +243,28 @@ interface Props$i<T extends Record<string, any>> {
|
|
|
242
243
|
children?: ReactNode;
|
|
243
244
|
childrenHeader?: ReactNode;
|
|
244
245
|
listBtnConfig?: BtnConfig[];
|
|
246
|
+
debug?: boolean;
|
|
247
|
+
isWrapInWizard?: boolean;
|
|
248
|
+
currentStep?: number;
|
|
249
|
+
totalSteps?: number;
|
|
245
250
|
}
|
|
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;
|
|
251
|
+
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, isWrapInWizard, totalSteps, currentStep, }: Props$i<T>) => react_jsx_runtime.JSX.Element;
|
|
247
252
|
|
|
253
|
+
interface WizardRenderProps<T> {
|
|
254
|
+
stepFields: FieldProps<T>[];
|
|
255
|
+
currentStep: number;
|
|
256
|
+
totalSteps: number;
|
|
257
|
+
setCurrentStep: Dispatch<SetStateAction<number>>;
|
|
258
|
+
}
|
|
248
259
|
interface Props$h<T> {
|
|
249
260
|
onSubmit?: (resp: FormResp<T>) => void;
|
|
250
261
|
fields: FieldConfig<T>[];
|
|
251
262
|
record: any;
|
|
263
|
+
children?: (props: WizardRenderProps<T>) => ReactNode;
|
|
264
|
+
isWrapInWizard?: boolean;
|
|
265
|
+
skipSteps?: boolean;
|
|
252
266
|
}
|
|
253
|
-
declare const WizardForm: <T extends Record<string, any>>({ fields, record, onSubmit, }: Props$h<T>) => react_jsx_runtime.JSX.Element;
|
|
267
|
+
declare const WizardForm: <T extends Record<string, any>>({ fields, record, onSubmit, children, isWrapInWizard, skipSteps, }: Props$h<T>) => react_jsx_runtime.JSX.Element;
|
|
254
268
|
|
|
255
269
|
declare const DynamicFormExample: () => react_jsx_runtime.JSX.Element;
|
|
256
270
|
declare const mockFields: Array<FieldProps | FieldProps[]>;
|
|
@@ -263,12 +277,6 @@ interface Props$g<T extends Record<string, any> = Record<string, any>> {
|
|
|
263
277
|
className?: string;
|
|
264
278
|
gap?: string;
|
|
265
279
|
}
|
|
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
280
|
declare const FormFieldsGrid: <T extends Record<string, any> = Record<string, any>>({ fields, form, isPending, readOnly, className, gap, }: Props$g<T>) => JSX.Element;
|
|
273
281
|
|
|
274
282
|
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,15 +243,28 @@ interface Props$i<T extends Record<string, any>> {
|
|
|
242
243
|
children?: ReactNode;
|
|
243
244
|
childrenHeader?: ReactNode;
|
|
244
245
|
listBtnConfig?: BtnConfig[];
|
|
246
|
+
debug?: boolean;
|
|
247
|
+
isWrapInWizard?: boolean;
|
|
248
|
+
currentStep?: number;
|
|
249
|
+
totalSteps?: number;
|
|
245
250
|
}
|
|
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;
|
|
251
|
+
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, isWrapInWizard, totalSteps, currentStep, }: Props$i<T>) => react_jsx_runtime.JSX.Element;
|
|
247
252
|
|
|
253
|
+
interface WizardRenderProps<T> {
|
|
254
|
+
stepFields: FieldProps<T>[];
|
|
255
|
+
currentStep: number;
|
|
256
|
+
totalSteps: number;
|
|
257
|
+
setCurrentStep: Dispatch<SetStateAction<number>>;
|
|
258
|
+
}
|
|
248
259
|
interface Props$h<T> {
|
|
249
260
|
onSubmit?: (resp: FormResp<T>) => void;
|
|
250
261
|
fields: FieldConfig<T>[];
|
|
251
262
|
record: any;
|
|
263
|
+
children?: (props: WizardRenderProps<T>) => ReactNode;
|
|
264
|
+
isWrapInWizard?: boolean;
|
|
265
|
+
skipSteps?: boolean;
|
|
252
266
|
}
|
|
253
|
-
declare const WizardForm: <T extends Record<string, any>>({ fields, record, onSubmit, }: Props$h<T>) => react_jsx_runtime.JSX.Element;
|
|
267
|
+
declare const WizardForm: <T extends Record<string, any>>({ fields, record, onSubmit, children, isWrapInWizard, skipSteps, }: Props$h<T>) => react_jsx_runtime.JSX.Element;
|
|
254
268
|
|
|
255
269
|
declare const DynamicFormExample: () => react_jsx_runtime.JSX.Element;
|
|
256
270
|
declare const mockFields: Array<FieldProps | FieldProps[]>;
|
|
@@ -263,12 +277,6 @@ interface Props$g<T extends Record<string, any> = Record<string, any>> {
|
|
|
263
277
|
className?: string;
|
|
264
278
|
gap?: string;
|
|
265
279
|
}
|
|
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
280
|
declare const FormFieldsGrid: <T extends Record<string, any> = Record<string, any>>({ fields, form, isPending, readOnly, className, gap, }: Props$g<T>) => JSX.Element;
|
|
273
281
|
|
|
274
282
|
interface Props$f<T extends FieldValues = Record<string, any>> {
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, CheckIcon, XIcon, MinusIcon, CircleIcon, GripVerticalIcon, ChevronUpIcon, SearchIcon, ChevronsUpDown, Check, CalendarIcon, EyeOff, Eye, Upload,
|
|
1
|
+
import { ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, CheckIcon, XIcon, MinusIcon, CircleIcon, GripVerticalIcon, ChevronUpIcon, SearchIcon, ChevronsUpDown, Check, Info, CalendarIcon, EyeOff, Eye, Upload, Trash2, Plus, 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';
|
|
@@ -4248,6 +4248,7 @@ var DateInput = class extends BaseInput {
|
|
|
4248
4248
|
};
|
|
4249
4249
|
var FieldTimeInput = ({ form, input, isSubmitting }) => {
|
|
4250
4250
|
const [isValid2, setIsValid] = useState(isValidField(input, form));
|
|
4251
|
+
const infoTooltip = input?.infoTooltip;
|
|
4251
4252
|
const groupConfig = input.inputGroupConfig;
|
|
4252
4253
|
const autoValidate = groupConfig?.autoValidIcons ?? input.zodType ? true : false;
|
|
4253
4254
|
const iconValidState = /* @__PURE__ */ jsx(CircleCheck, { style: { color: "#00bf3e" } });
|
|
@@ -4280,27 +4281,34 @@ var FieldTimeInput = ({ form, input, isSubmitting }) => {
|
|
|
4280
4281
|
return /* @__PURE__ */ jsxs(FormItem, { children: [
|
|
4281
4282
|
/* @__PURE__ */ jsx(FormLabel, { children: /* @__PURE__ */ jsx("b", { children: input.label }) }),
|
|
4282
4283
|
/* @__PURE__ */ jsxs(Popover, { children: [
|
|
4283
|
-
/* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4284
|
+
/* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsxs(InputGroup, { className: "flex flex-row gap-1", children: [
|
|
4285
|
+
infoTooltip && /* @__PURE__ */ jsxs(Tooltip, { children: [
|
|
4286
|
+
/* @__PURE__ */ jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx(Info, { size: 20 }) }),
|
|
4287
|
+
/* @__PURE__ */ jsx(TooltipContent, { children: /* @__PURE__ */ jsx("p", { children: infoTooltip }) })
|
|
4288
|
+
] }),
|
|
4289
|
+
/* @__PURE__ */ jsxs(
|
|
4290
|
+
Button,
|
|
4291
|
+
{
|
|
4292
|
+
variant: "outline",
|
|
4293
|
+
type: "button",
|
|
4294
|
+
className: cn(
|
|
4295
|
+
"w-full justify-start text-left py-0.5 ",
|
|
4296
|
+
!date && "text-muted-foreground"
|
|
4297
|
+
),
|
|
4298
|
+
children: [
|
|
4299
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-1 items-center gap-1 justify-start text-left ", children: [
|
|
4300
|
+
/* @__PURE__ */ jsx(CalendarIcon, {}),
|
|
4301
|
+
date ? format(date, "PPP") : /* @__PURE__ */ jsx("span", { children: input.placeHolder ?? "Fecha" })
|
|
4302
|
+
] }),
|
|
4303
|
+
(iconsRight.length > 0 || textRight || autoValidate) && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
4304
|
+
textRight && /* @__PURE__ */ jsx(InputGroupText, { children: textRight }),
|
|
4305
|
+
iconsRight.map((IconComponent, index) => /* @__PURE__ */ jsx(IconComponent, { size: 24, className: "w-6! h-6!" }, index)),
|
|
4306
|
+
autoValidate && /* @__PURE__ */ jsx("div", { children: isSubmitting ? iconLoadingState : isValid2 ? iconValidState : iconInvalidState })
|
|
4307
|
+
] })
|
|
4308
|
+
]
|
|
4309
|
+
}
|
|
4310
|
+
)
|
|
4311
|
+
] }) }) }),
|
|
4304
4312
|
/* @__PURE__ */ jsx(PopoverContent, { className: "w-auto p-0", children: /* @__PURE__ */ jsx(
|
|
4305
4313
|
Calendar,
|
|
4306
4314
|
{
|
|
@@ -6129,6 +6137,16 @@ var getFieldLabel = (fieldErrorKey, fields) => {
|
|
|
6129
6137
|
return foundField?.label ?? fieldErrorKey;
|
|
6130
6138
|
};
|
|
6131
6139
|
var isRenderableChild = (c) => c !== void 0 && c !== null && typeof c !== "function";
|
|
6140
|
+
var shouldShowField = (field, values) => {
|
|
6141
|
+
if (typeof field.showWhen === "function") {
|
|
6142
|
+
try {
|
|
6143
|
+
return !!field.showWhen(values);
|
|
6144
|
+
} catch {
|
|
6145
|
+
return true;
|
|
6146
|
+
}
|
|
6147
|
+
}
|
|
6148
|
+
return true;
|
|
6149
|
+
};
|
|
6132
6150
|
var FormFieldsGrid = ({
|
|
6133
6151
|
fields,
|
|
6134
6152
|
form,
|
|
@@ -6137,47 +6155,54 @@ var FormFieldsGrid = ({
|
|
|
6137
6155
|
className = "",
|
|
6138
6156
|
gap = "gap-2"
|
|
6139
6157
|
}) => {
|
|
6140
|
-
|
|
6141
|
-
|
|
6142
|
-
|
|
6143
|
-
|
|
6144
|
-
|
|
6145
|
-
|
|
6146
|
-
|
|
6147
|
-
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
|
|
6152
|
-
|
|
6153
|
-
|
|
6154
|
-
|
|
6155
|
-
|
|
6156
|
-
|
|
6157
|
-
|
|
6158
|
-
|
|
6159
|
-
|
|
6160
|
-
|
|
6158
|
+
const values = form.watch();
|
|
6159
|
+
return /* @__PURE__ */ jsx("div", { className: `w-full grid grid-cols-1 ${gap} ${className}`, children: fields.map((inputOrGroup, idx) => {
|
|
6160
|
+
if (Array.isArray(inputOrGroup)) {
|
|
6161
|
+
const visibleFields = inputOrGroup.filter(
|
|
6162
|
+
(f) => shouldShowField(f, values)
|
|
6163
|
+
);
|
|
6164
|
+
if (visibleFields.length === 0) return null;
|
|
6165
|
+
return /* @__PURE__ */ jsx(
|
|
6166
|
+
"div",
|
|
6167
|
+
{
|
|
6168
|
+
className: "w-full flex flex-row items-start gap-4 py-3",
|
|
6169
|
+
children: visibleFields.map((field, subIdx) => {
|
|
6170
|
+
const fieldCopy2 = {
|
|
6171
|
+
...field,
|
|
6172
|
+
disabled: readOnly ? true : field.disabled
|
|
6173
|
+
};
|
|
6174
|
+
const renderUp2 = fieldCopy2.childrenPosition !== "down" && isRenderableChild(fieldCopy2.children);
|
|
6175
|
+
const renderDown2 = fieldCopy2.childrenPosition === "down" && isRenderableChild(fieldCopy2.children);
|
|
6176
|
+
return /* @__PURE__ */ jsxs("div", { className: "w-full px-2", children: [
|
|
6177
|
+
renderUp2 && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy2.children }),
|
|
6178
|
+
InputFactory.create(fieldCopy2, form, isPending),
|
|
6179
|
+
renderDown2 && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy2.children })
|
|
6180
|
+
] }, `field-${idx}-${subIdx}`);
|
|
6181
|
+
})
|
|
6182
|
+
},
|
|
6183
|
+
`field-group-${idx}`
|
|
6184
|
+
);
|
|
6185
|
+
}
|
|
6186
|
+
if (!shouldShowField(inputOrGroup, values)) return null;
|
|
6187
|
+
const fieldCopy = {
|
|
6188
|
+
...inputOrGroup,
|
|
6189
|
+
disabled: readOnly ? true : inputOrGroup.disabled
|
|
6190
|
+
};
|
|
6191
|
+
const renderUp = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
|
|
6192
|
+
const renderDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
|
|
6193
|
+
return /* @__PURE__ */ jsxs(
|
|
6161
6194
|
"div",
|
|
6162
6195
|
{
|
|
6163
6196
|
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
|
-
})()
|
|
6197
|
+
children: [
|
|
6198
|
+
renderUp && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children }),
|
|
6199
|
+
InputFactory.create(fieldCopy, form, isPending),
|
|
6200
|
+
renderDown && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children })
|
|
6201
|
+
]
|
|
6177
6202
|
},
|
|
6178
6203
|
`field-single-${idx}`
|
|
6179
|
-
)
|
|
6180
|
-
) });
|
|
6204
|
+
);
|
|
6205
|
+
}) });
|
|
6181
6206
|
};
|
|
6182
6207
|
var DynamicForm = ({
|
|
6183
6208
|
formTitle,
|
|
@@ -6202,7 +6227,11 @@ var DynamicForm = ({
|
|
|
6202
6227
|
submitBtnLabelSubmiting = "Guardando...",
|
|
6203
6228
|
withFormWrapper = true,
|
|
6204
6229
|
btnGroupDirection = "flex-end",
|
|
6205
|
-
withSubmitBtn = true
|
|
6230
|
+
withSubmitBtn = true,
|
|
6231
|
+
debug = false,
|
|
6232
|
+
isWrapInWizard = false,
|
|
6233
|
+
totalSteps = 0,
|
|
6234
|
+
currentStep = 1
|
|
6206
6235
|
}) => {
|
|
6207
6236
|
const [isPending, startTransition] = useTransition();
|
|
6208
6237
|
const schema = useMemo(() => {
|
|
@@ -6229,7 +6258,7 @@ var DynamicForm = ({
|
|
|
6229
6258
|
if (!onClick) return;
|
|
6230
6259
|
const isValid2 = await form.trigger();
|
|
6231
6260
|
if (!isValid2) return;
|
|
6232
|
-
const data = form.
|
|
6261
|
+
const data = form.watch();
|
|
6233
6262
|
const resp = { data, form };
|
|
6234
6263
|
onClick(resp);
|
|
6235
6264
|
};
|
|
@@ -6273,11 +6302,11 @@ var DynamicForm = ({
|
|
|
6273
6302
|
disabled: isPending,
|
|
6274
6303
|
onClick: onClick ? handleClick : void 0,
|
|
6275
6304
|
children: isPending ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
6276
|
-
|
|
6277
|
-
|
|
6305
|
+
submitBtnLabelSubmiting,
|
|
6306
|
+
/* @__PURE__ */ jsx(Loader2, { className: "h-5 w-5 mr-2 animate-spin" })
|
|
6278
6307
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
6279
|
-
|
|
6280
|
-
|
|
6308
|
+
submitBtnLabel,
|
|
6309
|
+
(totalSteps == 0 || totalSteps == currentStep) && /* @__PURE__ */ jsx(Save, { className: "h-5 w-5 mr-2" })
|
|
6281
6310
|
] })
|
|
6282
6311
|
}
|
|
6283
6312
|
)
|
|
@@ -6301,7 +6330,15 @@ var DynamicForm = ({
|
|
|
6301
6330
|
fields
|
|
6302
6331
|
}
|
|
6303
6332
|
),
|
|
6304
|
-
withFormWrapper && /* @__PURE__ */ jsx(
|
|
6333
|
+
withFormWrapper && /* @__PURE__ */ jsx(
|
|
6334
|
+
FormWrapper,
|
|
6335
|
+
{
|
|
6336
|
+
form,
|
|
6337
|
+
isWrapInWizard,
|
|
6338
|
+
handleSubmit,
|
|
6339
|
+
children: formBody
|
|
6340
|
+
}
|
|
6341
|
+
),
|
|
6305
6342
|
!withFormWrapper && formBody,
|
|
6306
6343
|
withErrorsAlert && errorAlertPosition === "down" && /* @__PURE__ */ jsx(
|
|
6307
6344
|
FormErrorsAlert,
|
|
@@ -6314,13 +6351,17 @@ var DynamicForm = ({
|
|
|
6314
6351
|
if (!withCard) return formContent;
|
|
6315
6352
|
return /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(CardContent, { children: formContent }) });
|
|
6316
6353
|
};
|
|
6317
|
-
var FormWrapper = ({ form, handleSubmit, children, readOnly }) => {
|
|
6318
|
-
|
|
6354
|
+
var FormWrapper = ({ form, handleSubmit, children, readOnly, debug, isWrapInWizard }) => {
|
|
6355
|
+
const allValues = form.watch();
|
|
6356
|
+
return /* @__PURE__ */ jsx(Form, { ...form, children: /* @__PURE__ */ jsxs(
|
|
6319
6357
|
"form",
|
|
6320
6358
|
{
|
|
6321
6359
|
onSubmit: form.handleSubmit(handleSubmit),
|
|
6322
6360
|
className: `flex flex-col gap-2 ${readOnly ? "opacity-70 pointer-events-none select-none" : ""}`,
|
|
6323
|
-
children
|
|
6361
|
+
children: [
|
|
6362
|
+
children,
|
|
6363
|
+
debug && /* @__PURE__ */ jsx("pre", { className: "mt-4 p-3 bg-muted text-xs rounded", children: JSON.stringify(allValues, null, 2) })
|
|
6364
|
+
]
|
|
6324
6365
|
}
|
|
6325
6366
|
) });
|
|
6326
6367
|
};
|
|
@@ -6382,7 +6423,10 @@ function Stepper({ steps, currentStep, clickable = false, onStepClick }) {
|
|
|
6382
6423
|
var WizardForm = ({
|
|
6383
6424
|
fields,
|
|
6384
6425
|
record,
|
|
6385
|
-
onSubmit
|
|
6426
|
+
onSubmit,
|
|
6427
|
+
children,
|
|
6428
|
+
isWrapInWizard = true,
|
|
6429
|
+
skipSteps = false
|
|
6386
6430
|
}) => {
|
|
6387
6431
|
const [currentStep, setCurrentStep] = useState(1);
|
|
6388
6432
|
const flattenFields4 = (list) => list.flatMap((f) => Array.isArray(f) ? flattenFields4(f) : f);
|
|
@@ -6393,40 +6437,21 @@ var WizardForm = ({
|
|
|
6393
6437
|
);
|
|
6394
6438
|
const stepFields = allFields.filter((f) => (f.step ?? 1) === currentStep);
|
|
6395
6439
|
return /* @__PURE__ */ jsxs(Card, { className: "flex flex-col gap-4 px-4", children: [
|
|
6396
|
-
/* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */
|
|
6397
|
-
|
|
6398
|
-
|
|
6399
|
-
{
|
|
6400
|
-
|
|
6401
|
-
|
|
6402
|
-
|
|
6403
|
-
|
|
6404
|
-
|
|
6405
|
-
|
|
6406
|
-
|
|
6407
|
-
|
|
6408
|
-
|
|
6409
|
-
|
|
6410
|
-
|
|
6411
|
-
className: "w-32",
|
|
6412
|
-
onClick: () => setCurrentStep((prev) => prev - 1),
|
|
6413
|
-
disabled: currentStep === 1,
|
|
6414
|
-
children: /* @__PURE__ */ jsx(ChevronLeftIcon, {})
|
|
6415
|
-
}
|
|
6416
|
-
),
|
|
6417
|
-
/* @__PURE__ */ jsx(
|
|
6418
|
-
Button,
|
|
6419
|
-
{
|
|
6420
|
-
variant: "outline",
|
|
6421
|
-
className: "w-32",
|
|
6422
|
-
onClick: () => setCurrentStep((prev) => prev + 1),
|
|
6423
|
-
disabled: currentStep > totalSteps,
|
|
6424
|
-
children: /* @__PURE__ */ jsx(ChevronRightIcon, {})
|
|
6425
|
-
}
|
|
6426
|
-
)
|
|
6427
|
-
] })
|
|
6428
|
-
] }) }),
|
|
6429
|
-
/* @__PURE__ */ jsx(
|
|
6440
|
+
/* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx("div", { className: "flex justify-between mb-4 gap-2 px-4", children: /* @__PURE__ */ jsx(
|
|
6441
|
+
Stepper,
|
|
6442
|
+
{
|
|
6443
|
+
steps: Array(totalSteps).fill({}),
|
|
6444
|
+
currentStep,
|
|
6445
|
+
clickable: skipSteps,
|
|
6446
|
+
onStepClick: setCurrentStep
|
|
6447
|
+
}
|
|
6448
|
+
) }) }),
|
|
6449
|
+
children ? children({
|
|
6450
|
+
stepFields,
|
|
6451
|
+
currentStep,
|
|
6452
|
+
totalSteps,
|
|
6453
|
+
setCurrentStep
|
|
6454
|
+
}) : /* @__PURE__ */ jsx(
|
|
6430
6455
|
DynamicForm,
|
|
6431
6456
|
{
|
|
6432
6457
|
record,
|
|
@@ -6435,7 +6460,10 @@ var WizardForm = ({
|
|
|
6435
6460
|
withCard: false,
|
|
6436
6461
|
errorAlertPosition: "down",
|
|
6437
6462
|
fields: stepFields,
|
|
6438
|
-
onSubmit
|
|
6463
|
+
onSubmit,
|
|
6464
|
+
isWrapInWizard: true,
|
|
6465
|
+
currentStep,
|
|
6466
|
+
totalSteps
|
|
6439
6467
|
}
|
|
6440
6468
|
)
|
|
6441
6469
|
] });
|