@trackunit/react-form-wizard 1.10.18 → 1.10.19

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/index.cjs.js CHANGED
@@ -356,20 +356,108 @@ const cvaFormWizardLayout = cssClassVarianceUtilities.cvaMerge([
356
356
  const cvaStepContainer = cssClassVarianceUtilities.cvaMerge(["h-full", "grid", "bg-white", "overflow-hidden"]);
357
357
 
358
358
  /**
359
- * The FormWizard component is used for forms in multiple steps.
360
- * Use the useFormWizard hook to generate the props for this component.
359
+ * The `<FormWizard>` component renders multi-step forms with a sidebar navigation.
360
+ * Use the `useFormWizard` hook to generate the props for this component.
361
361
  *
362
- * The useFormWizard hook takes a form schema which is a zod schema that contains all the steps.
363
- * Each step will get a prop that is the form for that step and can be used to register inputs.
364
- * This allows for a coherent form structure that can be used to validate the form as steps and as a whole.
362
+ * The wizard uses Zod schemas for validation, where each schema property represents a step.
363
+ * Each step receives its own form instance for registering inputs, enabling per-step and
364
+ * full-form validation.
365
365
  *
366
- * The FormWizard component is a wrapper that renders the sidebar and the step wrapper.
367
- * The sidebar is a list of steps that can be navigated to.
368
- * The step wrapper is a list of steps that are rendered.
366
+ * **Note:** In production, the schema should be returned from a hook to allow translations
367
+ * for error messages.
369
368
  *
370
- * The FormWizard component also handles the navigation between steps.
369
+ * ### When to use
370
+ * - Complex forms that benefit from being split into logical steps
371
+ * - Onboarding flows or setup wizards
372
+ * - Forms where later steps depend on earlier input
371
373
  *
372
- * ** In production code, the schema should be returned from a hook, to allow the use of translations for error messages in the schema. **
374
+ * ### When not to use
375
+ * - Simple forms with few fields - use regular form components
376
+ * - Forms that should show all fields at once
377
+ *
378
+ * @example Basic usage with useFormWizard hook
379
+ * ```tsx
380
+ * import { FormWizard, useFormWizard } from "@trackunit/react-form-wizard";
381
+ * import { z } from "zod";
382
+ *
383
+ * const formSchema = z.object({
384
+ * basicInfo: z.object({
385
+ * name: z.string().min(1, "Name is required"),
386
+ * email: z.string().email("Invalid email"),
387
+ * }),
388
+ * preferences: z.object({
389
+ * notifications: z.boolean(),
390
+ * theme: z.enum(["light", "dark"]),
391
+ * }),
392
+ * });
393
+ *
394
+ * const MyWizard = () => {
395
+ * const wizardProps = useFormWizard({
396
+ * fullFormSchema: formSchema,
397
+ * steps: {
398
+ * basicInfo: {
399
+ * title: "Basic Information",
400
+ * component: BasicInfoStep,
401
+ * },
402
+ * preferences: {
403
+ * title: "Preferences",
404
+ * component: PreferencesStep,
405
+ * },
406
+ * },
407
+ * onSubmit: (data) => console.log("Form submitted:", data),
408
+ * });
409
+ *
410
+ * return <FormWizard {...wizardProps} basePath="/setup" />;
411
+ * };
412
+ * ```
413
+ * @example Step component pattern
414
+ * ```tsx
415
+ * import { FormWizardStepProps } from "@trackunit/react-form-wizard";
416
+ * import { TextField, EmailField } from "@trackunit/react-form-components";
417
+ *
418
+ * const BasicInfoStep = ({ form }: FormWizardStepProps) => {
419
+ * const { register, formState: { errors } } = form;
420
+ *
421
+ * return (
422
+ * <div className="space-y-4">
423
+ * <TextField
424
+ * label="Name"
425
+ * {...register("name")}
426
+ * errorMessage={errors.name?.message}
427
+ * />
428
+ * <EmailField
429
+ * label="Email"
430
+ * {...register("email")}
431
+ * errorMessage={errors.email?.message}
432
+ * />
433
+ * </div>
434
+ * );
435
+ * };
436
+ * ```
437
+ * @example With conditional steps
438
+ * ```tsx
439
+ * import { FormWizard, useFormWizard } from "@trackunit/react-form-wizard";
440
+ *
441
+ * const wizardProps = useFormWizard({
442
+ * fullFormSchema: formSchema,
443
+ * steps: {
444
+ * accountType: {
445
+ * title: "Account Type",
446
+ * component: AccountTypeStep,
447
+ * },
448
+ * businessDetails: {
449
+ * title: "Business Details",
450
+ * component: BusinessDetailsStep,
451
+ * shouldRender: (formState) => formState.accountType?.type === "business",
452
+ * },
453
+ * confirmation: {
454
+ * title: "Confirmation",
455
+ * component: ConfirmationStep,
456
+ * },
457
+ * },
458
+ * onSubmit: handleSubmit,
459
+ * });
460
+ * ```
373
461
  */
374
462
  const FormWizard = ({ lastStepPrimaryActionLabel, isEdit, steps, fullFormSchema, onCancel, className, "data-testid": dataTestId, basePath, }) => {
375
463
  const navigate = reactRouter.useNavigate();
package/index.esm.js CHANGED
@@ -354,20 +354,108 @@ const cvaFormWizardLayout = cvaMerge([
354
354
  const cvaStepContainer = cvaMerge(["h-full", "grid", "bg-white", "overflow-hidden"]);
355
355
 
356
356
  /**
357
- * The FormWizard component is used for forms in multiple steps.
358
- * Use the useFormWizard hook to generate the props for this component.
357
+ * The `<FormWizard>` component renders multi-step forms with a sidebar navigation.
358
+ * Use the `useFormWizard` hook to generate the props for this component.
359
359
  *
360
- * The useFormWizard hook takes a form schema which is a zod schema that contains all the steps.
361
- * Each step will get a prop that is the form for that step and can be used to register inputs.
362
- * This allows for a coherent form structure that can be used to validate the form as steps and as a whole.
360
+ * The wizard uses Zod schemas for validation, where each schema property represents a step.
361
+ * Each step receives its own form instance for registering inputs, enabling per-step and
362
+ * full-form validation.
363
363
  *
364
- * The FormWizard component is a wrapper that renders the sidebar and the step wrapper.
365
- * The sidebar is a list of steps that can be navigated to.
366
- * The step wrapper is a list of steps that are rendered.
364
+ * **Note:** In production, the schema should be returned from a hook to allow translations
365
+ * for error messages.
367
366
  *
368
- * The FormWizard component also handles the navigation between steps.
367
+ * ### When to use
368
+ * - Complex forms that benefit from being split into logical steps
369
+ * - Onboarding flows or setup wizards
370
+ * - Forms where later steps depend on earlier input
369
371
  *
370
- * ** In production code, the schema should be returned from a hook, to allow the use of translations for error messages in the schema. **
372
+ * ### When not to use
373
+ * - Simple forms with few fields - use regular form components
374
+ * - Forms that should show all fields at once
375
+ *
376
+ * @example Basic usage with useFormWizard hook
377
+ * ```tsx
378
+ * import { FormWizard, useFormWizard } from "@trackunit/react-form-wizard";
379
+ * import { z } from "zod";
380
+ *
381
+ * const formSchema = z.object({
382
+ * basicInfo: z.object({
383
+ * name: z.string().min(1, "Name is required"),
384
+ * email: z.string().email("Invalid email"),
385
+ * }),
386
+ * preferences: z.object({
387
+ * notifications: z.boolean(),
388
+ * theme: z.enum(["light", "dark"]),
389
+ * }),
390
+ * });
391
+ *
392
+ * const MyWizard = () => {
393
+ * const wizardProps = useFormWizard({
394
+ * fullFormSchema: formSchema,
395
+ * steps: {
396
+ * basicInfo: {
397
+ * title: "Basic Information",
398
+ * component: BasicInfoStep,
399
+ * },
400
+ * preferences: {
401
+ * title: "Preferences",
402
+ * component: PreferencesStep,
403
+ * },
404
+ * },
405
+ * onSubmit: (data) => console.log("Form submitted:", data),
406
+ * });
407
+ *
408
+ * return <FormWizard {...wizardProps} basePath="/setup" />;
409
+ * };
410
+ * ```
411
+ * @example Step component pattern
412
+ * ```tsx
413
+ * import { FormWizardStepProps } from "@trackunit/react-form-wizard";
414
+ * import { TextField, EmailField } from "@trackunit/react-form-components";
415
+ *
416
+ * const BasicInfoStep = ({ form }: FormWizardStepProps) => {
417
+ * const { register, formState: { errors } } = form;
418
+ *
419
+ * return (
420
+ * <div className="space-y-4">
421
+ * <TextField
422
+ * label="Name"
423
+ * {...register("name")}
424
+ * errorMessage={errors.name?.message}
425
+ * />
426
+ * <EmailField
427
+ * label="Email"
428
+ * {...register("email")}
429
+ * errorMessage={errors.email?.message}
430
+ * />
431
+ * </div>
432
+ * );
433
+ * };
434
+ * ```
435
+ * @example With conditional steps
436
+ * ```tsx
437
+ * import { FormWizard, useFormWizard } from "@trackunit/react-form-wizard";
438
+ *
439
+ * const wizardProps = useFormWizard({
440
+ * fullFormSchema: formSchema,
441
+ * steps: {
442
+ * accountType: {
443
+ * title: "Account Type",
444
+ * component: AccountTypeStep,
445
+ * },
446
+ * businessDetails: {
447
+ * title: "Business Details",
448
+ * component: BusinessDetailsStep,
449
+ * shouldRender: (formState) => formState.accountType?.type === "business",
450
+ * },
451
+ * confirmation: {
452
+ * title: "Confirmation",
453
+ * component: ConfirmationStep,
454
+ * },
455
+ * },
456
+ * onSubmit: handleSubmit,
457
+ * });
458
+ * ```
371
459
  */
372
460
  const FormWizard = ({ lastStepPrimaryActionLabel, isEdit, steps, fullFormSchema, onCancel, className, "data-testid": dataTestId, basePath, }) => {
373
461
  const navigate = useNavigate();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-form-wizard",
3
- "version": "1.10.18",
3
+ "version": "1.10.19",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "dependencies": {
@@ -10,10 +10,10 @@
10
10
  "react-hook-form": "7.62.0",
11
11
  "@tanstack/react-router": "1.114.29",
12
12
  "@tanstack/router-core": "1.114.29",
13
- "@trackunit/shared-utils": "1.12.15",
14
- "@trackunit/css-class-variance-utilities": "1.10.15",
15
- "@trackunit/react-components": "1.14.18",
16
- "@trackunit/i18n-library-translation": "1.10.15"
13
+ "@trackunit/shared-utils": "1.12.16",
14
+ "@trackunit/css-class-variance-utilities": "1.10.16",
15
+ "@trackunit/react-components": "1.14.19",
16
+ "@trackunit/i18n-library-translation": "1.10.16"
17
17
  },
18
18
  "engines": {
19
19
  "node": ">=24.x",
@@ -5,19 +5,107 @@ export type FormWizardStepFormReturnMap<TFullSchema extends AnyZodObject> = Part
5
5
  [TStepKey in keyof z.infer<TFullSchema>]: UseFormReturn<z.TypeOf<TFullSchema>[TStepKey]>;
6
6
  }>;
7
7
  /**
8
- * The FormWizard component is used for forms in multiple steps.
9
- * Use the useFormWizard hook to generate the props for this component.
8
+ * The `<FormWizard>` component renders multi-step forms with a sidebar navigation.
9
+ * Use the `useFormWizard` hook to generate the props for this component.
10
10
  *
11
- * The useFormWizard hook takes a form schema which is a zod schema that contains all the steps.
12
- * Each step will get a prop that is the form for that step and can be used to register inputs.
13
- * This allows for a coherent form structure that can be used to validate the form as steps and as a whole.
11
+ * The wizard uses Zod schemas for validation, where each schema property represents a step.
12
+ * Each step receives its own form instance for registering inputs, enabling per-step and
13
+ * full-form validation.
14
14
  *
15
- * The FormWizard component is a wrapper that renders the sidebar and the step wrapper.
16
- * The sidebar is a list of steps that can be navigated to.
17
- * The step wrapper is a list of steps that are rendered.
15
+ * **Note:** In production, the schema should be returned from a hook to allow translations
16
+ * for error messages.
18
17
  *
19
- * The FormWizard component also handles the navigation between steps.
18
+ * ### When to use
19
+ * - Complex forms that benefit from being split into logical steps
20
+ * - Onboarding flows or setup wizards
21
+ * - Forms where later steps depend on earlier input
20
22
  *
21
- * ** In production code, the schema should be returned from a hook, to allow the use of translations for error messages in the schema. **
23
+ * ### When not to use
24
+ * - Simple forms with few fields - use regular form components
25
+ * - Forms that should show all fields at once
26
+ *
27
+ * @example Basic usage with useFormWizard hook
28
+ * ```tsx
29
+ * import { FormWizard, useFormWizard } from "@trackunit/react-form-wizard";
30
+ * import { z } from "zod";
31
+ *
32
+ * const formSchema = z.object({
33
+ * basicInfo: z.object({
34
+ * name: z.string().min(1, "Name is required"),
35
+ * email: z.string().email("Invalid email"),
36
+ * }),
37
+ * preferences: z.object({
38
+ * notifications: z.boolean(),
39
+ * theme: z.enum(["light", "dark"]),
40
+ * }),
41
+ * });
42
+ *
43
+ * const MyWizard = () => {
44
+ * const wizardProps = useFormWizard({
45
+ * fullFormSchema: formSchema,
46
+ * steps: {
47
+ * basicInfo: {
48
+ * title: "Basic Information",
49
+ * component: BasicInfoStep,
50
+ * },
51
+ * preferences: {
52
+ * title: "Preferences",
53
+ * component: PreferencesStep,
54
+ * },
55
+ * },
56
+ * onSubmit: (data) => console.log("Form submitted:", data),
57
+ * });
58
+ *
59
+ * return <FormWizard {...wizardProps} basePath="/setup" />;
60
+ * };
61
+ * ```
62
+ * @example Step component pattern
63
+ * ```tsx
64
+ * import { FormWizardStepProps } from "@trackunit/react-form-wizard";
65
+ * import { TextField, EmailField } from "@trackunit/react-form-components";
66
+ *
67
+ * const BasicInfoStep = ({ form }: FormWizardStepProps) => {
68
+ * const { register, formState: { errors } } = form;
69
+ *
70
+ * return (
71
+ * <div className="space-y-4">
72
+ * <TextField
73
+ * label="Name"
74
+ * {...register("name")}
75
+ * errorMessage={errors.name?.message}
76
+ * />
77
+ * <EmailField
78
+ * label="Email"
79
+ * {...register("email")}
80
+ * errorMessage={errors.email?.message}
81
+ * />
82
+ * </div>
83
+ * );
84
+ * };
85
+ * ```
86
+ * @example With conditional steps
87
+ * ```tsx
88
+ * import { FormWizard, useFormWizard } from "@trackunit/react-form-wizard";
89
+ *
90
+ * const wizardProps = useFormWizard({
91
+ * fullFormSchema: formSchema,
92
+ * steps: {
93
+ * accountType: {
94
+ * title: "Account Type",
95
+ * component: AccountTypeStep,
96
+ * },
97
+ * businessDetails: {
98
+ * title: "Business Details",
99
+ * component: BusinessDetailsStep,
100
+ * shouldRender: (formState) => formState.accountType?.type === "business",
101
+ * },
102
+ * confirmation: {
103
+ * title: "Confirmation",
104
+ * component: ConfirmationStep,
105
+ * },
106
+ * },
107
+ * onSubmit: handleSubmit,
108
+ * });
109
+ * ```
22
110
  */
23
111
  export declare const FormWizard: <TFullSchema extends AnyZodObject, TComponentStepDefinitions extends StepDefinitions<TFullSchema>>({ lastStepPrimaryActionLabel, isEdit, steps, fullFormSchema, onCancel, className, "data-testid": dataTestId, basePath, }: FromWizardComponentProps<TFullSchema, TComponentStepDefinitions>) => import("react/jsx-runtime").JSX.Element;