@jfdevelops/react-multi-step-form 1.0.0-alpha.15 → 1.0.0-alpha.16
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/create-context.cjs +92 -0
- package/dist/create-context.cjs.map +1 -0
- package/dist/create-context.d.cts +154 -0
- package/dist/create-context.d.mts +154 -0
- package/dist/create-context.mjs +92 -0
- package/dist/create-context.mjs.map +1 -0
- package/dist/field.cjs +22 -0
- package/dist/field.cjs.map +1 -0
- package/dist/field.d.cts +38 -0
- package/dist/field.d.mts +38 -0
- package/dist/field.mjs +16 -0
- package/dist/field.mjs.map +1 -0
- package/dist/form-config.cjs +32 -0
- package/dist/form-config.cjs.map +1 -0
- package/dist/form-config.d.cts +160 -0
- package/dist/form-config.d.mts +160 -0
- package/dist/form-config.mjs +27 -0
- package/dist/form-config.mjs.map +1 -0
- package/dist/hooks/use-multi-step-form-data.cjs +41 -0
- package/dist/hooks/use-multi-step-form-data.cjs.map +1 -0
- package/dist/hooks/use-multi-step-form-data.d.cts +28 -0
- package/dist/hooks/use-multi-step-form-data.d.mts +28 -0
- package/dist/hooks/use-multi-step-form-data.mjs +39 -0
- package/dist/hooks/use-multi-step-form-data.mjs.map +1 -0
- package/dist/index.cjs +16 -47
- package/dist/index.d.cts +5 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +5 -1911
- package/dist/schema.cjs +44 -0
- package/dist/schema.cjs.map +1 -0
- package/dist/schema.d.cts +34 -0
- package/dist/schema.d.mts +34 -0
- package/dist/schema.mjs +43 -0
- package/dist/schema.mjs.map +1 -0
- package/dist/step-schema.cjs +222 -0
- package/dist/step-schema.cjs.map +1 -0
- package/dist/step-schema.d.cts +132 -0
- package/dist/step-schema.d.mts +132 -0
- package/dist/step-schema.mjs +215 -0
- package/dist/step-schema.mjs.map +1 -0
- package/package.json +9 -9
- package/dist/create-context.d.ts +0 -156
- package/dist/field.d.ts +0 -23
- package/dist/form-config.d.ts +0 -161
- package/dist/hooks/use-multi-step-form-data.d.ts +0 -26
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.mjs.map +0 -1
- package/dist/schema.d.ts +0 -30
- package/dist/step-schema.d.ts +0 -131
- package/dist/utils.d.ts +0 -0
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jfdevelops/react-multi-step-form",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.16",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": "https://github.com/jfdevelops/multi-step-form",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.cjs",
|
|
8
8
|
"module": "./dist/index.mjs",
|
|
9
|
-
"types": "./dist/index.d.
|
|
9
|
+
"types": "./dist/index.d.cts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"
|
|
13
|
-
"import": "./dist/index.mjs"
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
"require": "./dist/index.cjs",
|
|
13
|
+
"import": "./dist/index.mjs"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"dist"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"use-sync-external-store": "^1.6.0",
|
|
39
|
-
"@jfdevelops/multi-step-form-core": "1.0.0-alpha.
|
|
39
|
+
"@jfdevelops/multi-step-form-core": "1.0.0-alpha.13"
|
|
40
40
|
},
|
|
41
41
|
"publishConfig": {
|
|
42
42
|
"access": "public",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
46
|
"dev": "vite",
|
|
47
|
-
"build": "
|
|
48
|
-
"watch": "
|
|
47
|
+
"build": "tsdown",
|
|
48
|
+
"watch": "tsdown --watch"
|
|
49
49
|
}
|
|
50
50
|
}
|
package/dist/create-context.d.ts
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { ComponentProps, ReactNode } from 'react';
|
|
2
|
-
import { UseMultiStepFormData } from './hooks/use-multi-step-form-data';
|
|
3
|
-
import { MultiStepFormSchema, AnyMultiStepFormSchema } from './schema';
|
|
4
|
-
import { CreatedMultiStepFormComponent, CreateFunction } from './step-schema';
|
|
5
|
-
type BaseOptions<TSchema extends AnyMultiStepFormSchema, TTargetStep extends keyof MultiStepFormSchema.resolvedStep<TSchema>> = {
|
|
6
|
-
/**
|
|
7
|
-
* The step to return data from.
|
|
8
|
-
*/
|
|
9
|
-
targetStep: TTargetStep;
|
|
10
|
-
};
|
|
11
|
-
export type UseCurrentStepOptions<TSchema extends AnyMultiStepFormSchema, TTargetStep extends keyof MultiStepFormSchema.resolvedStep<TSchema>, props, isDataGuaranteed extends boolean = false> = BaseOptions<TSchema, TTargetStep> & {
|
|
12
|
-
/**
|
|
13
|
-
* Determines if the result should follow "strictness".
|
|
14
|
-
* The result will change based on the value for this option.
|
|
15
|
-
*
|
|
16
|
-
* - `true`: `data` is **defined** and `hasData` isn't available.
|
|
17
|
-
* - `false`: `data` _can be_ `undefined`, but the `hasData` property is available
|
|
18
|
-
* to help with type narrowing.
|
|
19
|
-
*
|
|
20
|
-
* @default false
|
|
21
|
-
* @example
|
|
22
|
-
* ### `true`
|
|
23
|
-
* ```tsx
|
|
24
|
-
* function MyComponent() {
|
|
25
|
-
* const { data, NoCurrentData } = useCurrentStep({
|
|
26
|
-
* stepNumber: 1,
|
|
27
|
-
* isDataGuaranteed: true,
|
|
28
|
-
* })
|
|
29
|
-
*
|
|
30
|
-
* // Notice how `NoCurrentData` is still available
|
|
31
|
-
* // Do things with `data` here
|
|
32
|
-
* }
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* ### `false` - The default
|
|
36
|
-
* ```tsx
|
|
37
|
-
* function MyComponent() {
|
|
38
|
-
* const { data, NoCurrentData, hasData } = useCurrentStep({
|
|
39
|
-
* stepNumber: 1,
|
|
40
|
-
* })
|
|
41
|
-
*
|
|
42
|
-
* if (!hasData) {
|
|
43
|
-
* return <NoCurrentData />
|
|
44
|
-
* }
|
|
45
|
-
*
|
|
46
|
-
* // Do things with `data` here
|
|
47
|
-
* }
|
|
48
|
-
* ```
|
|
49
|
-
*/
|
|
50
|
-
isDataGuaranteed?: isDataGuaranteed;
|
|
51
|
-
/**
|
|
52
|
-
* An optional transformation function to provide a custom not found message.
|
|
53
|
-
*/
|
|
54
|
-
notFoundMessage?: CreateFunction<[
|
|
55
|
-
ctx: BaseOptions<TSchema, TTargetStep>,
|
|
56
|
-
props: props
|
|
57
|
-
], ReactNode>;
|
|
58
|
-
};
|
|
59
|
-
export interface UseCurrentStepBaseResult<TData = unknown, TProps = undefined> {
|
|
60
|
-
/**
|
|
61
|
-
* The current step's data.
|
|
62
|
-
*/
|
|
63
|
-
data: TData | undefined;
|
|
64
|
-
/**
|
|
65
|
-
* Boolean indicating if the current step has data.
|
|
66
|
-
*/
|
|
67
|
-
hasData: boolean;
|
|
68
|
-
/**
|
|
69
|
-
* Component to render some sort of error if `data` isn't defined.
|
|
70
|
-
*/
|
|
71
|
-
NoCurrentData: CreatedMultiStepFormComponent<TProps extends undefined ? Omit<ComponentProps<'div'>, 'children'> : TProps>;
|
|
72
|
-
}
|
|
73
|
-
export interface UseCurrentStepErrorResult<TData = unknown, TProps = undefined> extends UseCurrentStepBaseResult<TData, TProps> {
|
|
74
|
-
data: undefined;
|
|
75
|
-
hasData: false;
|
|
76
|
-
}
|
|
77
|
-
export interface UseCurrentStepSuccessResult<TData = unknown, TProps = undefined> extends UseCurrentStepBaseResult<TData, TProps> {
|
|
78
|
-
data: TData;
|
|
79
|
-
hasData: true;
|
|
80
|
-
}
|
|
81
|
-
export type UseCurrentStepResult<TSchema extends AnyMultiStepFormSchema, TTargetStep extends keyof MultiStepFormSchema.resolvedStep<TSchema>, props, isDataGuaranteed extends boolean = false> = isDataGuaranteed extends true ? Omit<UseCurrentStepSuccessResult<MultiStepFormSchema.getData<TSchema, TTargetStep>, props>, 'hasData'> : UseCurrentStepErrorResult<MultiStepFormSchema.getData<TSchema, TTargetStep>, props> | UseCurrentStepSuccessResult<MultiStepFormSchema.getData<TSchema, TTargetStep>, props>;
|
|
82
|
-
export type UseProgressBaseOptions<TSchema extends AnyMultiStepFormSchema, TTargetStep extends keyof MultiStepFormSchema.resolvedStep<TSchema>> = BaseOptions<TSchema, TTargetStep> & {
|
|
83
|
-
/**
|
|
84
|
-
* The total amount of steps that are in the form.
|
|
85
|
-
*
|
|
86
|
-
* @default schema.stepData.steps.value.length
|
|
87
|
-
*/
|
|
88
|
-
totalSteps?: number;
|
|
89
|
-
/**
|
|
90
|
-
* The highest value the progress indicator should go.
|
|
91
|
-
*
|
|
92
|
-
* @default 100
|
|
93
|
-
*/
|
|
94
|
-
maxProgressValue?: number;
|
|
95
|
-
};
|
|
96
|
-
export type UseProgressOptions<TSchema extends AnyMultiStepFormSchema, TTargetStep extends keyof MultiStepFormSchema.resolvedStep<TSchema>, props> = UseProgressBaseOptions<TSchema, TTargetStep> & {
|
|
97
|
-
/**
|
|
98
|
-
* An optional transformation function to provide a custom progress text.
|
|
99
|
-
*/
|
|
100
|
-
progressTextTransformer?: CreateFunction<[
|
|
101
|
-
ctx: Required<UseProgressBaseOptions<TSchema, TTargetStep>>,
|
|
102
|
-
props
|
|
103
|
-
], ReactNode>;
|
|
104
|
-
};
|
|
105
|
-
export type UseProgressResult<props> = {
|
|
106
|
-
/**
|
|
107
|
-
* The value of the progress indicator.
|
|
108
|
-
*/
|
|
109
|
-
value: number;
|
|
110
|
-
/**
|
|
111
|
-
* The highest value the progress indicator can be.
|
|
112
|
-
*
|
|
113
|
-
* @default 100
|
|
114
|
-
*/
|
|
115
|
-
maxProgressValue: number;
|
|
116
|
-
ProgressText: CreatedMultiStepFormComponent<props extends undefined ? Omit<ComponentProps<'div'>, 'children'> : props>;
|
|
117
|
-
};
|
|
118
|
-
export type CreateHOC<TContext, TProps> = (ctx: TContext, props: TProps) => CreatedMultiStepFormComponent<TProps>;
|
|
119
|
-
export type MultiStepFormContextResult<TSchema extends AnyMultiStepFormSchema, TResolvedStep extends MultiStepFormSchema.resolvedStep<TSchema> = MultiStepFormSchema.resolvedStep<TSchema>> = {
|
|
120
|
-
useMultiStepFormData: UseMultiStepFormData<TSchema>;
|
|
121
|
-
/**
|
|
122
|
-
* Gets the data for the specified step.
|
|
123
|
-
*
|
|
124
|
-
* @returns The data for the given step number.
|
|
125
|
-
*/
|
|
126
|
-
useCurrentStepData: <targetStep extends keyof TResolvedStep, props = undefined, isDataGuaranteed extends boolean = false>(options: UseCurrentStepOptions<TSchema, targetStep, props, isDataGuaranteed>) => UseCurrentStepResult<TSchema, targetStep, props, isDataGuaranteed>;
|
|
127
|
-
useProgress: <targetStep extends keyof TResolvedStep, props = undefined>(options: UseProgressOptions<TSchema, targetStep, props>) => UseProgressResult<props>;
|
|
128
|
-
/**
|
|
129
|
-
* A hook that can be used to check if the form can be restarted. If no {@linkcode cb}
|
|
130
|
-
* is provided, the return value will be dictated by if there is an object stored in
|
|
131
|
-
* {@link MultiStepFormSchema#storage}.
|
|
132
|
-
* @param cb A callback function to provide custom logic for if the form can restart.
|
|
133
|
-
* @returns A boolean indicating if the form can restart.
|
|
134
|
-
*/
|
|
135
|
-
useCanRestartForm: (cb?: (canRestart: boolean) => boolean) => boolean;
|
|
136
|
-
/**
|
|
137
|
-
* A HOC for creating a custom progress text for `useProgress`.
|
|
138
|
-
* @param options Options for creating the HOC.
|
|
139
|
-
* @param cb The callback function for creating the HOC.
|
|
140
|
-
* @returns A HOC for the `progressTextTransformer` option of the `useProgress` hook.
|
|
141
|
-
*/
|
|
142
|
-
withProgressText: <targetStep extends keyof TResolvedStep, props = undefined>(options: UseProgressBaseOptions<TSchema, targetStep>, cb: (ctx: Required<UseProgressBaseOptions<TSchema, targetStep>>, props: props) => ReactNode) => CreatedMultiStepFormComponent<props>;
|
|
143
|
-
/**
|
|
144
|
-
* A HOC for creating a custom not found component for when a step's data is `undefined`.
|
|
145
|
-
* @param options Options for creating the HOC.
|
|
146
|
-
* @param cb The callback function for creating the HOC.
|
|
147
|
-
* @returns A HOC for the `notFoundMessage` option of the `useCurrentStep` hook.
|
|
148
|
-
*/
|
|
149
|
-
withNoStepDataFound: <targetStep extends keyof TResolvedStep, props = undefined>(options: BaseOptions<TSchema, targetStep>, cb: (ctx: BaseOptions<TSchema, targetStep>, props: props) => ReactNode) => CreatedMultiStepFormComponent<props>;
|
|
150
|
-
};
|
|
151
|
-
/**
|
|
152
|
-
* Create multi step form context with a {@linkcode MultiStepFormSchema} instance.
|
|
153
|
-
* @param schema The {@linkcode MultiStepFormSchema} instance.
|
|
154
|
-
*/
|
|
155
|
-
export declare function createMultiStepFormContext<schema extends AnyMultiStepFormSchema, resolvedStep extends MultiStepFormSchema.resolvedStep<schema> = MultiStepFormSchema.resolvedStep<schema>>(schema: schema): MultiStepFormContextResult<schema>;
|
|
156
|
-
export {};
|
package/dist/field.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { AnyResolvedStep, fields, Override, Updater } from '@jfdevelops/multi-step-form-core';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
3
|
-
export declare namespace Field {
|
|
4
|
-
type sharedProps<TField extends string> = {
|
|
5
|
-
/**
|
|
6
|
-
* The name of the field.
|
|
7
|
-
*/
|
|
8
|
-
name: TField;
|
|
9
|
-
};
|
|
10
|
-
export type childrenProps<TResolvedStep extends AnyResolvedStep, TTargetStep extends keyof TResolvedStep, TField extends fields.getDeep<TResolvedStep, TTargetStep>, TValue extends fields.resolveDeepPath<TResolvedStep, TTargetStep, TField> = fields.resolveDeepPath<TResolvedStep, TTargetStep, TField>> = sharedProps<TField> & Override<fields.get<TResolvedStep, TTargetStep>[fields.parentOf<TField>], 'defaultValue', TValue> & {
|
|
11
|
-
/**
|
|
12
|
-
* A useful wrapper around `update` to update the specific field.
|
|
13
|
-
* @param value The new value for the field.
|
|
14
|
-
*/
|
|
15
|
-
onInputChange: (value: Updater<TValue>) => void;
|
|
16
|
-
};
|
|
17
|
-
export type props<TResolvedStep extends AnyResolvedStep, TTargetStep extends keyof TResolvedStep, TField extends fields.getDeep<TResolvedStep, TTargetStep>> = sharedProps<TField> & {
|
|
18
|
-
children: (props: childrenProps<TResolvedStep, TTargetStep, TField>) => ReactNode;
|
|
19
|
-
};
|
|
20
|
-
export type component<TResolvedStep extends AnyResolvedStep, TTargetStep extends keyof TResolvedStep> = <TField extends fields.getDeep<TResolvedStep, TTargetStep>>(props: props<TResolvedStep, TTargetStep, TField>) => ReactNode;
|
|
21
|
-
export {};
|
|
22
|
-
}
|
|
23
|
-
export declare function createField<TResolvedStep extends AnyResolvedStep, TTargetStep extends keyof TResolvedStep>(propsCreator: <TField extends fields.getDeep<TResolvedStep, TTargetStep>>(name: TField) => Field.childrenProps<TResolvedStep, TTargetStep, TField>): Field.component<TResolvedStep, TTargetStep>;
|
package/dist/form-config.d.ts
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { Expand, HelperFnChosenSteps, StepNumbers, ValidStepKey } from '@jfdevelops/multi-step-form-core';
|
|
2
|
-
import { ComponentPropsWithRef, JSX } from 'react';
|
|
3
|
-
import { AnyResolvedStep, CreatedMultiStepFormComponent } from './step-schema';
|
|
4
|
-
export declare namespace MultiStepFormSchemaConfig {
|
|
5
|
-
export const DEFAULT_FORM_ALIAS = "Form";
|
|
6
|
-
export type defaultEnabledFor = HelperFnChosenSteps.defaultStringOption;
|
|
7
|
-
export type defaultFormAlias = typeof DEFAULT_FORM_ALIAS;
|
|
8
|
-
export type formEnabledFor<TResolvedStep extends AnyResolvedStep> = HelperFnChosenSteps<TResolvedStep, StepNumbers<TResolvedStep>>;
|
|
9
|
-
type strippedResolvedSteps<T extends AnyResolvedStep> = {
|
|
10
|
-
[_ in keyof T]: Expand<Omit<T[_], 'createComponent' | 'createHelperFn'>>;
|
|
11
|
-
};
|
|
12
|
-
export type AvailableStepForForm<TResolvedStep extends AnyResolvedStep, TEnabledFor extends formEnabledFor<TResolvedStep>> = TEnabledFor extends defaultEnabledFor ? strippedResolvedSteps<TResolvedStep> : TEnabledFor extends [
|
|
13
|
-
ValidStepKey<StepNumbers<TResolvedStep>>,
|
|
14
|
-
...ValidStepKey<StepNumbers<TResolvedStep>>[]
|
|
15
|
-
] ? TEnabledFor[number] extends keyof TResolvedStep ? Pick<strippedResolvedSteps<TResolvedStep>, TEnabledFor[number]> : never : keyof TEnabledFor extends keyof TResolvedStep ? Expand<Pick<strippedResolvedSteps<TResolvedStep>, Extract<keyof TResolvedStep, keyof TEnabledFor>>> : never;
|
|
16
|
-
export type formCtx<TAlias extends string, TProps> = {
|
|
17
|
-
[_ in TAlias]: CreatedMultiStepFormComponent<TProps>;
|
|
18
|
-
};
|
|
19
|
-
export type renderFnData<TResolvedStep extends AnyResolvedStep, TEnabledFor extends formEnabledFor<TResolvedStep>> = {
|
|
20
|
-
/**
|
|
21
|
-
* The id for the form, either a custom one or the default one.
|
|
22
|
-
*/
|
|
23
|
-
id: string;
|
|
24
|
-
/**
|
|
25
|
-
* The chosen steps that are available.
|
|
26
|
-
*/
|
|
27
|
-
steps: Expand<AvailableStepForForm<TResolvedStep, TEnabledFor>>;
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* The configuration options for the `form` option.
|
|
31
|
-
*/
|
|
32
|
-
export interface FormConfig<TResolvedStep extends AnyResolvedStep, TAlias extends string, TFormEnabledFor extends formEnabledFor<TResolvedStep>, TCustomFormProps extends object> {
|
|
33
|
-
/**
|
|
34
|
-
* The `id` for the form component.
|
|
35
|
-
*
|
|
36
|
-
* If there is no value provided, the default id will the **current step key**.
|
|
37
|
-
*
|
|
38
|
-
* @default `${currentStep}`
|
|
39
|
-
*/
|
|
40
|
-
id?: string;
|
|
41
|
-
/**
|
|
42
|
-
* The "name" of the form component.
|
|
43
|
-
* @default 'Form'
|
|
44
|
-
* @example
|
|
45
|
-
* ```tsx
|
|
46
|
-
* const schema = createMultiStepFormSchema({
|
|
47
|
-
* steps: {
|
|
48
|
-
* step1: {
|
|
49
|
-
* title: 'Step 1',
|
|
50
|
-
* fields: {
|
|
51
|
-
* firstName: {
|
|
52
|
-
* defaultValue: ''
|
|
53
|
-
* }
|
|
54
|
-
* }
|
|
55
|
-
* },
|
|
56
|
-
* form: {
|
|
57
|
-
* alias: 'MyCustomForm',
|
|
58
|
-
* render() {
|
|
59
|
-
* // return custom form component here
|
|
60
|
-
* }
|
|
61
|
-
* }
|
|
62
|
-
* }
|
|
63
|
-
* })
|
|
64
|
-
*
|
|
65
|
-
* const Step1 = schema.stepSchema.step1.createComponent(
|
|
66
|
-
* ({ ctx, MyCustomForm }, props: { children: ReactNode }) =>
|
|
67
|
-
* // Notice how the form is available with its alias
|
|
68
|
-
* <MyCustomFormName>{children}</MyCustomFormName>
|
|
69
|
-
* )
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
alias?: TAlias;
|
|
73
|
-
/**
|
|
74
|
-
* If the form component should be accessible for each step when calling `createComponent`.
|
|
75
|
-
*
|
|
76
|
-
* If no value is given, the form will be accessible for all the steps.
|
|
77
|
-
*/
|
|
78
|
-
enabledForSteps?: TFormEnabledFor;
|
|
79
|
-
/**
|
|
80
|
-
*
|
|
81
|
-
* @param data The data that is available for creating the custom form.
|
|
82
|
-
* @param props Props that can be used for the custom form.
|
|
83
|
-
* @returns An {@see JSX.Element} that is the custom form.
|
|
84
|
-
* @example
|
|
85
|
-
* ### With custom props
|
|
86
|
-
* ```tsx
|
|
87
|
-
* type CustomProps = {
|
|
88
|
-
* title: string;
|
|
89
|
-
* description?: string;
|
|
90
|
-
* children: ReactNode;
|
|
91
|
-
* };
|
|
92
|
-
*
|
|
93
|
-
* const schema = createMultiStepFormSchema({
|
|
94
|
-
* steps: {
|
|
95
|
-
* step1: {
|
|
96
|
-
* title: 'Step 1',
|
|
97
|
-
* fields: {
|
|
98
|
-
* firstName: {
|
|
99
|
-
* defaultValue: ''
|
|
100
|
-
* }
|
|
101
|
-
* }
|
|
102
|
-
* },
|
|
103
|
-
* form: {
|
|
104
|
-
* alias: 'MyCustomForm',
|
|
105
|
-
* render(data, props: CustomProps) {
|
|
106
|
-
* return (
|
|
107
|
-
* <div>
|
|
108
|
-
* <h1>{props.title}</h1>
|
|
109
|
-
* <p>{props.description}</p>
|
|
110
|
-
* <form>{props.children}</form>
|
|
111
|
-
* </div>
|
|
112
|
-
* );
|
|
113
|
-
* }
|
|
114
|
-
* }
|
|
115
|
-
* }
|
|
116
|
-
* })
|
|
117
|
-
* ```
|
|
118
|
-
* ### Without custom props
|
|
119
|
-
* ```tsx
|
|
120
|
-
* const schema = createMultiStepFormSchema({
|
|
121
|
-
* steps: {
|
|
122
|
-
* step1: {
|
|
123
|
-
* title: 'Step 1',
|
|
124
|
-
* fields: {
|
|
125
|
-
* firstName: {
|
|
126
|
-
* defaultValue: ''
|
|
127
|
-
* }
|
|
128
|
-
* }
|
|
129
|
-
* },
|
|
130
|
-
* form: {
|
|
131
|
-
* alias: 'MyCustomForm',
|
|
132
|
-
* render(data, props) {
|
|
133
|
-
* // The default type for `props` will be `ComponentPropsWithRef<'form'>`
|
|
134
|
-
* // return custom form component here
|
|
135
|
-
* }
|
|
136
|
-
* }
|
|
137
|
-
* }
|
|
138
|
-
* })
|
|
139
|
-
* ```
|
|
140
|
-
*/
|
|
141
|
-
render: (data: renderFnData<TResolvedStep, TFormEnabledFor>, props: TCustomFormProps) => JSX.Element;
|
|
142
|
-
}
|
|
143
|
-
export interface Form<TResolvedStep extends AnyResolvedStep, TAlias extends string, TFormEnabledFor extends formEnabledFor<TResolvedStep>, TCustomFormProps extends object> {
|
|
144
|
-
form?: FormConfig<TResolvedStep, TAlias, TFormEnabledFor, TCustomFormProps>;
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Compares {@linkcode enabledFor} to the {@linkcode target} to determine if the form
|
|
148
|
-
* should be available.
|
|
149
|
-
* @param target The target steps the form _should_ be available for.
|
|
150
|
-
* @param enabledFor The steps that the form _is_ enabled for.
|
|
151
|
-
* @returns A boolean representing if the form should be available.
|
|
152
|
-
*/
|
|
153
|
-
export function isFormAvailable<TResolvedStep extends AnyResolvedStep, TTarget extends HelperFnChosenSteps<TResolvedStep, StepNumbers<TResolvedStep>>, TEnabledFor extends formEnabledFor<TResolvedStep>>(target: TTarget, enabledFor: TEnabledFor): boolean;
|
|
154
|
-
/**
|
|
155
|
-
* Creates a form component with a default id.
|
|
156
|
-
* @param id The default id for the form.
|
|
157
|
-
* @returns A form component with a default {@linkcode id}.
|
|
158
|
-
*/
|
|
159
|
-
export function createDefaultForm(id: string): (props: Omit<ComponentPropsWithRef<"form">, "id">) => import("react/jsx-runtime").JSX.Element;
|
|
160
|
-
export {};
|
|
161
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { AnyMultiStepFormSchema, MultiStepFormSchema } from '../schema';
|
|
2
|
-
export type UseMultiStepFormDataOptions<TSchema extends AnyMultiStepFormSchema, TTarget extends keyof MultiStepFormSchema.resolvedStep<TSchema> = keyof MultiStepFormSchema.resolvedStep<TSchema>> = {
|
|
3
|
-
targetStep: TTarget;
|
|
4
|
-
};
|
|
5
|
-
export type UseMultiStepFormData<TSchema extends AnyMultiStepFormSchema, TResolvedStep extends MultiStepFormSchema.resolvedStep<TSchema> = MultiStepFormSchema.resolvedStep<TSchema>> = {
|
|
6
|
-
/**
|
|
7
|
-
* Returns the entire {@linkcode MultiStepFormSchema instance}.
|
|
8
|
-
*/
|
|
9
|
-
(): TSchema;
|
|
10
|
-
/**
|
|
11
|
-
* Returns the data for the target step.
|
|
12
|
-
* @param stepNumber The step number to return.
|
|
13
|
-
* @throws {TypeError} If `options.stepNumber` is invalid.
|
|
14
|
-
*/
|
|
15
|
-
<targetStep extends keyof TResolvedStep>(options: UseMultiStepFormDataOptions<TSchema, targetStep>): MultiStepFormSchema.getData<TSchema, targetStep>;
|
|
16
|
-
/**
|
|
17
|
-
* Returns the specified data from the {@linkcode MultiStepFormSchema} instance via the callback's return.
|
|
18
|
-
*/
|
|
19
|
-
<data>(selector: (schema: TSchema) => data): data;
|
|
20
|
-
};
|
|
21
|
-
export declare function throwIfInvalidStepNumber<schema extends AnyMultiStepFormSchema>(schema: schema, targetStep: unknown): MultiStepFormSchema.stepNumbers<schema>;
|
|
22
|
-
export declare function createMultiStepFormDataHook<schema extends AnyMultiStepFormSchema>(schema: schema): UseMultiStepFormData<schema>;
|
|
23
|
-
declare function useMultiStepFormData<schema extends AnyMultiStepFormSchema>(schema: schema): schema;
|
|
24
|
-
declare function useMultiStepFormData<schema extends AnyMultiStepFormSchema, targetStep extends keyof MultiStepFormSchema.resolvedStep<schema>>(schema: schema, options: UseMultiStepFormDataOptions<schema, targetStep>): MultiStepFormSchema.getData<schema, targetStep>;
|
|
25
|
-
declare function useMultiStepFormData<schema extends AnyMultiStepFormSchema, data>(schema: schema, selector: (schema: schema) => data): data;
|
|
26
|
-
export { useMultiStepFormData };
|