shadcn-zod-formkit 1.31.0 → 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 +70 -64
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.mjs +71 -65
- 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.31.0.tgz +0 -0
package/dist/index.d.mts
CHANGED
|
@@ -244,15 +244,27 @@ interface Props$i<T extends Record<string, any>> {
|
|
|
244
244
|
childrenHeader?: ReactNode;
|
|
245
245
|
listBtnConfig?: BtnConfig[];
|
|
246
246
|
debug?: boolean;
|
|
247
|
+
isWrapInWizard?: boolean;
|
|
248
|
+
currentStep?: number;
|
|
249
|
+
totalSteps?: number;
|
|
247
250
|
}
|
|
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;
|
|
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;
|
|
249
252
|
|
|
253
|
+
interface WizardRenderProps<T> {
|
|
254
|
+
stepFields: FieldProps<T>[];
|
|
255
|
+
currentStep: number;
|
|
256
|
+
totalSteps: number;
|
|
257
|
+
setCurrentStep: Dispatch<SetStateAction<number>>;
|
|
258
|
+
}
|
|
250
259
|
interface Props$h<T> {
|
|
251
260
|
onSubmit?: (resp: FormResp<T>) => void;
|
|
252
261
|
fields: FieldConfig<T>[];
|
|
253
262
|
record: any;
|
|
263
|
+
children?: (props: WizardRenderProps<T>) => ReactNode;
|
|
264
|
+
isWrapInWizard?: boolean;
|
|
265
|
+
skipSteps?: boolean;
|
|
254
266
|
}
|
|
255
|
-
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;
|
|
256
268
|
|
|
257
269
|
declare const DynamicFormExample: () => react_jsx_runtime.JSX.Element;
|
|
258
270
|
declare const mockFields: Array<FieldProps | FieldProps[]>;
|
package/dist/index.d.ts
CHANGED
|
@@ -244,15 +244,27 @@ interface Props$i<T extends Record<string, any>> {
|
|
|
244
244
|
childrenHeader?: ReactNode;
|
|
245
245
|
listBtnConfig?: BtnConfig[];
|
|
246
246
|
debug?: boolean;
|
|
247
|
+
isWrapInWizard?: boolean;
|
|
248
|
+
currentStep?: number;
|
|
249
|
+
totalSteps?: number;
|
|
247
250
|
}
|
|
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;
|
|
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;
|
|
249
252
|
|
|
253
|
+
interface WizardRenderProps<T> {
|
|
254
|
+
stepFields: FieldProps<T>[];
|
|
255
|
+
currentStep: number;
|
|
256
|
+
totalSteps: number;
|
|
257
|
+
setCurrentStep: Dispatch<SetStateAction<number>>;
|
|
258
|
+
}
|
|
250
259
|
interface Props$h<T> {
|
|
251
260
|
onSubmit?: (resp: FormResp<T>) => void;
|
|
252
261
|
fields: FieldConfig<T>[];
|
|
253
262
|
record: any;
|
|
263
|
+
children?: (props: WizardRenderProps<T>) => ReactNode;
|
|
264
|
+
isWrapInWizard?: boolean;
|
|
265
|
+
skipSteps?: boolean;
|
|
254
266
|
}
|
|
255
|
-
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;
|
|
256
268
|
|
|
257
269
|
declare const DynamicFormExample: () => react_jsx_runtime.JSX.Element;
|
|
258
270
|
declare const mockFields: Array<FieldProps | FieldProps[]>;
|
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
|
{
|
|
@@ -6220,7 +6228,10 @@ var DynamicForm = ({
|
|
|
6220
6228
|
withFormWrapper = true,
|
|
6221
6229
|
btnGroupDirection = "flex-end",
|
|
6222
6230
|
withSubmitBtn = true,
|
|
6223
|
-
debug = false
|
|
6231
|
+
debug = false,
|
|
6232
|
+
isWrapInWizard = false,
|
|
6233
|
+
totalSteps = 0,
|
|
6234
|
+
currentStep = 1
|
|
6224
6235
|
}) => {
|
|
6225
6236
|
const [isPending, startTransition] = useTransition();
|
|
6226
6237
|
const schema = useMemo(() => {
|
|
@@ -6291,11 +6302,11 @@ var DynamicForm = ({
|
|
|
6291
6302
|
disabled: isPending,
|
|
6292
6303
|
onClick: onClick ? handleClick : void 0,
|
|
6293
6304
|
children: isPending ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
6294
|
-
|
|
6295
|
-
|
|
6305
|
+
submitBtnLabelSubmiting,
|
|
6306
|
+
/* @__PURE__ */ jsx(Loader2, { className: "h-5 w-5 mr-2 animate-spin" })
|
|
6296
6307
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
6297
|
-
|
|
6298
|
-
|
|
6308
|
+
submitBtnLabel,
|
|
6309
|
+
(totalSteps == 0 || totalSteps == currentStep) && /* @__PURE__ */ jsx(Save, { className: "h-5 w-5 mr-2" })
|
|
6299
6310
|
] })
|
|
6300
6311
|
}
|
|
6301
6312
|
)
|
|
@@ -6319,7 +6330,15 @@ var DynamicForm = ({
|
|
|
6319
6330
|
fields
|
|
6320
6331
|
}
|
|
6321
6332
|
),
|
|
6322
|
-
withFormWrapper && /* @__PURE__ */ jsx(
|
|
6333
|
+
withFormWrapper && /* @__PURE__ */ jsx(
|
|
6334
|
+
FormWrapper,
|
|
6335
|
+
{
|
|
6336
|
+
form,
|
|
6337
|
+
isWrapInWizard,
|
|
6338
|
+
handleSubmit,
|
|
6339
|
+
children: formBody
|
|
6340
|
+
}
|
|
6341
|
+
),
|
|
6323
6342
|
!withFormWrapper && formBody,
|
|
6324
6343
|
withErrorsAlert && errorAlertPosition === "down" && /* @__PURE__ */ jsx(
|
|
6325
6344
|
FormErrorsAlert,
|
|
@@ -6332,7 +6351,7 @@ var DynamicForm = ({
|
|
|
6332
6351
|
if (!withCard) return formContent;
|
|
6333
6352
|
return /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(CardContent, { children: formContent }) });
|
|
6334
6353
|
};
|
|
6335
|
-
var FormWrapper = ({ form, handleSubmit, children, readOnly, debug }) => {
|
|
6354
|
+
var FormWrapper = ({ form, handleSubmit, children, readOnly, debug, isWrapInWizard }) => {
|
|
6336
6355
|
const allValues = form.watch();
|
|
6337
6356
|
return /* @__PURE__ */ jsx(Form, { ...form, children: /* @__PURE__ */ jsxs(
|
|
6338
6357
|
"form",
|
|
@@ -6404,7 +6423,10 @@ function Stepper({ steps, currentStep, clickable = false, onStepClick }) {
|
|
|
6404
6423
|
var WizardForm = ({
|
|
6405
6424
|
fields,
|
|
6406
6425
|
record,
|
|
6407
|
-
onSubmit
|
|
6426
|
+
onSubmit,
|
|
6427
|
+
children,
|
|
6428
|
+
isWrapInWizard = true,
|
|
6429
|
+
skipSteps = false
|
|
6408
6430
|
}) => {
|
|
6409
6431
|
const [currentStep, setCurrentStep] = useState(1);
|
|
6410
6432
|
const flattenFields4 = (list) => list.flatMap((f) => Array.isArray(f) ? flattenFields4(f) : f);
|
|
@@ -6415,40 +6437,21 @@ var WizardForm = ({
|
|
|
6415
6437
|
);
|
|
6416
6438
|
const stepFields = allFields.filter((f) => (f.step ?? 1) === currentStep);
|
|
6417
6439
|
return /* @__PURE__ */ jsxs(Card, { className: "flex flex-col gap-4 px-4", children: [
|
|
6418
|
-
/* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */
|
|
6419
|
-
|
|
6420
|
-
|
|
6421
|
-
{
|
|
6422
|
-
|
|
6423
|
-
|
|
6424
|
-
|
|
6425
|
-
|
|
6426
|
-
|
|
6427
|
-
|
|
6428
|
-
|
|
6429
|
-
|
|
6430
|
-
|
|
6431
|
-
|
|
6432
|
-
|
|
6433
|
-
className: "w-32",
|
|
6434
|
-
onClick: () => setCurrentStep((prev) => prev - 1),
|
|
6435
|
-
disabled: currentStep === 1,
|
|
6436
|
-
children: /* @__PURE__ */ jsx(ChevronLeftIcon, {})
|
|
6437
|
-
}
|
|
6438
|
-
),
|
|
6439
|
-
/* @__PURE__ */ jsx(
|
|
6440
|
-
Button,
|
|
6441
|
-
{
|
|
6442
|
-
variant: "outline",
|
|
6443
|
-
className: "w-32",
|
|
6444
|
-
onClick: () => setCurrentStep((prev) => prev + 1),
|
|
6445
|
-
disabled: currentStep > totalSteps,
|
|
6446
|
-
children: /* @__PURE__ */ jsx(ChevronRightIcon, {})
|
|
6447
|
-
}
|
|
6448
|
-
)
|
|
6449
|
-
] })
|
|
6450
|
-
] }) }),
|
|
6451
|
-
/* @__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(
|
|
6452
6455
|
DynamicForm,
|
|
6453
6456
|
{
|
|
6454
6457
|
record,
|
|
@@ -6457,7 +6460,10 @@ var WizardForm = ({
|
|
|
6457
6460
|
withCard: false,
|
|
6458
6461
|
errorAlertPosition: "down",
|
|
6459
6462
|
fields: stepFields,
|
|
6460
|
-
onSubmit
|
|
6463
|
+
onSubmit,
|
|
6464
|
+
isWrapInWizard: true,
|
|
6465
|
+
currentStep,
|
|
6466
|
+
totalSteps
|
|
6461
6467
|
}
|
|
6462
6468
|
)
|
|
6463
6469
|
] });
|