shadcn-zod-formkit 1.30.0 → 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 +193 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +15 -11
- package/dist/index.d.ts +15 -11
- package/dist/index.mjs +193 -49
- package/dist/index.mjs.map +1 -1
- package/dist/shadcn-zod-formkit-1.31.0.tgz +0 -0
- package/package.json +4 -2
- package/dist/shadcn-zod-formkit-1.30.0.tgz +0 -0
package/dist/index.cjs
CHANGED
|
@@ -2221,6 +2221,8 @@ var ColorInput = class extends BaseInput {
|
|
|
2221
2221
|
}
|
|
2222
2222
|
};
|
|
2223
2223
|
var PRESET_COLORS = [
|
|
2224
|
+
"#9A275A",
|
|
2225
|
+
// QuinaMagenta
|
|
2224
2226
|
"#800000",
|
|
2225
2227
|
// Maroon
|
|
2226
2228
|
"#ef4444",
|
|
@@ -2231,6 +2233,8 @@ var PRESET_COLORS = [
|
|
|
2231
2233
|
// yellow
|
|
2232
2234
|
"#22c55e",
|
|
2233
2235
|
// green
|
|
2236
|
+
"#99EDCC",
|
|
2237
|
+
// Aquamarine
|
|
2234
2238
|
"#00FF00",
|
|
2235
2239
|
// lime
|
|
2236
2240
|
"#00FFFF",
|
|
@@ -2249,10 +2253,12 @@ var PRESET_COLORS = [
|
|
|
2249
2253
|
// pink
|
|
2250
2254
|
"#64748b",
|
|
2251
2255
|
// slate
|
|
2256
|
+
"#000000",
|
|
2257
|
+
// black
|
|
2252
2258
|
"#808080",
|
|
2253
2259
|
// Gray
|
|
2254
|
-
"#
|
|
2255
|
-
//
|
|
2260
|
+
"#FFFFFF"
|
|
2261
|
+
// White
|
|
2256
2262
|
];
|
|
2257
2263
|
var FieldColor = ({ form, input, isSubmitting }) => {
|
|
2258
2264
|
const [ColorCmp, _setColorCmp] = React3.useState(ColorComp);
|
|
@@ -2305,13 +2311,13 @@ var ColorComp = React3__namespace.default.forwardRef(
|
|
|
2305
2311
|
}
|
|
2306
2312
|
};
|
|
2307
2313
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3", children: [
|
|
2308
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-
|
|
2314
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row gap-2 p-2", children: PRESET_COLORS.map((presetColor) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
2309
2315
|
"button",
|
|
2310
2316
|
{
|
|
2311
2317
|
type: "button",
|
|
2312
2318
|
disabled,
|
|
2313
2319
|
className: cn(
|
|
2314
|
-
"size-
|
|
2320
|
+
"flex-1 size-4 shadow-lg rounded-md border-2 border-black transition-all hover:scale-110 disabled:opacity-50 disabled:cursor-not-allowed",
|
|
2315
2321
|
color.hex === presetColor ? "border-foreground ring-2 ring-foreground/20" : "border-border hover:border-foreground/50"
|
|
2316
2322
|
),
|
|
2317
2323
|
style: { backgroundColor: presetColor },
|
|
@@ -4752,7 +4758,7 @@ var FieldKeyValueList = ({ form, input, isSubmitting }) => {
|
|
|
4752
4758
|
] }),
|
|
4753
4759
|
/* @__PURE__ */ jsxRuntime.jsxs(ButtonGroup, { className: "w-full", children: [
|
|
4754
4760
|
/* @__PURE__ */ jsxRuntime.jsx(ButtonGroupText, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(LabelPrimitive.Label, { htmlFor: "value", children: "Value" }) }),
|
|
4755
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4761
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4756
4762
|
CustomInputGroup,
|
|
4757
4763
|
{
|
|
4758
4764
|
autoValidate: true,
|
|
@@ -4763,7 +4769,7 @@ var FieldKeyValueList = ({ form, input, isSubmitting }) => {
|
|
|
4763
4769
|
onChange: (e) => handleChange(index, "value", e.target.value),
|
|
4764
4770
|
form
|
|
4765
4771
|
}
|
|
4766
|
-
)
|
|
4772
|
+
)
|
|
4767
4773
|
] }),
|
|
4768
4774
|
input.isRemovebleOption && /* @__PURE__ */ jsxRuntime.jsx(
|
|
4769
4775
|
Button,
|
|
@@ -5763,7 +5769,7 @@ var FieldSwitch = ({ input, form, isSubmitting }) => {
|
|
|
5763
5769
|
onCheckedChange: (event) => {
|
|
5764
5770
|
handleOnChage(event, input, field);
|
|
5765
5771
|
},
|
|
5766
|
-
disabled:
|
|
5772
|
+
disabled: input.disabled || isSubmitting
|
|
5767
5773
|
}
|
|
5768
5774
|
) })
|
|
5769
5775
|
] }) })
|
|
@@ -6160,6 +6166,16 @@ var getFieldLabel = (fieldErrorKey, fields) => {
|
|
|
6160
6166
|
return foundField?.label ?? fieldErrorKey;
|
|
6161
6167
|
};
|
|
6162
6168
|
var isRenderableChild = (c) => c !== void 0 && c !== null && typeof c !== "function";
|
|
6169
|
+
var shouldShowField = (field, values) => {
|
|
6170
|
+
if (typeof field.showWhen === "function") {
|
|
6171
|
+
try {
|
|
6172
|
+
return !!field.showWhen(values);
|
|
6173
|
+
} catch {
|
|
6174
|
+
return true;
|
|
6175
|
+
}
|
|
6176
|
+
}
|
|
6177
|
+
return true;
|
|
6178
|
+
};
|
|
6163
6179
|
var FormFieldsGrid = ({
|
|
6164
6180
|
fields,
|
|
6165
6181
|
form,
|
|
@@ -6168,47 +6184,54 @@ var FormFieldsGrid = ({
|
|
|
6168
6184
|
className = "",
|
|
6169
6185
|
gap = "gap-2"
|
|
6170
6186
|
}) => {
|
|
6171
|
-
|
|
6172
|
-
|
|
6173
|
-
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
|
|
6187
|
-
|
|
6188
|
-
|
|
6189
|
-
|
|
6190
|
-
|
|
6191
|
-
|
|
6187
|
+
const values = form.watch();
|
|
6188
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: `w-full grid grid-cols-1 ${gap} ${className}`, children: fields.map((inputOrGroup, idx) => {
|
|
6189
|
+
if (Array.isArray(inputOrGroup)) {
|
|
6190
|
+
const visibleFields = inputOrGroup.filter(
|
|
6191
|
+
(f) => shouldShowField(f, values)
|
|
6192
|
+
);
|
|
6193
|
+
if (visibleFields.length === 0) return null;
|
|
6194
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
6195
|
+
"div",
|
|
6196
|
+
{
|
|
6197
|
+
className: "w-full flex flex-row items-start gap-4 py-3",
|
|
6198
|
+
children: visibleFields.map((field, subIdx) => {
|
|
6199
|
+
const fieldCopy2 = {
|
|
6200
|
+
...field,
|
|
6201
|
+
disabled: readOnly ? true : field.disabled
|
|
6202
|
+
};
|
|
6203
|
+
const renderUp2 = fieldCopy2.childrenPosition !== "down" && isRenderableChild(fieldCopy2.children);
|
|
6204
|
+
const renderDown2 = fieldCopy2.childrenPosition === "down" && isRenderableChild(fieldCopy2.children);
|
|
6205
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full px-2", children: [
|
|
6206
|
+
renderUp2 && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy2.children }),
|
|
6207
|
+
InputFactory.create(fieldCopy2, form, isPending),
|
|
6208
|
+
renderDown2 && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy2.children })
|
|
6209
|
+
] }, `field-${idx}-${subIdx}`);
|
|
6210
|
+
})
|
|
6211
|
+
},
|
|
6212
|
+
`field-group-${idx}`
|
|
6213
|
+
);
|
|
6214
|
+
}
|
|
6215
|
+
if (!shouldShowField(inputOrGroup, values)) return null;
|
|
6216
|
+
const fieldCopy = {
|
|
6217
|
+
...inputOrGroup,
|
|
6218
|
+
disabled: readOnly ? true : inputOrGroup.disabled
|
|
6219
|
+
};
|
|
6220
|
+
const renderUp = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
|
|
6221
|
+
const renderDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
|
|
6222
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6192
6223
|
"div",
|
|
6193
6224
|
{
|
|
6194
6225
|
className: "flex flex-col justify-between py-3 w-full px-2",
|
|
6195
|
-
children:
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
|
|
6199
|
-
|
|
6200
|
-
const renderUp = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
|
|
6201
|
-
const renderDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
|
|
6202
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
6203
|
-
renderUp && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children }),
|
|
6204
|
-
InputFactory.create(fieldCopy, form, isPending),
|
|
6205
|
-
renderDown && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children })
|
|
6206
|
-
] });
|
|
6207
|
-
})()
|
|
6226
|
+
children: [
|
|
6227
|
+
renderUp && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children }),
|
|
6228
|
+
InputFactory.create(fieldCopy, form, isPending),
|
|
6229
|
+
renderDown && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fieldCopy.children })
|
|
6230
|
+
]
|
|
6208
6231
|
},
|
|
6209
6232
|
`field-single-${idx}`
|
|
6210
|
-
)
|
|
6211
|
-
) });
|
|
6233
|
+
);
|
|
6234
|
+
}) });
|
|
6212
6235
|
};
|
|
6213
6236
|
var DynamicForm = ({
|
|
6214
6237
|
formTitle,
|
|
@@ -6233,7 +6256,8 @@ var DynamicForm = ({
|
|
|
6233
6256
|
submitBtnLabelSubmiting = "Guardando...",
|
|
6234
6257
|
withFormWrapper = true,
|
|
6235
6258
|
btnGroupDirection = "flex-end",
|
|
6236
|
-
withSubmitBtn = true
|
|
6259
|
+
withSubmitBtn = true,
|
|
6260
|
+
debug = false
|
|
6237
6261
|
}) => {
|
|
6238
6262
|
const [isPending, startTransition] = React3.useTransition();
|
|
6239
6263
|
const schema = React3.useMemo(() => {
|
|
@@ -6260,7 +6284,7 @@ var DynamicForm = ({
|
|
|
6260
6284
|
if (!onClick) return;
|
|
6261
6285
|
const isValid2 = await form.trigger();
|
|
6262
6286
|
if (!isValid2) return;
|
|
6263
|
-
const data = form.
|
|
6287
|
+
const data = form.watch();
|
|
6264
6288
|
const resp = { data, form };
|
|
6265
6289
|
onClick(resp);
|
|
6266
6290
|
};
|
|
@@ -6345,16 +6369,136 @@ var DynamicForm = ({
|
|
|
6345
6369
|
if (!withCard) return formContent;
|
|
6346
6370
|
return /* @__PURE__ */ jsxRuntime.jsx(Card, { children: /* @__PURE__ */ jsxRuntime.jsx(CardContent, { children: formContent }) });
|
|
6347
6371
|
};
|
|
6348
|
-
var FormWrapper = ({ form, handleSubmit, children, readOnly }) => {
|
|
6349
|
-
|
|
6372
|
+
var FormWrapper = ({ form, handleSubmit, children, readOnly, debug }) => {
|
|
6373
|
+
const allValues = form.watch();
|
|
6374
|
+
return /* @__PURE__ */ jsxRuntime.jsx(Form, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
6350
6375
|
"form",
|
|
6351
6376
|
{
|
|
6352
6377
|
onSubmit: form.handleSubmit(handleSubmit),
|
|
6353
6378
|
className: `flex flex-col gap-2 ${readOnly ? "opacity-70 pointer-events-none select-none" : ""}`,
|
|
6354
|
-
children
|
|
6379
|
+
children: [
|
|
6380
|
+
children,
|
|
6381
|
+
debug && /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "mt-4 p-3 bg-muted text-xs rounded", children: JSON.stringify(allValues, null, 2) })
|
|
6382
|
+
]
|
|
6355
6383
|
}
|
|
6356
6384
|
) });
|
|
6357
6385
|
};
|
|
6386
|
+
function Stepper({ steps, currentStep, clickable = false, onStepClick }) {
|
|
6387
|
+
const handleStepClick = (stepNumber) => {
|
|
6388
|
+
if (clickable && onStepClick) {
|
|
6389
|
+
onStepClick(stepNumber);
|
|
6390
|
+
}
|
|
6391
|
+
};
|
|
6392
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row gap-4 items-center justify-around", children: steps.map((step, index) => {
|
|
6393
|
+
const stepNumber = index + 1;
|
|
6394
|
+
const isCompleted = stepNumber < currentStep;
|
|
6395
|
+
const isCurrent = stepNumber === currentStep;
|
|
6396
|
+
const isUpcoming = stepNumber > currentStep;
|
|
6397
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 items-center", children: [
|
|
6398
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center", children: [
|
|
6399
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6400
|
+
"div",
|
|
6401
|
+
{
|
|
6402
|
+
onClick: () => handleStepClick(stepNumber),
|
|
6403
|
+
className: cn(
|
|
6404
|
+
"flex size-10 items-center shadow-lg justify-center rounded-full border-2 transition-all duration-300",
|
|
6405
|
+
isCompleted && "border-primary bg-primary text-primary-foreground",
|
|
6406
|
+
isCurrent && "border-primary bg-background text-primary scale-110",
|
|
6407
|
+
isUpcoming && "border-muted-foreground/60 bg-background border-b text-muted-foreground",
|
|
6408
|
+
clickable && "cursor-pointer hover:scale-125 hover:shadow-xl",
|
|
6409
|
+
!clickable && "cursor-default"
|
|
6410
|
+
),
|
|
6411
|
+
children: isCompleted ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "size-5" }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-semibold", children: stepNumber })
|
|
6412
|
+
}
|
|
6413
|
+
),
|
|
6414
|
+
step.title && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "mt-3 text-center", children: [
|
|
6415
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6416
|
+
"p",
|
|
6417
|
+
{
|
|
6418
|
+
className: cn(
|
|
6419
|
+
"text-sm font-medium transition-colors",
|
|
6420
|
+
(isCompleted || isCurrent) && "text-foreground",
|
|
6421
|
+
isUpcoming && "text-muted-foreground"
|
|
6422
|
+
),
|
|
6423
|
+
children: step.title
|
|
6424
|
+
}
|
|
6425
|
+
),
|
|
6426
|
+
step.description && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-1 text-xs text-muted-foreground max-w-[120px]", children: step.description })
|
|
6427
|
+
] })
|
|
6428
|
+
] }),
|
|
6429
|
+
index < steps.length - 1 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "mx-2 flex-1 mb-8", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
6430
|
+
"div",
|
|
6431
|
+
{
|
|
6432
|
+
className: cn(
|
|
6433
|
+
"h-0.5 w-full transition-all duration-300",
|
|
6434
|
+
stepNumber < currentStep ? "bg-primary" : "bg-muted-foreground/30"
|
|
6435
|
+
)
|
|
6436
|
+
}
|
|
6437
|
+
) })
|
|
6438
|
+
] }, index);
|
|
6439
|
+
}) }) });
|
|
6440
|
+
}
|
|
6441
|
+
var WizardForm = ({
|
|
6442
|
+
fields,
|
|
6443
|
+
record,
|
|
6444
|
+
onSubmit
|
|
6445
|
+
}) => {
|
|
6446
|
+
const [currentStep, setCurrentStep] = React3.useState(1);
|
|
6447
|
+
const flattenFields4 = (list) => list.flatMap((f) => Array.isArray(f) ? flattenFields4(f) : f);
|
|
6448
|
+
const allFields = flattenFields4(fields);
|
|
6449
|
+
const totalSteps = allFields.reduce(
|
|
6450
|
+
(max, f) => Math.max(max, f.step ?? 1),
|
|
6451
|
+
1
|
|
6452
|
+
);
|
|
6453
|
+
const stepFields = allFields.filter((f) => (f.step ?? 1) === currentStep);
|
|
6454
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(Card, { className: "flex flex-col gap-4 px-4", children: [
|
|
6455
|
+
/* @__PURE__ */ jsxRuntime.jsx(Card, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-between mb-4 gap-2 px-4", children: [
|
|
6456
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6457
|
+
Stepper,
|
|
6458
|
+
{
|
|
6459
|
+
steps: Array(totalSteps).fill({}),
|
|
6460
|
+
currentStep,
|
|
6461
|
+
clickable: true,
|
|
6462
|
+
onStepClick: setCurrentStep
|
|
6463
|
+
}
|
|
6464
|
+
),
|
|
6465
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-center space-x-4 gap-2", children: [
|
|
6466
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6467
|
+
Button,
|
|
6468
|
+
{
|
|
6469
|
+
variant: "outline",
|
|
6470
|
+
className: "w-32",
|
|
6471
|
+
onClick: () => setCurrentStep((prev) => prev - 1),
|
|
6472
|
+
disabled: currentStep === 1,
|
|
6473
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronLeftIcon, {})
|
|
6474
|
+
}
|
|
6475
|
+
),
|
|
6476
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6477
|
+
Button,
|
|
6478
|
+
{
|
|
6479
|
+
variant: "outline",
|
|
6480
|
+
className: "w-32",
|
|
6481
|
+
onClick: () => setCurrentStep((prev) => prev + 1),
|
|
6482
|
+
disabled: currentStep > totalSteps,
|
|
6483
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.ChevronRightIcon, {})
|
|
6484
|
+
}
|
|
6485
|
+
)
|
|
6486
|
+
] })
|
|
6487
|
+
] }) }),
|
|
6488
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6489
|
+
DynamicForm,
|
|
6490
|
+
{
|
|
6491
|
+
record,
|
|
6492
|
+
formSubTitle: "This is a subtitle",
|
|
6493
|
+
formTitle: "Wizard Form Example",
|
|
6494
|
+
withCard: false,
|
|
6495
|
+
errorAlertPosition: "down",
|
|
6496
|
+
fields: stepFields,
|
|
6497
|
+
onSubmit
|
|
6498
|
+
}
|
|
6499
|
+
)
|
|
6500
|
+
] });
|
|
6501
|
+
};
|
|
6358
6502
|
var DynamicFormExample = () => {
|
|
6359
6503
|
const record = {
|
|
6360
6504
|
username: "John Doe ",
|
|
@@ -6805,6 +6949,7 @@ exports.Tooltip = Tooltip;
|
|
|
6805
6949
|
exports.TooltipContent = TooltipContent;
|
|
6806
6950
|
exports.TooltipProvider = TooltipProvider;
|
|
6807
6951
|
exports.TooltipTrigger = TooltipTrigger;
|
|
6952
|
+
exports.WizardForm = WizardForm;
|
|
6808
6953
|
exports.badgeVariants = badgeVariants;
|
|
6809
6954
|
exports.buttonGroupVariants = buttonGroupVariants;
|
|
6810
6955
|
exports.buttonVariants = buttonVariants;
|