@saas-ui/forms 1.1.2 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
package/src/index.ts CHANGED
@@ -12,6 +12,115 @@ export * from './display-if'
12
12
  export * from './step-form'
13
13
  export * from './use-step-form'
14
14
  export * from './field-resolver'
15
+ export * from './watch-field'
15
16
  export * from '@saas-ui/input-right-button'
16
17
 
17
- export type { FieldErrors } from 'react-hook-form'
18
+ export type {
19
+ BatchFieldArrayUpdate,
20
+ ChangeHandler,
21
+ Control,
22
+ ControllerFieldState,
23
+ ControllerProps,
24
+ ControllerRenderProps,
25
+ CriteriaMode,
26
+ CustomElement,
27
+ DeepMap,
28
+ DeepPartial,
29
+ DeepPartialSkipArrayKey,
30
+ DefaultValues,
31
+ DelayCallback,
32
+ EmptyObject,
33
+ ErrorOption,
34
+ EventType,
35
+ Field as FieldDef,
36
+ FieldArray,
37
+ FieldArrayMethodProps,
38
+ FieldArrayWithId,
39
+ FieldElement,
40
+ FieldError,
41
+ FieldErrors,
42
+ FieldName,
43
+ FieldNamesMarkedBoolean,
44
+ FieldRefs,
45
+ FieldValue,
46
+ FieldValues,
47
+ FormProviderProps,
48
+ FormState,
49
+ FormStateProxy,
50
+ FormStateSubjectRef,
51
+ GetIsDirty,
52
+ InternalFieldErrors,
53
+ InternalFieldName,
54
+ InternalNameSet,
55
+ IsAny,
56
+ IsFlatObject,
57
+ KeepStateOptions,
58
+ LiteralUnion,
59
+ Message,
60
+ Mode,
61
+ MultipleFieldErrors,
62
+ Names,
63
+ NativeFieldValue,
64
+ NestedValue,
65
+ NonUndefined,
66
+ Noop,
67
+ Primitive,
68
+ ReadFormState,
69
+ Ref,
70
+ RefCallBack,
71
+ RegisterOptions,
72
+ Resolver,
73
+ ResolverError,
74
+ ResolverOptions,
75
+ ResolverResult,
76
+ ResolverSuccess,
77
+ SetFieldValue,
78
+ SetValueConfig,
79
+ Subjects,
80
+ SubmitErrorHandler,
81
+ SubmitHandler,
82
+ TriggerConfig,
83
+ UnpackNestedValue,
84
+ UseControllerProps,
85
+ UseControllerReturn,
86
+ UseFieldArrayProps,
87
+ UseFieldArrayReturn,
88
+ UseFormClearErrors,
89
+ UseFormGetValues,
90
+ UseFormHandleSubmit,
91
+ UseFormProps,
92
+ UseFormRegister,
93
+ UseFormRegisterReturn,
94
+ UseFormReset,
95
+ UseFormResetField,
96
+ UseFormReturn,
97
+ UseFormSetError,
98
+ UseFormSetFocus,
99
+ UseFormSetValue,
100
+ UseFormStateProps,
101
+ UseFormStateReturn,
102
+ UseFormTrigger,
103
+ UseFormUnregister,
104
+ UseFormWatch,
105
+ UseWatchProps,
106
+ Validate,
107
+ ValidateResult,
108
+ ValidationMode,
109
+ ValidationRule,
110
+ ValidationValue,
111
+ ValidationValueMessage,
112
+ WatchInternal,
113
+ WatchObserver,
114
+ } from 'react-hook-form'
115
+
116
+ export {
117
+ appendErrors,
118
+ useController,
119
+ useFieldArray,
120
+ useForm,
121
+ useFormContext,
122
+ useFormState,
123
+ useWatch,
124
+ Controller,
125
+ FormProvider,
126
+ } from 'react-hook-form'
@@ -0,0 +1,39 @@
1
+ import {
2
+ FieldValues,
3
+ useFormContext,
4
+ UseFormReturn,
5
+ useWatch,
6
+ } from 'react-hook-form'
7
+
8
+ export interface WatchFieldProps<
9
+ Value = unknown,
10
+ TFieldValues extends FieldValues = FieldValues
11
+ > {
12
+ name: string
13
+ defaultValue?: Value
14
+ isDisabled?: boolean
15
+ isExact?: boolean
16
+ children: (
17
+ value: Value,
18
+ form: UseFormReturn<TFieldValues>
19
+ ) => React.ReactElement | void
20
+ }
21
+
22
+ export const WatchField = <
23
+ Value = unknown,
24
+ TFieldValues extends FieldValues = FieldValues
25
+ >(
26
+ props: WatchFieldProps<Value, TFieldValues>
27
+ ) => {
28
+ const { name, defaultValue, isDisabled, isExact } = props
29
+ const form = useFormContext<TFieldValues>()
30
+
31
+ const field = useWatch({
32
+ name,
33
+ defaultValue,
34
+ disabled: isDisabled,
35
+ exact: isExact,
36
+ })
37
+
38
+ return props.children(field, form) || null
39
+ }