@saas-ui/forms 2.0.0-next.2 → 2.0.0-next.21
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +194 -0
- package/README.md +53 -6
- package/dist/ajv/index.d.ts +24 -11
- package/dist/ajv/index.js +7 -9
- package/dist/ajv/index.js.map +1 -1
- package/dist/ajv/index.mjs +7 -10
- package/dist/ajv/index.mjs.map +1 -1
- package/dist/index.d.ts +519 -280
- package/dist/index.js +777 -696
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +756 -676
- package/dist/index.mjs.map +1 -1
- package/dist/yup/index.d.ts +525 -21
- package/dist/yup/index.js +21 -9
- package/dist/yup/index.js.map +1 -1
- package/dist/yup/index.mjs +21 -10
- package/dist/yup/index.mjs.map +1 -1
- package/dist/zod/index.d.ts +525 -12
- package/dist/zod/index.js +21 -1
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.mjs +21 -3
- package/dist/zod/index.mjs.map +1 -1
- package/package.json +33 -10
- package/src/array-field.tsx +88 -48
- package/src/auto-form.tsx +7 -3
- package/src/base-field.tsx +54 -0
- package/src/create-field.tsx +144 -0
- package/src/create-form.tsx +68 -0
- package/src/create-step-form.tsx +100 -0
- package/src/default-fields.tsx +163 -0
- package/src/display-field.tsx +9 -11
- package/src/display-if.tsx +20 -13
- package/src/field-resolver.ts +10 -8
- package/src/field.tsx +18 -445
- package/src/fields-context.tsx +23 -0
- package/src/fields.tsx +34 -21
- package/src/form-context.tsx +84 -0
- package/src/form.tsx +77 -55
- package/src/index.ts +58 -4
- package/src/input-right-button/input-right-button.stories.tsx +1 -1
- package/src/input-right-button/input-right-button.tsx +0 -2
- package/src/layout.tsx +16 -11
- package/src/number-input/number-input.tsx +9 -5
- package/src/object-field.tsx +35 -13
- package/src/password-input/password-input.stories.tsx +23 -2
- package/src/password-input/password-input.tsx +6 -6
- package/src/pin-input/pin-input.tsx +1 -5
- package/src/radio/radio-input.stories.tsx +1 -1
- package/src/radio/radio-input.tsx +12 -10
- package/src/select/native-select.tsx +1 -4
- package/src/select/select-context.tsx +130 -0
- package/src/select/select.stories.tsx +116 -85
- package/src/select/select.test.tsx +1 -1
- package/src/select/select.tsx +162 -146
- package/src/step-form.tsx +76 -76
- package/src/submit-button.tsx +5 -1
- package/src/types.ts +149 -0
- package/src/use-array-field.tsx +9 -3
- package/src/use-step-form.tsx +54 -9
- package/src/utils.ts +23 -1
- package/src/watch-field.tsx +2 -6
- /package/src/radio/{radio.test.tsx → radio-input.test.tsx} +0 -0
package/dist/yup/index.d.ts
CHANGED
@@ -1,10 +1,393 @@
|
|
1
|
-
import * as
|
2
|
-
import
|
1
|
+
import * as React$1 from 'react';
|
2
|
+
import React$1__default from 'react';
|
3
|
+
import * as react_hook_form from 'react-hook-form';
|
4
|
+
import { FieldValues, FieldPath, UseFormProps, SubmitHandler, RegisterOptions, UseFormReturn, UseFieldArrayReturn, WatchObserver, SubmitErrorHandler } from 'react-hook-form';
|
5
|
+
import { MaybeRenderProp } from '@chakra-ui/react-utils';
|
6
|
+
import { UseStepperProps, UseStepperReturn } from '@saas-ui/core';
|
7
|
+
import { HTMLChakraProps, TextareaProps, SwitchProps, CheckboxProps, FormControlProps, ResponsiveValue, InputProps, RadioGroupProps, MenuProps, SelectProps as SelectProps$1, UsePinInputProps, SystemProps, NumberInputProps as NumberInputProps$1, StackDirection, MenuItemOptionProps, ButtonProps, RadioProps } from '@chakra-ui/react';
|
8
|
+
import { FocusableElement } from '@chakra-ui/utils';
|
9
|
+
import * as _chakra_ui_system_dist_system_types from '@chakra-ui/system/dist/system.types';
|
3
10
|
import * as yup from 'yup';
|
4
|
-
import {
|
11
|
+
import { ObjectSchema, InferType } from 'yup';
|
12
|
+
import { FieldProps as FieldProps$1, GetFieldResolver, WithFields, FormProps as FormProps$1, CreateFormProps } from '@saas-ui/forms';
|
5
13
|
import { yupResolver } from '@hookform/resolvers/yup';
|
6
14
|
export { yupResolver } from '@hookform/resolvers/yup';
|
7
|
-
|
15
|
+
|
16
|
+
interface NumberInputOptions {
|
17
|
+
/**
|
18
|
+
* Hide the stepper.
|
19
|
+
*/
|
20
|
+
hideStepper?: boolean;
|
21
|
+
/**
|
22
|
+
* Render a custom increment icon.
|
23
|
+
*/
|
24
|
+
incrementIcon?: React$1.ReactNode;
|
25
|
+
/**
|
26
|
+
* Render a custom decrement icon.
|
27
|
+
*/
|
28
|
+
decrementIcon?: React$1.ReactNode;
|
29
|
+
}
|
30
|
+
interface NumberInputProps extends NumberInputProps$1, NumberInputOptions {
|
31
|
+
}
|
32
|
+
|
33
|
+
interface PasswordOptions {
|
34
|
+
viewIcon?: React$1__default.ReactNode;
|
35
|
+
viewOffIcon?: React$1__default.ReactNode;
|
36
|
+
leftAddon?: React$1__default.ReactNode;
|
37
|
+
}
|
38
|
+
interface PasswordInputProps extends InputProps, PasswordOptions {
|
39
|
+
}
|
40
|
+
|
41
|
+
interface RadioOption extends Omit<RadioProps, 'value' | 'label'>, FieldOption {
|
42
|
+
}
|
43
|
+
type RadioOptions = FieldOptions<RadioOption>;
|
44
|
+
interface RadioInputOptions {
|
45
|
+
options: RadioOptions;
|
46
|
+
spacing?: SystemProps['margin'];
|
47
|
+
direction?: StackDirection;
|
48
|
+
}
|
49
|
+
interface RadioInputProps extends Omit<RadioGroupProps, 'children'>, RadioInputOptions {
|
50
|
+
}
|
51
|
+
|
52
|
+
interface SelectOptions {
|
53
|
+
/**
|
54
|
+
* The name of the input field in a native form.
|
55
|
+
*/
|
56
|
+
name: string;
|
57
|
+
/**
|
58
|
+
* The value of the select field.
|
59
|
+
*/
|
60
|
+
value?: string | string[];
|
61
|
+
/**
|
62
|
+
* The initial value of the select field.
|
63
|
+
*/
|
64
|
+
defaultValue?: string | string[];
|
65
|
+
/**
|
66
|
+
* The callback invoked when the value of the select field changes.
|
67
|
+
* @param value The value of the select field.
|
68
|
+
*/
|
69
|
+
onChange?: (value: string | string[]) => void;
|
70
|
+
/**
|
71
|
+
* The placeholder text when there's no value.
|
72
|
+
*/
|
73
|
+
placeholder?: string;
|
74
|
+
/**
|
75
|
+
* If `true`, the select will be disabled.
|
76
|
+
*/
|
77
|
+
isDisabled?: boolean;
|
78
|
+
/**
|
79
|
+
* An array of options
|
80
|
+
* If you leave this empty the children prop will be rendered.
|
81
|
+
*/
|
82
|
+
options?: FieldOptions<SelectOption>;
|
83
|
+
/**
|
84
|
+
* Enable multiple select.
|
85
|
+
*/
|
86
|
+
multiple?: boolean;
|
87
|
+
/**
|
88
|
+
* The function used to render the value of the select field.
|
89
|
+
* @param value The value of the select field.
|
90
|
+
* @returns The rendered value.
|
91
|
+
*/
|
92
|
+
renderValue?: (value: string | string[]) => React$1__default.ReactNode;
|
93
|
+
}
|
94
|
+
|
95
|
+
interface SelectProps extends Omit<MenuProps, 'children'>, SelectOptions {
|
96
|
+
}
|
97
|
+
interface SelectOption extends Omit<MenuItemOptionProps, 'value'>, FieldOption {
|
98
|
+
}
|
99
|
+
/**
|
100
|
+
* An option in a select list
|
101
|
+
*
|
102
|
+
* @see https://saas-ui.dev/docs/components/forms/select
|
103
|
+
*/
|
104
|
+
declare const SelectOption: _chakra_ui_system_dist_system_types.ComponentWithAs<"button", MenuItemOptionProps>;
|
105
|
+
|
106
|
+
interface Option$1 {
|
107
|
+
value: string;
|
108
|
+
label?: string;
|
109
|
+
}
|
110
|
+
interface NativeSelectOptions {
|
111
|
+
options?: Option$1[];
|
112
|
+
}
|
113
|
+
interface NativeSelectProps extends SelectProps$1, NativeSelectOptions {
|
114
|
+
}
|
115
|
+
|
116
|
+
interface InputFieldProps extends InputProps {
|
117
|
+
type?: string;
|
118
|
+
leftAddon?: React$1.ReactNode;
|
119
|
+
rightAddon?: React$1.ReactNode;
|
120
|
+
}
|
121
|
+
interface NumberInputFieldProps extends NumberInputProps {
|
122
|
+
type: 'number';
|
123
|
+
}
|
124
|
+
interface PinFieldProps extends Omit<UsePinInputProps, 'type'> {
|
125
|
+
pinLength?: number;
|
126
|
+
pinType?: 'alphanumeric' | 'number';
|
127
|
+
spacing?: SystemProps['margin'];
|
128
|
+
}
|
129
|
+
declare const defaultFieldTypes: {
|
130
|
+
text: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
131
|
+
email: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
132
|
+
url: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
133
|
+
phone: React$1.FC<InputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
134
|
+
number: React$1.FC<NumberInputFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
135
|
+
password: React$1.FC<PasswordInputProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
136
|
+
textarea: React$1.FC<TextareaProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
137
|
+
switch: React$1.FC<SwitchProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
138
|
+
select: React$1.FC<SelectProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
139
|
+
checkbox: React$1.FC<CheckboxProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
140
|
+
radio: React$1.FC<RadioInputProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
141
|
+
pin: React$1.FC<PinFieldProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
142
|
+
'native-select': React$1.FC<NativeSelectProps & BaseFieldProps<react_hook_form.FieldValues, string>>;
|
143
|
+
};
|
144
|
+
type DefaultFields = typeof defaultFieldTypes;
|
145
|
+
|
146
|
+
interface SubmitButtonProps extends ButtonProps {
|
147
|
+
/**
|
148
|
+
* Disable the submit button if the form is untouched.
|
149
|
+
*
|
150
|
+
* Change the default behavior by updating
|
151
|
+
* `SubmitButton.defaultProps.disableIfUntouched`
|
152
|
+
*/
|
153
|
+
disableIfUntouched?: boolean;
|
154
|
+
/**
|
155
|
+
* Disable the submit button if the form is invalid.
|
156
|
+
*
|
157
|
+
* Change the default behavior by updating
|
158
|
+
* `SubmitButton.defaultProps.disableIfInvalid`
|
159
|
+
*/
|
160
|
+
disableIfInvalid?: boolean;
|
161
|
+
}
|
162
|
+
|
163
|
+
type FieldOption = {
|
164
|
+
label?: string;
|
165
|
+
value: string;
|
166
|
+
};
|
167
|
+
type FieldOptions<TOption extends FieldOption = FieldOption> = Array<string> | Array<TOption>;
|
168
|
+
type ValueOf<T> = T[keyof T];
|
169
|
+
type ShallowMerge<A, B> = Omit<A, keyof B> & B;
|
170
|
+
type Split<S extends string, D extends string> = string extends S ? string[] : S extends '' ? [] : S extends `${infer T}${D}${infer U}` ? [T, ...Split<U, D>] : [S];
|
171
|
+
type MapPath<T extends string[]> = T extends [infer U, ...infer R] ? U extends string ? `${U extends `${number}` ? '$' : U}${R[0] extends string ? '.' : ''}${R extends string[] ? MapPath<R> : ''}` : '' : '';
|
172
|
+
type TransformPath<T extends string> = MapPath<Split<T, '.'>>;
|
173
|
+
type ArrayFieldPath<Name extends string> = Name extends string ? TransformPath<Name> : never;
|
174
|
+
interface BaseFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends Omit<FormControlProps, 'label' | 'type'> {
|
175
|
+
/**
|
176
|
+
* The field name
|
177
|
+
*/
|
178
|
+
name: TName | ArrayFieldPath<TName>;
|
179
|
+
/**
|
180
|
+
* The field label
|
181
|
+
*/
|
182
|
+
label?: string;
|
183
|
+
/**
|
184
|
+
* Hide the field label
|
185
|
+
*/
|
186
|
+
hideLabel?: boolean;
|
187
|
+
/**
|
188
|
+
* Field help text
|
189
|
+
*/
|
190
|
+
help?: string;
|
191
|
+
/**
|
192
|
+
* React hook form rules
|
193
|
+
*/
|
194
|
+
rules?: Omit<RegisterOptions<TFieldValues, TName>, 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'>;
|
195
|
+
/**
|
196
|
+
* Build-in types:
|
197
|
+
* text, number, password, textarea, select, native-select, checkbox, radio, switch, pin
|
198
|
+
*
|
199
|
+
* Will default to a text field if there is no matching type.
|
200
|
+
*/
|
201
|
+
type?: string;
|
202
|
+
/**
|
203
|
+
* The input placeholder
|
204
|
+
*/
|
205
|
+
placeholder?: string;
|
206
|
+
}
|
207
|
+
type MergeFieldProps<FieldDefs, TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = ValueOf<{
|
208
|
+
[K in keyof FieldDefs]: FieldDefs[K] extends React.FC<infer Props> ? {
|
209
|
+
type?: K;
|
210
|
+
} & ShallowMerge<Props, BaseFieldProps<TFieldValues, TName>> : never;
|
211
|
+
}>;
|
212
|
+
type FieldProps<TFieldValues extends FieldValues = FieldValues> = MergeFieldProps<DefaultFields, TFieldValues>;
|
213
|
+
type DefaultFieldOverrides = {
|
214
|
+
submit?: SubmitButtonProps;
|
215
|
+
[key: string]: any;
|
216
|
+
};
|
217
|
+
|
218
|
+
type FieldResolver = {
|
219
|
+
getFields(): BaseFieldProps[];
|
220
|
+
getNestedFields(name: string): BaseFieldProps[];
|
221
|
+
};
|
222
|
+
|
223
|
+
interface DisplayIfProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> {
|
224
|
+
children: React$1.ReactElement;
|
225
|
+
name: TName;
|
226
|
+
defaultValue?: unknown;
|
227
|
+
isDisabled?: boolean;
|
228
|
+
isExact?: boolean;
|
229
|
+
condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean;
|
230
|
+
}
|
231
|
+
|
232
|
+
interface UseArrayFieldReturn extends UseFieldArrayReturn {
|
233
|
+
/**
|
234
|
+
* The array field name
|
235
|
+
*/
|
236
|
+
name: string;
|
237
|
+
/**
|
238
|
+
* The default value for new items
|
239
|
+
*/
|
240
|
+
defaultValue: Record<string, any>;
|
241
|
+
/**
|
242
|
+
* Min amount of items
|
243
|
+
*/
|
244
|
+
min?: number;
|
245
|
+
/**
|
246
|
+
* Max amount of items
|
247
|
+
*/
|
248
|
+
max?: number;
|
249
|
+
}
|
250
|
+
interface ArrayFieldOptions<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> {
|
251
|
+
/**
|
252
|
+
* The field name
|
253
|
+
*/
|
254
|
+
name: TName;
|
255
|
+
/**
|
256
|
+
* Default value for new values in the array
|
257
|
+
*/
|
258
|
+
defaultValue?: Record<string, any>;
|
259
|
+
/**
|
260
|
+
* Default key name for rows, change this if your data uses a different 'id' field
|
261
|
+
* @default "id"
|
262
|
+
*/
|
263
|
+
keyName?: string;
|
264
|
+
min?: number;
|
265
|
+
max?: number;
|
266
|
+
}
|
267
|
+
interface ArrayFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends ArrayFieldOptions<TFieldValues, TName>, Omit<BaseFieldProps<TFieldValues, TName>, 'name' | 'defaultValue' | 'children'> {
|
268
|
+
children: MaybeRenderProp<ArrayField[]>;
|
269
|
+
}
|
270
|
+
interface ArrayField {
|
271
|
+
id: string;
|
272
|
+
[key: string]: unknown;
|
273
|
+
}
|
274
|
+
/**
|
275
|
+
* The wrapper component that composes the default ArrayField functionality.
|
276
|
+
*
|
277
|
+
* @see Docs https://saas-ui.dev/docs/components/forms/array-field
|
278
|
+
*/
|
279
|
+
declare const ArrayField: ((props: ArrayFieldProps & {
|
280
|
+
ref?: React$1.ForwardedRef<UseArrayFieldReturn>;
|
281
|
+
}) => React$1.ReactElement) & {
|
282
|
+
displayName: string;
|
283
|
+
};
|
284
|
+
|
285
|
+
interface ObjectFieldProps<TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends BaseFieldProps {
|
286
|
+
name: TName;
|
287
|
+
children: React$1.ReactNode;
|
288
|
+
columns?: ResponsiveValue<number>;
|
289
|
+
spacing?: ResponsiveValue<string | number>;
|
290
|
+
}
|
291
|
+
|
292
|
+
interface FormRenderContext<TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends UseFormReturn<TFieldValues, TContext> {
|
293
|
+
Field: React$1.FC<TFieldTypes & React$1.RefAttributes<FocusableElement>>;
|
294
|
+
DisplayIf: React$1.FC<DisplayIfProps<TFieldValues>>;
|
295
|
+
ArrayField: React$1.FC<ArrayFieldProps<TFieldValues> & React$1.RefAttributes<UseArrayFieldReturn>>;
|
296
|
+
ObjectField: React$1.FC<ObjectFieldProps<TFieldValues>>;
|
297
|
+
}
|
298
|
+
interface FormOptions<TSchema = unknown, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> {
|
299
|
+
/**
|
300
|
+
* The form schema.
|
301
|
+
*/
|
302
|
+
schema?: TSchema;
|
303
|
+
/**
|
304
|
+
* Triggers when any of the field change.
|
305
|
+
*/
|
306
|
+
onChange?: WatchObserver<TFieldValues>;
|
307
|
+
/**
|
308
|
+
* The submit handler.
|
309
|
+
*/
|
310
|
+
onSubmit: SubmitHandler<TFieldValues>;
|
311
|
+
/**
|
312
|
+
* Triggers when there are validation errors.
|
313
|
+
*/
|
314
|
+
onError?: SubmitErrorHandler<TFieldValues>;
|
315
|
+
/**
|
316
|
+
* The Hook Form state ref.
|
317
|
+
*/
|
318
|
+
formRef?: React$1.RefObject<UseFormReturn<TFieldValues, TContext>>;
|
319
|
+
/**
|
320
|
+
* The form children, can be a render prop or a ReactNode.
|
321
|
+
*/
|
322
|
+
children?: MaybeRenderProp<FormRenderContext<TFieldValues, TContext, TFieldTypes>>;
|
323
|
+
/**
|
324
|
+
* The field resolver, used to resolve the fields from schemas.
|
325
|
+
*/
|
326
|
+
fieldResolver?: FieldResolver;
|
327
|
+
/**
|
328
|
+
* Field overrides
|
329
|
+
*/
|
330
|
+
fields?: DefaultFieldOverrides;
|
331
|
+
}
|
332
|
+
interface FormProps<TSchema = unknown, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends UseFormProps<TFieldValues, TContext>, Omit<HTMLChakraProps<'form'>, 'children' | 'onChange' | 'onSubmit' | 'onError'>, FormOptions<TSchema, TFieldValues, TContext, TFieldTypes> {
|
333
|
+
}
|
334
|
+
|
335
|
+
type StepsOptions<TSchema, TName extends string = string> = {
|
336
|
+
/**
|
337
|
+
* The step name
|
338
|
+
*/
|
339
|
+
name: TName;
|
340
|
+
/**
|
341
|
+
* Schema
|
342
|
+
*/
|
343
|
+
schema?: TSchema;
|
344
|
+
}[];
|
345
|
+
interface FormStepOptions<TName extends string = string> {
|
346
|
+
/**
|
347
|
+
* The step name
|
348
|
+
*/
|
349
|
+
name: TName;
|
350
|
+
/**
|
351
|
+
* Schema
|
352
|
+
*/
|
353
|
+
schema?: any;
|
354
|
+
/**
|
355
|
+
* Hook Form Resolver
|
356
|
+
*/
|
357
|
+
resolver?: any;
|
358
|
+
}
|
359
|
+
interface FormStepProps<TName extends string = string> extends FormStepOptions<TName>, Omit<HTMLChakraProps<'div'>, 'onSubmit'> {
|
360
|
+
onSubmit?: FormStepSubmitHandler;
|
361
|
+
}
|
362
|
+
type FormStepSubmitHandler<TFieldValues extends FieldValues = FieldValues> = (data: TFieldValues, stepper: UseStepperReturn) => Promise<void>;
|
363
|
+
|
364
|
+
type StepName<T extends {
|
365
|
+
[k: number]: {
|
366
|
+
readonly name: string;
|
367
|
+
};
|
368
|
+
}> = T[number]['name'];
|
369
|
+
interface StepFormRenderContext<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends UseStepFormReturn<TFieldValues> {
|
370
|
+
Field: React$1.FC<TFieldTypes & React$1.RefAttributes<FocusableElement>>;
|
371
|
+
FormStep: React$1.FC<FormStepProps<StepName<TSteps>>>;
|
372
|
+
DisplayIf: React$1.FC<DisplayIfProps<TFieldValues>>;
|
373
|
+
ArrayField: React$1.FC<ArrayFieldProps<TFieldValues> & React$1.RefAttributes<UseArrayFieldReturn>>;
|
374
|
+
ObjectField: React$1.FC<ObjectFieldProps<TFieldValues>>;
|
375
|
+
}
|
376
|
+
interface UseStepFormProps<TSteps extends StepsOptions<any> = StepsOptions<any>, TFieldValues extends FieldValues = FieldValues, TContext extends object = object, TFieldTypes = FieldProps<TFieldValues>> extends Omit<UseStepperProps, 'onChange'>, Omit<FormProps<any, TFieldValues, TContext, TFieldTypes>, 'children'> {
|
377
|
+
steps?: TSteps;
|
378
|
+
children: MaybeRenderProp<StepFormRenderContext<TSteps, TFieldValues, TContext, TFieldTypes>>;
|
379
|
+
}
|
380
|
+
interface UseStepFormReturn<TFieldValues extends FieldValues = FieldValues> extends UseStepperReturn {
|
381
|
+
getFormProps(): {
|
382
|
+
onSubmit: SubmitHandler<TFieldValues>;
|
383
|
+
schema?: any;
|
384
|
+
resolver?: any;
|
385
|
+
};
|
386
|
+
updateStep(step: any): void;
|
387
|
+
steps: Record<string, any>;
|
388
|
+
}
|
389
|
+
|
390
|
+
type AnyObjectSchema = ObjectSchema<any, any, any, ''> | ObjectSchema<any, any, any, 'd'> | ObjectSchema<any, any, any, 's'>;
|
8
391
|
|
9
392
|
type Options = {
|
10
393
|
min?: number;
|
@@ -16,26 +399,147 @@ type Options = {
|
|
16
399
|
* @param schema The Yup schema
|
17
400
|
* @returns {FieldProps[]}
|
18
401
|
*/
|
19
|
-
declare const getFieldsFromSchema: (schema: AnyObjectSchema) => FieldProps[];
|
20
|
-
declare const getNestedSchema: (schema: AnyObjectSchema, path: string) =>
|
21
|
-
declare const yupFieldResolver:
|
22
|
-
getFields(): FieldProps<_saas_ui_forms.FieldValues, string>[];
|
23
|
-
getNestedFields(name: string): FieldProps<_saas_ui_forms.FieldValues, string>[];
|
24
|
-
};
|
25
|
-
declare const yupForm: (schema: AnyObjectSchema, schemaOptions?: {}, resolverOptions?: {}) => {
|
26
|
-
schema: AnyObjectSchema;
|
27
|
-
resolver: <TFieldValues extends _saas_ui_forms.FieldValues, TContext>(values: TFieldValues, context: TContext | undefined, options: _saas_ui_forms.ResolverOptions<TFieldValues>) => Promise<_saas_ui_forms.ResolverResult<TFieldValues>>;
|
28
|
-
fieldResolver: {
|
29
|
-
getFields(): FieldProps<_saas_ui_forms.FieldValues, string>[];
|
30
|
-
getNestedFields(name: string): FieldProps<_saas_ui_forms.FieldValues, string>[];
|
31
|
-
};
|
32
|
-
};
|
402
|
+
declare const getFieldsFromSchema: (schema: AnyObjectSchema) => FieldProps$1[];
|
403
|
+
declare const getNestedSchema: (schema: AnyObjectSchema, path: string) => AnyObjectSchema;
|
404
|
+
declare const yupFieldResolver: GetFieldResolver;
|
33
405
|
|
34
406
|
type ResolverArgs = Parameters<typeof yupResolver>;
|
35
|
-
interface CreateYupFormProps extends CreateFormProps {
|
407
|
+
interface CreateYupFormProps<FieldDefs> extends CreateFormProps<FieldDefs> {
|
36
408
|
schemaOptions?: ResolverArgs[1];
|
37
409
|
resolverOptions?: ResolverArgs[2];
|
38
410
|
}
|
39
|
-
|
411
|
+
type YupFormType<FieldDefs, ExtraProps = object, ExtraOverrides = object, Type extends 'yup' = 'yup'> = (<TSchema extends AnyObjectSchema = AnyObjectSchema, TFieldValues extends InferType<TSchema> = InferType<TSchema>, // placeholder
|
412
|
+
TContext extends object = object>(props: WithFields<FormProps$1<TFieldValues, TContext, TSchema>, FieldDefs, ExtraOverrides> & {
|
413
|
+
ref?: React$1__default.ForwardedRef<HTMLFormElement>;
|
414
|
+
} & ExtraProps) => React$1__default.ReactElement) & {
|
415
|
+
displayName?: string;
|
416
|
+
id?: 'YupForm';
|
417
|
+
};
|
418
|
+
declare const createYupForm: <FieldDefs>(options?: CreateYupFormProps<FieldDefs> | undefined) => YupFormType<FieldDefs, object, object, "yup">;
|
419
|
+
|
420
|
+
declare const Form: YupFormType<unknown, object, object, "yup">;
|
421
|
+
declare const StepForm: (<TSteps extends {
|
422
|
+
name: string;
|
423
|
+
schema?: AnyObjectSchema | undefined;
|
424
|
+
}[] = {
|
425
|
+
name: string;
|
426
|
+
schema?: AnyObjectSchema | undefined;
|
427
|
+
}[], TFieldValues extends TSteps extends [infer Step, ...infer Rest] ? Step extends {
|
428
|
+
schema: AnyObjectSchema;
|
429
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
430
|
+
name: string;
|
431
|
+
schema?: AnyObjectSchema | undefined;
|
432
|
+
}[] ? Rest extends infer T ? T extends Rest ? T extends [infer Step, ...infer Rest] ? Step extends {
|
433
|
+
schema: AnyObjectSchema;
|
434
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
435
|
+
name: string;
|
436
|
+
schema?: AnyObjectSchema | undefined;
|
437
|
+
}[] ? Rest extends infer T_1 ? T_1 extends Rest ? T_1 extends [infer Step, ...infer Rest] ? Step extends {
|
438
|
+
schema: AnyObjectSchema;
|
439
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
440
|
+
name: string;
|
441
|
+
schema?: AnyObjectSchema | undefined;
|
442
|
+
}[] ? Rest extends infer T_2 ? T_2 extends Rest ? T_2 extends [infer Step, ...infer Rest] ? Step extends {
|
443
|
+
schema: AnyObjectSchema;
|
444
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
445
|
+
name: string;
|
446
|
+
schema?: AnyObjectSchema | undefined;
|
447
|
+
}[] ? Rest extends infer T_3 ? T_3 extends Rest ? T_3 extends [infer Step, ...infer Rest] ? Step extends {
|
448
|
+
schema: AnyObjectSchema;
|
449
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
450
|
+
name: string;
|
451
|
+
schema?: AnyObjectSchema | undefined;
|
452
|
+
}[] ? Rest extends infer T_4 ? T_4 extends Rest ? T_4 extends [infer Step, ...infer Rest] ? Step extends {
|
453
|
+
schema: AnyObjectSchema;
|
454
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
455
|
+
name: string;
|
456
|
+
schema?: AnyObjectSchema | undefined;
|
457
|
+
}[] ? Rest extends infer T_5 ? T_5 extends Rest ? T_5 extends [infer Step, ...infer Rest] ? Step extends {
|
458
|
+
schema: AnyObjectSchema;
|
459
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
460
|
+
name: string;
|
461
|
+
schema?: AnyObjectSchema | undefined;
|
462
|
+
}[] ? Rest extends infer T_6 ? T_6 extends Rest ? T_6 extends [infer Step, ...infer Rest] ? Step extends {
|
463
|
+
schema: AnyObjectSchema;
|
464
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
465
|
+
name: string;
|
466
|
+
schema?: AnyObjectSchema | undefined;
|
467
|
+
}[] ? Rest extends infer T_7 ? T_7 extends Rest ? T_7 extends [infer Step, ...infer Rest] ? Step extends {
|
468
|
+
schema: AnyObjectSchema;
|
469
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
470
|
+
name: string;
|
471
|
+
schema?: AnyObjectSchema | undefined;
|
472
|
+
}[] ? Rest extends infer T_8 ? T_8 extends Rest ? T_8 extends [infer Step, ...infer Rest] ? Step extends {
|
473
|
+
schema: AnyObjectSchema;
|
474
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
475
|
+
name: string;
|
476
|
+
schema?: AnyObjectSchema | undefined;
|
477
|
+
}[] ? Rest extends infer T_9 ? T_9 extends Rest ? T_9 extends [infer Step, ...infer Rest] ? Step extends {
|
478
|
+
schema: AnyObjectSchema;
|
479
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
480
|
+
name: string;
|
481
|
+
schema?: AnyObjectSchema | undefined;
|
482
|
+
}[] ? any : object) : object : object : never : never : object) : object : object : never : never : object) : object : object : never : never : object) : object : object : never : never : object) : object : object : never : never : object) : object : object : never : never : object) : object : object : never : never : object) : object : object : never : never : object) : object : object : never : never : object) : object : object : never : never : object) : object : object = TSteps extends [infer Step, ...infer Rest] ? Step extends {
|
483
|
+
schema: AnyObjectSchema;
|
484
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
485
|
+
name: string;
|
486
|
+
schema?: AnyObjectSchema | undefined;
|
487
|
+
}[] ? Rest extends infer T_10 ? T_10 extends Rest ? T_10 extends [infer Step, ...infer Rest] ? Step extends {
|
488
|
+
schema: AnyObjectSchema;
|
489
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
490
|
+
name: string;
|
491
|
+
schema?: AnyObjectSchema | undefined;
|
492
|
+
}[] ? Rest extends infer T_11 ? T_11 extends Rest ? T_11 extends [infer Step, ...infer Rest] ? Step extends {
|
493
|
+
schema: AnyObjectSchema;
|
494
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
495
|
+
name: string;
|
496
|
+
schema?: AnyObjectSchema | undefined;
|
497
|
+
}[] ? Rest extends infer T_12 ? T_12 extends Rest ? T_12 extends [infer Step, ...infer Rest] ? Step extends {
|
498
|
+
schema: AnyObjectSchema;
|
499
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
500
|
+
name: string;
|
501
|
+
schema?: AnyObjectSchema | undefined;
|
502
|
+
}[] ? Rest extends infer T_13 ? T_13 extends Rest ? T_13 extends [infer Step, ...infer Rest] ? Step extends {
|
503
|
+
schema: AnyObjectSchema;
|
504
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
505
|
+
name: string;
|
506
|
+
schema?: AnyObjectSchema | undefined;
|
507
|
+
}[] ? Rest extends infer T_14 ? T_14 extends Rest ? T_14 extends [infer Step, ...infer Rest] ? Step extends {
|
508
|
+
schema: AnyObjectSchema;
|
509
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
510
|
+
name: string;
|
511
|
+
schema?: AnyObjectSchema | undefined;
|
512
|
+
}[] ? Rest extends infer T_15 ? T_15 extends Rest ? T_15 extends [infer Step, ...infer Rest] ? Step extends {
|
513
|
+
schema: AnyObjectSchema;
|
514
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
515
|
+
name: string;
|
516
|
+
schema?: AnyObjectSchema | undefined;
|
517
|
+
}[] ? Rest extends infer T_16 ? T_16 extends Rest ? T_16 extends [infer Step, ...infer Rest] ? Step extends {
|
518
|
+
schema: AnyObjectSchema;
|
519
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
520
|
+
name: string;
|
521
|
+
schema?: AnyObjectSchema | undefined;
|
522
|
+
}[] ? Rest extends infer T_17 ? T_17 extends Rest ? T_17 extends [infer Step, ...infer Rest] ? Step extends {
|
523
|
+
schema: AnyObjectSchema;
|
524
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
525
|
+
name: string;
|
526
|
+
schema?: AnyObjectSchema | undefined;
|
527
|
+
}[] ? Rest extends infer T_18 ? T_18 extends Rest ? T_18 extends [infer Step, ...infer Rest] ? Step extends {
|
528
|
+
schema: AnyObjectSchema;
|
529
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
530
|
+
name: string;
|
531
|
+
schema?: AnyObjectSchema | undefined;
|
532
|
+
}[] ? Rest extends infer T_19 ? T_19 extends Rest ? T_19 extends [infer Step, ...infer Rest] ? Step extends {
|
533
|
+
schema: AnyObjectSchema;
|
534
|
+
} ? yup.Asserts<Step["schema"]> & (Rest extends {
|
535
|
+
name: string;
|
536
|
+
schema?: AnyObjectSchema | undefined;
|
537
|
+
}[] ? any : object) : object : object : never : never : object) : object : object : never : never : object) : object : object : never : never : object) : object : object : never : never : object) : object : object : never : never : object) : object : object : never : never : object) : object : object : never : never : object) : object : object : never : never : object) : object : object : never : never : object) : object : object : never : never : object) : object : object, TContext extends object = object>(props: UseStepFormProps<TSteps, TFieldValues, TContext, FieldProps<TFieldValues>> & {
|
538
|
+
steps: TSteps;
|
539
|
+
ref?: React$1.ForwardedRef<HTMLFormElement> | undefined;
|
540
|
+
}) => React$1.ReactElement<any, string | React$1.JSXElementConstructor<any>>) & {
|
541
|
+
displayName?: string | undefined;
|
542
|
+
id?: string | undefined;
|
543
|
+
};
|
40
544
|
|
41
|
-
export { Options, createYupForm, getFieldsFromSchema, getNestedSchema, yupFieldResolver
|
545
|
+
export { AnyObjectSchema, Form, Options, StepForm, YupFormType, createYupForm, getFieldsFromSchema, getNestedSchema, yupFieldResolver };
|
package/dist/yup/index.js
CHANGED
@@ -68,28 +68,40 @@ var yupFieldResolver = (schema) => {
|
|
68
68
|
}
|
69
69
|
};
|
70
70
|
};
|
71
|
-
var yupForm = (schema, schemaOptions = {}, resolverOptions = {}) => {
|
72
|
-
return {
|
73
|
-
schema,
|
74
|
-
resolver: yup.yupResolver(schema, schemaOptions, resolverOptions),
|
75
|
-
fieldResolver: yupFieldResolver(schema)
|
76
|
-
};
|
77
|
-
};
|
78
71
|
var createYupForm = (options) => {
|
79
|
-
|
72
|
+
const YupForm = forms.createForm({
|
73
|
+
resolver: (schema) => yup.yupResolver(schema, options == null ? void 0 : options.schemaOptions, options == null ? void 0 : options.resolverOptions),
|
74
|
+
fieldResolver: yupFieldResolver,
|
75
|
+
...options
|
76
|
+
});
|
77
|
+
YupForm.displayName = "YupForm";
|
78
|
+
YupForm.id = "YupForm";
|
79
|
+
return YupForm;
|
80
|
+
};
|
81
|
+
var createYupStepForm = (options) => {
|
82
|
+
const YupStepForm = forms.createStepForm({
|
80
83
|
resolver: (schema) => yup.yupResolver(schema, options == null ? void 0 : options.schemaOptions, options == null ? void 0 : options.resolverOptions),
|
84
|
+
fieldResolver: yupFieldResolver,
|
81
85
|
...options
|
82
86
|
});
|
87
|
+
YupStepForm.displayName = "YupStepForm";
|
88
|
+
YupStepForm.id = "YupStepForm";
|
89
|
+
return YupStepForm;
|
83
90
|
};
|
84
91
|
|
92
|
+
// yup/src/index.ts
|
93
|
+
var Form2 = createYupForm();
|
94
|
+
var StepForm = createYupStepForm();
|
95
|
+
|
85
96
|
Object.defineProperty(exports, 'yupResolver', {
|
86
97
|
enumerable: true,
|
87
98
|
get: function () { return yup.yupResolver; }
|
88
99
|
});
|
100
|
+
exports.Form = Form2;
|
101
|
+
exports.StepForm = StepForm;
|
89
102
|
exports.createYupForm = createYupForm;
|
90
103
|
exports.getFieldsFromSchema = getFieldsFromSchema;
|
91
104
|
exports.getNestedSchema = getNestedSchema;
|
92
105
|
exports.yupFieldResolver = yupFieldResolver;
|
93
|
-
exports.yupForm = yupForm;
|
94
106
|
//# sourceMappingURL=out.js.map
|
95
107
|
//# sourceMappingURL=index.js.map
|
package/dist/yup/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../yup/src/yup-resolver.ts","../../yup/src/create-yup-form.
|
1
|
+
{"version":3,"sources":["../../yup/src/yup-resolver.ts","../../yup/src/create-yup-form.ts","../../yup/src/create-yup-step-form.ts","../../yup/src/index.ts"],"names":["Form"],"mappings":";AAAA,SAAS,aAAa;AACtB,SAAS,mBAAmB;AAa5B,IAAM,UAAU,CAAC,UAAe;AAdhC;AAeE,OAAI,WAAM,KAAK,SAAX,mBAAiB,MAAM;AACzB,WAAO,MAAM,KAAK,KAAK;AAAA,EACzB;AAEA,UAAQ,MAAM,MAAM;AAAA,IAClB,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AAAA,IACL;AACE,aAAO;AAAA,EACX;AACF;AAEA,IAAM,iBAAiB,CAAC,OAAY,SAAiB;AAlCrD;AAmCE,aAAW,QAAQ,MAAM,OAAO;AAC9B,SAAI,UAAK,YAAL,mBAAc,OAAO;AAAO,aAAO,KAAK,QAAQ,OAAO,IAAI;AAAA,EACjE;AACF;AAQO,IAAM,sBAAsB,CAAC,WAA0C;AAC5E,QAAM,SAAS,CAAC;AAEhB,MAAI,eAAoC,CAAC;AACzC,MAAI,OAAO,SAAS,SAAS;AAE3B,mBAAe,OAAO,UAAU;AAAA,EAClC,OAAO;AACL,mBAAe,OAAO;AAAA,EACxB;AAEA,aAAW,QAAQ,cAAc;AAC/B,UAAM,QAAQ,aAAa,IAAI;AAE/B,UAAM,UAAmB,CAAC;AAC1B,QAAI,MAAM,SAAS,SAAS;AAC1B,cAAQ,MAAM,eAAe,OAAO,KAAK;AACzC,cAAQ,MAAM,eAAe,OAAO,KAAK;AAAA,IAC3C;AAEA,WAAO,KAAK;AAAA,MACV;AAAA,MACA,OAAO,MAAM,KAAK,SAAS;AAAA,MAC3B,MAAM,QAAQ,KAAK;AAAA,MACnB,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AACA,SAAO;AACT;AAEO,IAAM,kBAAkB,CAAC,QAAyB,SAAiB;AACxE,SAAO,MAAM,QAAQ,IAAI;AAC3B;AAEO,IAAM,mBAAqC,CAAC,WAA4B;AAC7E,SAAO;AAAA,IACL,YAAY;AACV,aAAO,oBAAoB,MAAM;AAAA,IACnC;AAAA,IACA,gBAAgB,MAAc;AAC5B,aAAO,oBAAoB,gBAAgB,QAAQ,IAAI,CAAC;AAAA,IAC1D;AAAA,EACF;AACF;;;ACzFA;AAAA,EACE;AAAA,OAKK;AAoCA,IAAM,gBAAgB,CAC3B,YACG;AACH,QAAM,UAAU,WAAW;AAAA,IACzB,UAAU,CAAC,WACT,YAAY,QAAQ,mCAAS,eAAe,mCAAS,eAAe;AAAA,IACtE,eAAe;AAAA,IACf,GAAG;AAAA,EACL,CAAC;AAED,UAAQ,cAAc;AACtB,UAAQ,KAAK;AAEb,SAAO;AACT;;;ACxDA;AAAA,EAME;AAAA,OAIK;AA4CA,IAAM,oBAAoB,CAC/B,YACG;AACH,QAAM,cAAc,eAA8B;AAAA,IAChD,UAAU,CAAC,WACT,YAAY,QAAQ,mCAAS,eAAe,mCAAS,eAAe;AAAA,IACtE,eAAe;AAAA,IACf,GAAG;AAAA,EACL,CAAC;AAED,cAAY,cAAc;AAC1B,cAAY,KAAK;AAEjB,SAAO;AACT;;;AC9DO,IAAMA,QAAO,cAAc;AAE3B,IAAM,WAAW,kBAAkB","sourcesContent":["import { reach } from 'yup'\nimport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps, GetFieldResolver } from '@saas-ui/forms'\nimport { AnyObjectSchema } from './types'\n\nexport { yupResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\n// @TODO get proper typings for the schema fields\nconst getType = (field: any) => {\n if (field.spec.meta?.type) {\n return field.spec.meta.type\n }\n\n switch (field.type) {\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n case 'number':\n return 'number'\n case 'date':\n return 'date'\n case 'string':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n for (const test of field.tests) {\n if (test.OPTIONS?.params[name]) return test.OPTIONS.params[name]\n }\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: AnyObjectSchema): FieldProps[] => {\n const fields = []\n\n let schemaFields: Record<string, any> = {}\n if (schema.type === 'array') {\n /* @ts-ignore this is actually valid */\n schemaFields = schema.innerType.fields\n } else {\n schemaFields = schema.fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field.type === 'array') {\n options.min = getArrayOption(field, 'min')\n options.max = getArrayOption(field, 'max')\n }\n\n fields.push({\n name,\n label: field.spec.label || name,\n type: getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: AnyObjectSchema, path: string) => {\n return reach(schema, path) as AnyObjectSchema\n}\n\nexport const yupFieldResolver: GetFieldResolver = (schema: AnyObjectSchema) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n","import {\n createForm,\n CreateFormProps,\n FormProps,\n WithFields,\n FieldValues,\n} from '@saas-ui/forms'\nimport { yupFieldResolver, yupResolver } from './yup-resolver'\nimport { InferType } from 'yup'\nimport React from 'react'\nimport { AnyObjectSchema } from './types'\n\ntype ResolverArgs = Parameters<typeof yupResolver>\n\nexport interface CreateYupFormProps<FieldDefs>\n extends CreateFormProps<FieldDefs> {\n schemaOptions?: ResolverArgs[1]\n resolverOptions?: ResolverArgs[2]\n}\n\nexport type YupFormType<\n FieldDefs,\n ExtraProps = object,\n ExtraOverrides = object,\n Type extends 'yup' = 'yup'\n> = (<\n TSchema extends AnyObjectSchema = AnyObjectSchema,\n TFieldValues extends InferType<TSchema> = InferType<TSchema>, // placeholder\n TContext extends object = object\n>(\n props: WithFields<\n FormProps<TFieldValues, TContext, TSchema>,\n FieldDefs,\n ExtraOverrides\n > & {\n ref?: React.ForwardedRef<HTMLFormElement>\n } & ExtraProps\n) => React.ReactElement) & {\n displayName?: string\n id?: 'YupForm'\n}\n\nexport const createYupForm = <FieldDefs>(\n options?: CreateYupFormProps<FieldDefs>\n) => {\n const YupForm = createForm({\n resolver: (schema: any) =>\n yupResolver(schema, options?.schemaOptions, options?.resolverOptions),\n fieldResolver: yupFieldResolver,\n ...options,\n })\n\n YupForm.displayName = 'YupForm'\n YupForm.id = 'YupForm'\n\n return YupForm as YupFormType<FieldDefs>\n}\n","import {\n createForm,\n CreateFormProps,\n FormProps,\n WithFields,\n FieldValues,\n createStepForm,\n StepsOptions,\n UseStepFormProps,\n Form,\n} from '@saas-ui/forms'\nimport { yupFieldResolver, yupResolver } from './yup-resolver'\nimport { InferType, object, string } from 'yup'\nimport React from 'react'\nimport { AnyObjectSchema } from './types'\n\ntype ResolverArgs = Parameters<typeof yupResolver>\n\nexport interface CreateYupFormProps<FieldDefs>\n extends CreateFormProps<FieldDefs> {\n schemaOptions?: ResolverArgs[1]\n resolverOptions?: ResolverArgs[2]\n}\n\ntype InferStepType<T extends Required<StepsOptions<AnyObjectSchema>>> =\n T extends [infer Step, ...infer Rest]\n ? Step extends { schema: AnyObjectSchema }\n ? InferType<Step['schema']> &\n (Rest extends Required<StepsOptions<AnyObjectSchema>>\n ? InferStepType<Rest>\n : object)\n : object\n : object\n\ntype YupStepFormType<\n FieldDefs,\n ExtraProps = object,\n ExtraOverrides = object\n> = (<\n TSteps extends Required<StepsOptions<AnyObjectSchema>> = Required<\n StepsOptions<AnyObjectSchema>\n >,\n TFieldValues extends InferStepType<TSteps> = InferStepType<TSteps>,\n TContext extends object = object\n>(\n props: UseStepFormProps<TSteps, TFieldValues, TContext> & {\n steps: TSteps\n ref?: React.ForwardedRef<HTMLFormElement>\n }\n) => React.ReactElement) & {\n displayName?: string\n id?: string\n}\n\nexport const createYupStepForm = <FieldDefs>(\n options?: CreateYupFormProps<FieldDefs>\n) => {\n const YupStepForm = createStepForm<any, any, any>({\n resolver: (schema: any) =>\n yupResolver(schema, options?.schemaOptions, options?.resolverOptions),\n fieldResolver: yupFieldResolver,\n ...options,\n })\n\n YupStepForm.displayName = 'YupStepForm'\n YupStepForm.id = 'YupStepForm'\n\n return YupStepForm as YupStepFormType<FieldDefs>\n}\n","export * from './yup-resolver'\nexport { createYupForm, type YupFormType } from './create-yup-form'\nexport type { AnyObjectSchema } from './types'\nimport { createYupForm } from './create-yup-form'\nimport { createYupStepForm } from './create-yup-step-form'\n\nexport const Form = createYupForm()\n\nexport const StepForm = createYupStepForm()\n"]}
|