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.cjs
CHANGED
|
@@ -4285,6 +4285,7 @@ var DateInput = class extends BaseInput {
|
|
|
4285
4285
|
};
|
|
4286
4286
|
var FieldTimeInput = ({ form, input, isSubmitting }) => {
|
|
4287
4287
|
const [isValid2, setIsValid] = React3.useState(isValidField(input, form));
|
|
4288
|
+
const infoTooltip = input?.infoTooltip;
|
|
4288
4289
|
const groupConfig = input.inputGroupConfig;
|
|
4289
4290
|
const autoValidate = groupConfig?.autoValidIcons ?? input.zodType ? true : false;
|
|
4290
4291
|
const iconValidState = /* @__PURE__ */ jsxRuntime.jsx(lucideReact.CircleCheck, { style: { color: "#00bf3e" } });
|
|
@@ -4317,27 +4318,34 @@ var FieldTimeInput = ({ form, input, isSubmitting }) => {
|
|
|
4317
4318
|
return /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { children: [
|
|
4318
4319
|
/* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
|
|
4319
4320
|
/* @__PURE__ */ jsxRuntime.jsxs(Popover, { children: [
|
|
4320
|
-
/* @__PURE__ */ jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
|
|
4326
|
-
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4321
|
+
/* @__PURE__ */ jsxRuntime.jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsxs(InputGroup, { className: "flex flex-row gap-1", children: [
|
|
4322
|
+
infoTooltip && /* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { children: [
|
|
4323
|
+
/* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Info, { size: 20 }) }),
|
|
4324
|
+
/* @__PURE__ */ jsxRuntime.jsx(TooltipContent, { children: /* @__PURE__ */ jsxRuntime.jsx("p", { children: infoTooltip }) })
|
|
4325
|
+
] }),
|
|
4326
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4327
|
+
Button,
|
|
4328
|
+
{
|
|
4329
|
+
variant: "outline",
|
|
4330
|
+
type: "button",
|
|
4331
|
+
className: cn(
|
|
4332
|
+
"w-full justify-start text-left py-0.5 ",
|
|
4333
|
+
!date && "text-muted-foreground"
|
|
4334
|
+
),
|
|
4335
|
+
children: [
|
|
4336
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 items-center gap-1 justify-start text-left ", children: [
|
|
4337
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.CalendarIcon, {}),
|
|
4338
|
+
date ? format(date, "PPP") : /* @__PURE__ */ jsxRuntime.jsx("span", { children: input.placeHolder ?? "Fecha" })
|
|
4339
|
+
] }),
|
|
4340
|
+
(iconsRight.length > 0 || textRight || autoValidate) && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4341
|
+
textRight && /* @__PURE__ */ jsxRuntime.jsx(InputGroupText, { children: textRight }),
|
|
4342
|
+
iconsRight.map((IconComponent, index) => /* @__PURE__ */ jsxRuntime.jsx(IconComponent, { size: 24, className: "w-6! h-6!" }, index)),
|
|
4343
|
+
autoValidate && /* @__PURE__ */ jsxRuntime.jsx("div", { children: isSubmitting ? iconLoadingState : isValid2 ? iconValidState : iconInvalidState })
|
|
4344
|
+
] })
|
|
4345
|
+
]
|
|
4346
|
+
}
|
|
4347
|
+
)
|
|
4348
|
+
] }) }) }),
|
|
4341
4349
|
/* @__PURE__ */ jsxRuntime.jsx(PopoverContent, { className: "w-auto p-0", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4342
4350
|
Calendar,
|
|
4343
4351
|
{
|
|
@@ -6166,6 +6174,16 @@ var getFieldLabel = (fieldErrorKey, fields) => {
|
|
|
6166
6174
|
return foundField?.label ?? fieldErrorKey;
|
|
6167
6175
|
};
|
|
6168
6176
|
var isRenderableChild = (c) => c !== void 0 && c !== null && typeof c !== "function";
|
|
6177
|
+
var shouldShowField = (field, values) => {
|
|
6178
|
+
if (typeof field.showWhen === "function") {
|
|
6179
|
+
try {
|
|
6180
|
+
return !!field.showWhen(values);
|
|
6181
|
+
} catch {
|
|
6182
|
+
return true;
|
|
6183
|
+
}
|
|
6184
|
+
}
|
|
6185
|
+
return true;
|
|
6186
|
+
};
|
|
6169
6187
|
var FormFieldsGrid = ({
|
|
6170
6188
|
fields,
|
|
6171
6189
|
form,
|
|
@@ -6174,47 +6192,54 @@ var FormFieldsGrid = ({
|
|
|
6174
6192
|
className = "",
|
|
6175
6193
|
gap = "gap-2"
|
|
6176
6194
|
}) => {
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6195
|
+
const values = form.watch();
|
|
6196
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: `w-full grid grid-cols-1 ${gap} ${className}`, children: fields.map((inputOrGroup, idx) => {
|
|
6197
|
+
if (Array.isArray(inputOrGroup)) {
|
|
6198
|
+
const visibleFields = inputOrGroup.filter(
|
|
6199
|
+
(f) => shouldShowField(f, values)
|
|
6200
|
+
);
|
|
6201
|
+
if (visibleFields.length === 0) return null;
|
|
6202
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
6203
|
+
"div",
|
|
6204
|
+
{
|
|
6205
|
+
className: "w-full flex flex-row items-start gap-4 py-3",
|
|
6206
|
+
children: visibleFields.map((field, subIdx) => {
|
|
6207
|
+
const fieldCopy2 = {
|
|
6208
|
+
...field,
|
|
6209
|
+
disabled: readOnly ? true : field.disabled
|
|
6210
|
+
};
|
|
6211
|
+
const renderUp2 = fieldCopy2.childrenPosition !== "down" && isRenderableChild(fieldCopy2.children);
|
|
6212
|
+
const renderDown2 = fieldCopy2.childrenPosition === "down" && isRenderableChild(fieldCopy2.children);
|
|
6213
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full px-2", children: [
|
|
6214
|
+
renderUp2 && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy2.children }),
|
|
6215
|
+
InputFactory.create(fieldCopy2, form, isPending),
|
|
6216
|
+
renderDown2 && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy2.children })
|
|
6217
|
+
] }, `field-${idx}-${subIdx}`);
|
|
6218
|
+
})
|
|
6219
|
+
},
|
|
6220
|
+
`field-group-${idx}`
|
|
6221
|
+
);
|
|
6222
|
+
}
|
|
6223
|
+
if (!shouldShowField(inputOrGroup, values)) return null;
|
|
6224
|
+
const fieldCopy = {
|
|
6225
|
+
...inputOrGroup,
|
|
6226
|
+
disabled: readOnly ? true : inputOrGroup.disabled
|
|
6227
|
+
};
|
|
6228
|
+
const renderUp = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
|
|
6229
|
+
const renderDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
|
|
6230
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6198
6231
|
"div",
|
|
6199
6232
|
{
|
|
6200
6233
|
className: "flex flex-col justify-between py-3 w-full px-2",
|
|
6201
|
-
children:
|
|
6202
|
-
|
|
6203
|
-
|
|
6204
|
-
|
|
6205
|
-
|
|
6206
|
-
const renderUp = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
|
|
6207
|
-
const renderDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
|
|
6208
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
6209
|
-
renderUp && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children }),
|
|
6210
|
-
InputFactory.create(fieldCopy, form, isPending),
|
|
6211
|
-
renderDown && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children })
|
|
6212
|
-
] });
|
|
6213
|
-
})()
|
|
6234
|
+
children: [
|
|
6235
|
+
renderUp && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children }),
|
|
6236
|
+
InputFactory.create(fieldCopy, form, isPending),
|
|
6237
|
+
renderDown && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children })
|
|
6238
|
+
]
|
|
6214
6239
|
},
|
|
6215
6240
|
`field-single-${idx}`
|
|
6216
|
-
)
|
|
6217
|
-
) });
|
|
6241
|
+
);
|
|
6242
|
+
}) });
|
|
6218
6243
|
};
|
|
6219
6244
|
var DynamicForm = ({
|
|
6220
6245
|
formTitle,
|
|
@@ -6239,7 +6264,11 @@ var DynamicForm = ({
|
|
|
6239
6264
|
submitBtnLabelSubmiting = "Guardando...",
|
|
6240
6265
|
withFormWrapper = true,
|
|
6241
6266
|
btnGroupDirection = "flex-end",
|
|
6242
|
-
withSubmitBtn = true
|
|
6267
|
+
withSubmitBtn = true,
|
|
6268
|
+
debug = false,
|
|
6269
|
+
isWrapInWizard = false,
|
|
6270
|
+
totalSteps = 0,
|
|
6271
|
+
currentStep = 1
|
|
6243
6272
|
}) => {
|
|
6244
6273
|
const [isPending, startTransition] = React3.useTransition();
|
|
6245
6274
|
const schema = React3.useMemo(() => {
|
|
@@ -6266,7 +6295,7 @@ var DynamicForm = ({
|
|
|
6266
6295
|
if (!onClick) return;
|
|
6267
6296
|
const isValid2 = await form.trigger();
|
|
6268
6297
|
if (!isValid2) return;
|
|
6269
|
-
const data = form.
|
|
6298
|
+
const data = form.watch();
|
|
6270
6299
|
const resp = { data, form };
|
|
6271
6300
|
onClick(resp);
|
|
6272
6301
|
};
|
|
@@ -6310,11 +6339,11 @@ var DynamicForm = ({
|
|
|
6310
6339
|
disabled: isPending,
|
|
6311
6340
|
onClick: onClick ? handleClick : void 0,
|
|
6312
6341
|
children: isPending ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
6313
|
-
|
|
6314
|
-
|
|
6342
|
+
submitBtnLabelSubmiting,
|
|
6343
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-5 w-5 mr-2 animate-spin" })
|
|
6315
6344
|
] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
6316
|
-
|
|
6317
|
-
|
|
6345
|
+
submitBtnLabel,
|
|
6346
|
+
(totalSteps == 0 || totalSteps == currentStep) && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Save, { className: "h-5 w-5 mr-2" })
|
|
6318
6347
|
] })
|
|
6319
6348
|
}
|
|
6320
6349
|
)
|
|
@@ -6338,7 +6367,15 @@ var DynamicForm = ({
|
|
|
6338
6367
|
fields
|
|
6339
6368
|
}
|
|
6340
6369
|
),
|
|
6341
|
-
withFormWrapper && /* @__PURE__ */ jsxRuntime.jsx(
|
|
6370
|
+
withFormWrapper && /* @__PURE__ */ jsxRuntime.jsx(
|
|
6371
|
+
FormWrapper,
|
|
6372
|
+
{
|
|
6373
|
+
form,
|
|
6374
|
+
isWrapInWizard,
|
|
6375
|
+
handleSubmit,
|
|
6376
|
+
children: formBody
|
|
6377
|
+
}
|
|
6378
|
+
),
|
|
6342
6379
|
!withFormWrapper && formBody,
|
|
6343
6380
|
withErrorsAlert && errorAlertPosition === "down" && /* @__PURE__ */ jsxRuntime.jsx(
|
|
6344
6381
|
FormErrorsAlert,
|
|
@@ -6351,13 +6388,17 @@ var DynamicForm = ({
|
|
|
6351
6388
|
if (!withCard) return formContent;
|
|
6352
6389
|
return /* @__PURE__ */ jsxRuntime.jsx(Card, { children: /* @__PURE__ */ jsxRuntime.jsx(CardContent, { children: formContent }) });
|
|
6353
6390
|
};
|
|
6354
|
-
var FormWrapper = ({ form, handleSubmit, children, readOnly }) => {
|
|
6355
|
-
|
|
6391
|
+
var FormWrapper = ({ form, handleSubmit, children, readOnly, debug, isWrapInWizard }) => {
|
|
6392
|
+
const allValues = form.watch();
|
|
6393
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6356
6394
|
"form",
|
|
6357
6395
|
{
|
|
6358
6396
|
onSubmit: form.handleSubmit(handleSubmit),
|
|
6359
6397
|
className: `flex flex-col gap-2 ${readOnly ? "opacity-70 pointer-events-none select-none" : ""}`,
|
|
6360
|
-
children
|
|
6398
|
+
children: [
|
|
6399
|
+
children,
|
|
6400
|
+
debug && /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "mt-4 p-3 bg-muted text-xs rounded", children: JSON.stringify(allValues, null, 2) })
|
|
6401
|
+
]
|
|
6361
6402
|
}
|
|
6362
6403
|
) });
|
|
6363
6404
|
};
|
|
@@ -6419,7 +6460,10 @@ function Stepper({ steps, currentStep, clickable = false, onStepClick }) {
|
|
|
6419
6460
|
var WizardForm = ({
|
|
6420
6461
|
fields,
|
|
6421
6462
|
record,
|
|
6422
|
-
onSubmit
|
|
6463
|
+
onSubmit,
|
|
6464
|
+
children,
|
|
6465
|
+
isWrapInWizard = true,
|
|
6466
|
+
skipSteps = false
|
|
6423
6467
|
}) => {
|
|
6424
6468
|
const [currentStep, setCurrentStep] = React3.useState(1);
|
|
6425
6469
|
const flattenFields4 = (list) => list.flatMap((f) => Array.isArray(f) ? flattenFields4(f) : f);
|
|
@@ -6430,40 +6474,21 @@ var WizardForm = ({
|
|
|
6430
6474
|
);
|
|
6431
6475
|
const stepFields = allFields.filter((f) => (f.step ?? 1) === currentStep);
|
|
6432
6476
|
return /* @__PURE__ */ jsxRuntime.jsxs(Card, { className: "flex flex-col gap-4 px-4", children: [
|
|
6433
|
-
/* @__PURE__ */ jsxRuntime.jsx(Card, { children: /* @__PURE__ */ jsxRuntime.
|
|
6434
|
-
|
|
6435
|
-
|
|
6436
|
-
{
|
|
6437
|
-
|
|
6438
|
-
|
|
6439
|
-
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
|
|
6444
|
-
|
|
6445
|
-
|
|
6446
|
-
|
|
6447
|
-
|
|
6448
|
-
className: "w-32",
|
|
6449
|
-
onClick: () => setCurrentStep((prev) => prev - 1),
|
|
6450
|
-
disabled: currentStep === 1,
|
|
6451
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronLeftIcon, {})
|
|
6452
|
-
}
|
|
6453
|
-
),
|
|
6454
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6455
|
-
Button,
|
|
6456
|
-
{
|
|
6457
|
-
variant: "outline",
|
|
6458
|
-
className: "w-32",
|
|
6459
|
-
onClick: () => setCurrentStep((prev) => prev + 1),
|
|
6460
|
-
disabled: currentStep > totalSteps,
|
|
6461
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRightIcon, {})
|
|
6462
|
-
}
|
|
6463
|
-
)
|
|
6464
|
-
] })
|
|
6465
|
-
] }) }),
|
|
6466
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6477
|
+
/* @__PURE__ */ jsxRuntime.jsx(Card, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-between mb-4 gap-2 px-4", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
6478
|
+
Stepper,
|
|
6479
|
+
{
|
|
6480
|
+
steps: Array(totalSteps).fill({}),
|
|
6481
|
+
currentStep,
|
|
6482
|
+
clickable: skipSteps,
|
|
6483
|
+
onStepClick: setCurrentStep
|
|
6484
|
+
}
|
|
6485
|
+
) }) }),
|
|
6486
|
+
children ? children({
|
|
6487
|
+
stepFields,
|
|
6488
|
+
currentStep,
|
|
6489
|
+
totalSteps,
|
|
6490
|
+
setCurrentStep
|
|
6491
|
+
}) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
6467
6492
|
DynamicForm,
|
|
6468
6493
|
{
|
|
6469
6494
|
record,
|
|
@@ -6472,7 +6497,10 @@ var WizardForm = ({
|
|
|
6472
6497
|
withCard: false,
|
|
6473
6498
|
errorAlertPosition: "down",
|
|
6474
6499
|
fields: stepFields,
|
|
6475
|
-
onSubmit
|
|
6500
|
+
onSubmit,
|
|
6501
|
+
isWrapInWizard: true,
|
|
6502
|
+
currentStep,
|
|
6503
|
+
totalSteps
|
|
6476
6504
|
}
|
|
6477
6505
|
)
|
|
6478
6506
|
] });
|