@ereo/forms 0.1.23
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/a11y.d.ts +52 -0
- package/dist/a11y.d.ts.map +1 -0
- package/dist/accessibility.d.ts +152 -0
- package/dist/accessibility.d.ts.map +1 -0
- package/dist/action-integration.d.ts +104 -0
- package/dist/action-integration.d.ts.map +1 -0
- package/dist/action.d.ts +33 -0
- package/dist/action.d.ts.map +1 -0
- package/dist/adapters.d.ts +25 -0
- package/dist/adapters.d.ts.map +1 -0
- package/dist/array-field.d.ts +49 -0
- package/dist/array-field.d.ts.map +1 -0
- package/dist/components.d.ts +8 -0
- package/dist/components.d.ts.map +1 -0
- package/dist/composition.d.ts +4 -0
- package/dist/composition.d.ts.map +1 -0
- package/dist/context.d.ts +9 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/field.d.ts +88 -0
- package/dist/field.d.ts.map +1 -0
- package/dist/form.d.ts +59 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/hooks.d.ts +13 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2945 -0
- package/dist/proxy.d.ts +3 -0
- package/dist/proxy.d.ts.map +1 -0
- package/dist/schema.d.ts +31 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/store.d.ts +69 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/types.d.ts +243 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/validation-engine.d.ts +33 -0
- package/dist/validation-engine.d.ts.map +1 -0
- package/dist/validation.d.ts +241 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validators.d.ts +51 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/wizard.d.ts +52 -0
- package/dist/wizard.d.ts.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ereo/forms - Validation System
|
|
3
|
+
*
|
|
4
|
+
* Built-in validators with async support and debouncing.
|
|
5
|
+
*/
|
|
6
|
+
import type { ValidationRule, ValidatorFunction, ValidationResult } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* Built-in validation rules.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* const form = createForm({
|
|
12
|
+
* initialValues: { email: '', age: 0 },
|
|
13
|
+
* validators: {
|
|
14
|
+
* email: [validators.required(), validators.email()],
|
|
15
|
+
* age: [validators.required(), validators.min(18)],
|
|
16
|
+
* },
|
|
17
|
+
* });
|
|
18
|
+
*/
|
|
19
|
+
export declare const validators: {
|
|
20
|
+
/**
|
|
21
|
+
* Required field validator.
|
|
22
|
+
*/
|
|
23
|
+
required: (message?: string) => ValidationRule;
|
|
24
|
+
/**
|
|
25
|
+
* Email format validator.
|
|
26
|
+
*/
|
|
27
|
+
email: (message?: string) => ValidationRule;
|
|
28
|
+
/**
|
|
29
|
+
* Minimum length validator for strings and arrays.
|
|
30
|
+
*/
|
|
31
|
+
minLength: (length: number, message?: string) => ValidationRule;
|
|
32
|
+
/**
|
|
33
|
+
* Maximum length validator for strings and arrays.
|
|
34
|
+
*/
|
|
35
|
+
maxLength: (length: number, message?: string) => ValidationRule;
|
|
36
|
+
/**
|
|
37
|
+
* Minimum value validator for numbers.
|
|
38
|
+
*/
|
|
39
|
+
min: (minValue: number, message?: string) => ValidationRule;
|
|
40
|
+
/**
|
|
41
|
+
* Maximum value validator for numbers.
|
|
42
|
+
*/
|
|
43
|
+
max: (maxValue: number, message?: string) => ValidationRule;
|
|
44
|
+
/**
|
|
45
|
+
* Pattern validator using regex.
|
|
46
|
+
*/
|
|
47
|
+
pattern: (regex: RegExp, message?: string) => ValidationRule;
|
|
48
|
+
/**
|
|
49
|
+
* URL format validator.
|
|
50
|
+
*/
|
|
51
|
+
url: (message?: string) => ValidationRule;
|
|
52
|
+
/**
|
|
53
|
+
* Date validator (checks if value is a valid date).
|
|
54
|
+
*/
|
|
55
|
+
date: (message?: string) => ValidationRule;
|
|
56
|
+
/**
|
|
57
|
+
* Number validator.
|
|
58
|
+
*/
|
|
59
|
+
number: (message?: string) => ValidationRule;
|
|
60
|
+
/**
|
|
61
|
+
* Integer validator.
|
|
62
|
+
*/
|
|
63
|
+
integer: (message?: string) => ValidationRule;
|
|
64
|
+
/**
|
|
65
|
+
* Positive number validator.
|
|
66
|
+
*/
|
|
67
|
+
positive: (message?: string) => ValidationRule;
|
|
68
|
+
/**
|
|
69
|
+
* Custom validation function.
|
|
70
|
+
*/
|
|
71
|
+
custom: <T = unknown>(fn: ValidatorFunction<T>, message?: string) => ValidationRule<T>;
|
|
72
|
+
/**
|
|
73
|
+
* Async validation with optional debouncing.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* validators.async(async (value, signal) => {
|
|
77
|
+
* const response = await fetch(`/api/check-email?email=${value}`, { signal });
|
|
78
|
+
* const { available } = await response.json();
|
|
79
|
+
* return available || 'Email already taken';
|
|
80
|
+
* }, { debounce: 300 })
|
|
81
|
+
*/
|
|
82
|
+
async: <T = unknown>(fn: (value: T, signal?: AbortSignal) => Promise<boolean | string>, options?: {
|
|
83
|
+
debounce?: number;
|
|
84
|
+
message?: string;
|
|
85
|
+
}) => ValidationRule<T>;
|
|
86
|
+
/**
|
|
87
|
+
* Match another field's value.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* validators.matches('password', 'Passwords must match')
|
|
91
|
+
*/
|
|
92
|
+
matches: (otherField: string, message?: string, getFieldValue?: (path: string) => unknown) => ValidationRule;
|
|
93
|
+
/**
|
|
94
|
+
* One of allowed values.
|
|
95
|
+
*/
|
|
96
|
+
oneOf: <T>(values: T[], message?: string) => ValidationRule<T>;
|
|
97
|
+
/**
|
|
98
|
+
* Not one of disallowed values.
|
|
99
|
+
*/
|
|
100
|
+
notOneOf: <T>(values: T[], message?: string) => ValidationRule<T>;
|
|
101
|
+
/**
|
|
102
|
+
* Phone number validator (basic format).
|
|
103
|
+
*/
|
|
104
|
+
phone: (message?: string) => ValidationRule;
|
|
105
|
+
/**
|
|
106
|
+
* File size validator (in bytes).
|
|
107
|
+
*/
|
|
108
|
+
fileSize: (maxSize: number, message?: string) => ValidationRule<File | FileList>;
|
|
109
|
+
/**
|
|
110
|
+
* File type validator.
|
|
111
|
+
*/
|
|
112
|
+
fileType: (allowedTypes: string[], message?: string) => ValidationRule<File | FileList>;
|
|
113
|
+
};
|
|
114
|
+
/**
|
|
115
|
+
* Create a validator that compares with another field.
|
|
116
|
+
* Pass the form's getValue function to enable cross-field access.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* const form = createForm({
|
|
120
|
+
* initialValues: { password: '', confirmPassword: '' },
|
|
121
|
+
* validators: {
|
|
122
|
+
* confirmPassword: crossField(
|
|
123
|
+
* (value, getValue) => value === getValue('password'),
|
|
124
|
+
* 'Passwords must match'
|
|
125
|
+
* ),
|
|
126
|
+
* },
|
|
127
|
+
* });
|
|
128
|
+
*/
|
|
129
|
+
export declare function crossField<T = unknown>(validate: (value: T, getValue: (path: string) => unknown, values: Record<string, unknown>) => boolean | string, message?: string): ValidationRule<T> & {
|
|
130
|
+
_crossField: true;
|
|
131
|
+
_validate: typeof validate;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Create a validator that checks if value equals another field.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* validators: {
|
|
138
|
+
* confirmPassword: equalTo('password', 'Passwords must match'),
|
|
139
|
+
* }
|
|
140
|
+
*/
|
|
141
|
+
export declare function equalTo(otherField: string, message?: string): ValidationRule & {
|
|
142
|
+
_crossField: true;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Create a validator that checks if value is different from another field.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* validators: {
|
|
149
|
+
* newPassword: notEqualTo('currentPassword', 'New password must be different'),
|
|
150
|
+
* }
|
|
151
|
+
*/
|
|
152
|
+
export declare function notEqualTo(otherField: string, message?: string): ValidationRule & {
|
|
153
|
+
_crossField: true;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Create a validator that checks if date is after another field's date.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* validators: {
|
|
160
|
+
* endDate: dateAfter('startDate', 'End date must be after start date'),
|
|
161
|
+
* }
|
|
162
|
+
*/
|
|
163
|
+
export declare function dateAfter(otherField: string, message?: string): ValidationRule<Date | string> & {
|
|
164
|
+
_crossField: true;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* Create a validator that checks if date is before another field's date.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* validators: {
|
|
171
|
+
* startDate: dateBefore('endDate', 'Start date must be before end date'),
|
|
172
|
+
* }
|
|
173
|
+
*/
|
|
174
|
+
export declare function dateBefore(otherField: string, message?: string): ValidationRule<Date | string> & {
|
|
175
|
+
_crossField: true;
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Create a validator that checks if number is less than another field.
|
|
179
|
+
*/
|
|
180
|
+
export declare function lessThan(otherField: string, message?: string): ValidationRule<number> & {
|
|
181
|
+
_crossField: true;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Create a validator that checks if number is greater than another field.
|
|
185
|
+
*/
|
|
186
|
+
export declare function greaterThan(otherField: string, message?: string): ValidationRule<number> & {
|
|
187
|
+
_crossField: true;
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Check if a validator is a cross-field validator.
|
|
191
|
+
*/
|
|
192
|
+
export declare function isCrossFieldValidator(rule: ValidationRule): rule is ValidationRule & {
|
|
193
|
+
_crossField: true;
|
|
194
|
+
_validate: Function;
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* Compose multiple validators into one.
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* const passwordValidator = composeValidators(
|
|
201
|
+
* validators.required(),
|
|
202
|
+
* validators.minLength(8),
|
|
203
|
+
* validators.pattern(/[A-Z]/, 'Must contain uppercase'),
|
|
204
|
+
* validators.pattern(/[0-9]/, 'Must contain number'),
|
|
205
|
+
* );
|
|
206
|
+
*/
|
|
207
|
+
export declare function composeValidators(...rules: ValidationRule[]): ValidationRule;
|
|
208
|
+
/**
|
|
209
|
+
* Create a conditional validator.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* const conditionalValidator = when(
|
|
213
|
+
* (value, form) => form.getValue('sendEmail'),
|
|
214
|
+
* validators.email()
|
|
215
|
+
* );
|
|
216
|
+
*/
|
|
217
|
+
export declare function when<T = unknown>(condition: (value: T, context?: unknown) => boolean, validator: ValidationRule<T>, context?: unknown): ValidationRule<T>;
|
|
218
|
+
/**
|
|
219
|
+
* Debounce an async validator.
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* const debouncedEmailCheck = debounceValidator(
|
|
223
|
+
* async (email) => {
|
|
224
|
+
* const response = await fetch(`/api/check-email?email=${email}`);
|
|
225
|
+
* const { available } = await response.json();
|
|
226
|
+
* return available;
|
|
227
|
+
* },
|
|
228
|
+
* 300
|
|
229
|
+
* );
|
|
230
|
+
*/
|
|
231
|
+
export declare function debounceValidator<T>(validator: (value: T, signal?: AbortSignal) => Promise<boolean | string>, delay: number): (value: T, signal?: AbortSignal) => Promise<boolean | string>;
|
|
232
|
+
/**
|
|
233
|
+
* Create a validation result object.
|
|
234
|
+
*/
|
|
235
|
+
export declare function createValidationResult(errors?: Record<string, string[]>): ValidationResult;
|
|
236
|
+
/**
|
|
237
|
+
* Merge multiple validation results.
|
|
238
|
+
*/
|
|
239
|
+
export declare function mergeValidationResults(...results: ValidationResult[]): ValidationResult;
|
|
240
|
+
export type { ValidationRule, ValidatorFunction, ValidationResult };
|
|
241
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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AM,EAAE,CAAM,GACpC,gBAAgB,CAKlB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,OAAO,EAAE,gBAAgB,EAAE,GAAG,gBAAgB,CAavF;AAGD,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ValidatorFunction } from './types';
|
|
2
|
+
export declare function required(msg?: string): ValidatorFunction;
|
|
3
|
+
export declare function email(msg?: string): ValidatorFunction<string>;
|
|
4
|
+
export declare function url(msg?: string): ValidatorFunction<string>;
|
|
5
|
+
export declare function date(msg?: string): ValidatorFunction<string>;
|
|
6
|
+
export declare function phone(msg?: string): ValidatorFunction<string>;
|
|
7
|
+
export declare function minLength(n: number, msg?: string): ValidatorFunction<string>;
|
|
8
|
+
export declare function maxLength(n: number, msg?: string): ValidatorFunction<string>;
|
|
9
|
+
export declare function min(n: number, msg?: string): ValidatorFunction<number>;
|
|
10
|
+
export declare function max(n: number, msg?: string): ValidatorFunction<number>;
|
|
11
|
+
export declare function pattern(regex: RegExp, msg?: string): ValidatorFunction<string>;
|
|
12
|
+
export declare function number(msg?: string): ValidatorFunction;
|
|
13
|
+
export declare function integer(msg?: string): ValidatorFunction;
|
|
14
|
+
export declare function positive(msg?: string): ValidatorFunction<number>;
|
|
15
|
+
export declare function custom<T = unknown>(fn: (value: T) => string | undefined, msg?: string): ValidatorFunction<T>;
|
|
16
|
+
export declare function async<T = unknown>(fn: (value: T) => Promise<string | undefined>, opts?: {
|
|
17
|
+
debounce?: number;
|
|
18
|
+
message?: string;
|
|
19
|
+
}): ValidatorFunction<T>;
|
|
20
|
+
export declare function matches(otherField: string, msg?: string): ValidatorFunction;
|
|
21
|
+
export declare function oneOf<T>(values: T[], msg?: string): ValidatorFunction<T>;
|
|
22
|
+
export declare function notOneOf<T>(values: T[], msg?: string): ValidatorFunction<T>;
|
|
23
|
+
export declare function fileSize(maxBytes: number, msg?: string): ValidatorFunction;
|
|
24
|
+
export declare function fileType(types: string[], msg?: string): ValidatorFunction;
|
|
25
|
+
export declare function compose<T = unknown>(...rules: ValidatorFunction<T>[]): ValidatorFunction<T>;
|
|
26
|
+
export declare function when<T = unknown>(condition: (value: T, context?: any) => boolean, rule: ValidatorFunction<T>): ValidatorFunction<T>;
|
|
27
|
+
export declare const v: {
|
|
28
|
+
required: typeof required;
|
|
29
|
+
email: typeof email;
|
|
30
|
+
url: typeof url;
|
|
31
|
+
date: typeof date;
|
|
32
|
+
phone: typeof phone;
|
|
33
|
+
minLength: typeof minLength;
|
|
34
|
+
maxLength: typeof maxLength;
|
|
35
|
+
min: typeof min;
|
|
36
|
+
max: typeof max;
|
|
37
|
+
pattern: typeof pattern;
|
|
38
|
+
number: typeof number;
|
|
39
|
+
integer: typeof integer;
|
|
40
|
+
positive: typeof positive;
|
|
41
|
+
custom: typeof custom;
|
|
42
|
+
async: typeof async;
|
|
43
|
+
matches: typeof matches;
|
|
44
|
+
oneOf: typeof oneOf;
|
|
45
|
+
notOneOf: typeof notOneOf;
|
|
46
|
+
fileSize: typeof fileSize;
|
|
47
|
+
fileType: typeof fileType;
|
|
48
|
+
compose: typeof compose;
|
|
49
|
+
when: typeof when;
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAIjD,wBAAgB,QAAQ,CAAC,GAAG,SAA2B,GAAG,iBAAiB,CAQ1E;AAED,wBAAgB,KAAK,CAAC,GAAG,SAA0B,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAM9E;AAED,wBAAgB,GAAG,CAAC,GAAG,SAAgB,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAUlE;AAED,wBAAgB,IAAI,CAAC,GAAG,SAAiB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AAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,GAC7C,iBAAiB,CAAC,CAAC,CAAC,CAKtB;AAID,wBAAgB,OAAO,CACrB,UAAU,EAAE,MAAM,EAClB,GAAG,CAAC,EAAE,MAAM,GACX,iBAAiB,CAQnB;AAID,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAOxE;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAO3E;AAID,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,iBAAiB,CAS1E;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,iBAAiB,CASzE;AAID,wBAAgB,OAAO,CAAC,CAAC,GAAG,OAAO,EACjC,GAAG,KAAK,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,GAC/B,iBAAiB,CAAC,CAAC,CAAC,CAwBtB;AAED,wBAAgB,IAAI,CAAC,CAAC,GAAG,OAAO,EAC9B,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,GAAG,KAAK,OAAO,EAC/C,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,GACzB,iBAAiB,CAAC,CAAC,CAAC,CAatB;AAID,eAAO,MAAM,CAAC;;;;;;;;;;;;;;;;;;;;;;;CAuBb,CAAC"}
|
package/dist/wizard.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { ReactNode, ReactElement } from 'react';
|
|
2
|
+
import { Signal } from '@ereo/state';
|
|
3
|
+
import { FormStore } from './store';
|
|
4
|
+
import type { WizardConfig, WizardStepConfig, WizardState } from './types';
|
|
5
|
+
export interface WizardHelpers<T extends Record<string, any>> {
|
|
6
|
+
form: FormStore<T>;
|
|
7
|
+
currentStep: Signal<number>;
|
|
8
|
+
completedSteps: Signal<Set<string>>;
|
|
9
|
+
state: WizardState;
|
|
10
|
+
next: () => Promise<boolean>;
|
|
11
|
+
prev: () => void;
|
|
12
|
+
goTo: (stepIdOrIndex: string | number) => void;
|
|
13
|
+
submit: () => Promise<void>;
|
|
14
|
+
reset: () => void;
|
|
15
|
+
dispose: () => void;
|
|
16
|
+
getStepConfig: (index: number) => WizardStepConfig | undefined;
|
|
17
|
+
canGoNext: () => boolean;
|
|
18
|
+
canGoPrev: () => boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare function createWizard<T extends Record<string, any>>(config: WizardConfig<T>): WizardHelpers<T>;
|
|
21
|
+
export declare function useWizard<T extends Record<string, any>>(config: WizardConfig<T>): WizardHelpers<T> & {
|
|
22
|
+
currentStepState: WizardState;
|
|
23
|
+
};
|
|
24
|
+
export interface WizardProviderProps<T extends Record<string, any>> {
|
|
25
|
+
wizard: WizardHelpers<T>;
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
}
|
|
28
|
+
export declare function WizardProvider<T extends Record<string, any>>({ wizard, children, }: WizardProviderProps<T>): ReactElement;
|
|
29
|
+
export declare function useWizardContext<T extends Record<string, any> = Record<string, any>>(): WizardHelpers<T> | null;
|
|
30
|
+
export interface WizardStepProps {
|
|
31
|
+
id: string;
|
|
32
|
+
wizard?: WizardHelpers<any>;
|
|
33
|
+
keepMounted?: boolean;
|
|
34
|
+
children: ReactNode;
|
|
35
|
+
}
|
|
36
|
+
export declare function WizardStep({ id, wizard: wizardProp, keepMounted, children, }: WizardStepProps): ReactElement | null;
|
|
37
|
+
export interface WizardProgressProps {
|
|
38
|
+
wizard?: WizardHelpers<any>;
|
|
39
|
+
renderStep?: (step: WizardStepConfig, index: number, state: {
|
|
40
|
+
isActive: boolean;
|
|
41
|
+
isCompleted: boolean;
|
|
42
|
+
}) => ReactNode;
|
|
43
|
+
}
|
|
44
|
+
export declare function WizardProgress({ wizard: wizardProp, renderStep, }: WizardProgressProps): ReactElement | null;
|
|
45
|
+
export interface WizardNavigationProps {
|
|
46
|
+
wizard?: WizardHelpers<any>;
|
|
47
|
+
backLabel?: string;
|
|
48
|
+
nextLabel?: string;
|
|
49
|
+
submitLabel?: string;
|
|
50
|
+
}
|
|
51
|
+
export declare function WizardNavigation({ wizard: wizardProp, backLabel, nextLabel, submitLabel, }: WizardNavigationProps): ReactElement | null;
|
|
52
|
+
//# sourceMappingURL=wizard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wizard.d.ts","sourceRoot":"","sources":["../src/wizard.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAAU,MAAM,EAAS,MAAM,aAAa,CAAC;AAEpD,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEpC,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,WAAW,EAGZ,MAAM,SAAS,CAAC;AAIjB,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAC1D,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5B,cAAc,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IACpC,KAAK,EAAE,WAAW,CAAC;IACnB,IAAI,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;IAC7B,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,IAAI,EAAE,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,KAAK,IAAI,CAAC;IAC/C,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;I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,EAAE,SAAS,CAAC;CACrB;AAED,wBAAgB,UAAU,CAAC,EACzB,EAAE,EACF,MAAM,EAAE,UAAU,EAClB,WAAmB,EACnB,QAAQ,GACT,EAAE,eAAe,GAAG,YAAY,GAAG,IAAI,CAwBvC;AAID,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC5B,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE;QAAE,QAAQ,EAAE,OAAO,CAAC;QAAC,WAAW,EAAE,OAAO,CAAA;KAAE,KAAK,SAAS,CAAC;CACvH;AAED,wBAAgB,cAAc,CAAC,EAC7B,MAAM,EAAE,UAAU,EAClB,UAAU,GACX,EAAE,mBAAmB,GAAG,YAAY,GAAG,IAAI,CAkD3C;AAID,MAAM,WAAW,qBAAqB;IACpC,MAAM,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAC5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,wBAAgB,gBAAgB,CAAC,EAC/B,MAAM,EAAE,UAAU,EAClB,SAAkB,EAClB,SAAkB,EAClB,WAAsB,GACvB,EAAE,qBAAqB,GAAG,YAAY,GAAG,IAAI,CAkC7C"}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ereo/forms",
|
|
3
|
+
"version": "0.1.23",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Ereo Team",
|
|
6
|
+
"homepage": "https://ereo.dev",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/ereojs/ereo.git",
|
|
10
|
+
"directory": "packages/forms"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/ereojs/ereo/issues"
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./dist/index.js",
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "bun build ./src/index.ts --outdir ./dist --target browser --external @ereo/state --external @ereo/client --external @ereo/data --external react --external react-dom && bun run build:types",
|
|
29
|
+
"build:types": "tsc --emitDeclarationOnly --outDir dist",
|
|
30
|
+
"dev": "bun build ./src/index.ts --outdir ./dist --target browser --watch",
|
|
31
|
+
"test": "bun test",
|
|
32
|
+
"typecheck": "tsc --noEmit"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@ereo/state": "^0.1.23"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"react": "^18.2.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependenciesMeta": {
|
|
41
|
+
"@ereo/client": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
44
|
+
"@ereo/data": {
|
|
45
|
+
"optional": true
|
|
46
|
+
},
|
|
47
|
+
"zod": {
|
|
48
|
+
"optional": true
|
|
49
|
+
},
|
|
50
|
+
"valibot": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@types/bun": "^1.1.0",
|
|
56
|
+
"@types/react": "^18.2.0",
|
|
57
|
+
"@types/react-dom": "^18.2.0",
|
|
58
|
+
"typescript": "^5.4.0"
|
|
59
|
+
}
|
|
60
|
+
}
|