linear-react-components-ui 1.1.25-rc.11 → 1.1.25-rc.13
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/lib/form2/types.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ChangeEventHandler, FocusEventHandler, Ref, RefCallback, FocusEvent, ChangeEvent } from 'react';
|
|
2
|
+
|
|
1
3
|
type DeepPartial<T> = {
|
|
2
4
|
[K in keyof T]?: T[K] extends Array<infer U> ? Array<DeepPartial<U>> : T[K] extends object ? DeepPartial<T[K]> : T[K];
|
|
3
5
|
};
|
|
@@ -23,6 +25,11 @@ type RegisterFunction = (name: string, externalRef?: React.Ref<HTMLInputElement>
|
|
|
23
25
|
onBlur: () => void;
|
|
24
26
|
onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
|
|
25
27
|
};
|
|
28
|
+
type RegisterOptions = {
|
|
29
|
+
onChange?: ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement> | undefined;
|
|
30
|
+
onBlur?: FocusEventHandler<HTMLInputElement | HTMLTextAreaElement> | undefined;
|
|
31
|
+
ref?: Ref<HTMLInputElement | HTMLTextAreaElement>;
|
|
32
|
+
};
|
|
26
33
|
interface UseFormProps<T> {
|
|
27
34
|
initialValues: T;
|
|
28
35
|
validators?: ValidatorsSchema;
|
|
@@ -62,14 +69,14 @@ interface UseFormReturn<T> {
|
|
|
62
69
|
/**
|
|
63
70
|
* Registra um campo no formulário, integrando com `ref`, `value`, `onChange` e `onBlur`.
|
|
64
71
|
* @param name - Nome do campo.
|
|
65
|
-
* @param
|
|
72
|
+
* @param registerOptions - Opções de registro, incluindo referências e manipuladores de eventos.
|
|
66
73
|
*/
|
|
67
|
-
register: (name: string,
|
|
74
|
+
register: (name: string, registerOptions?: RegisterOptions) => {
|
|
68
75
|
name: string;
|
|
69
|
-
ref:
|
|
76
|
+
ref: RefCallback<HTMLInputElement | HTMLTextAreaElement>;
|
|
70
77
|
value: any;
|
|
71
|
-
onBlur: () => void;
|
|
72
|
-
onChange: (event:
|
|
78
|
+
onBlur: (event: FocusEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
79
|
+
onChange: (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
73
80
|
};
|
|
74
81
|
/**
|
|
75
82
|
* Limpa mensagens de erro de campos especificados, ou de todos os campos se nenhum for informado.
|
|
@@ -126,4 +133,4 @@ interface UseFormReturn<T> {
|
|
|
126
133
|
setExternalErrors: (errors: Record<string, string[]>) => void;
|
|
127
134
|
}
|
|
128
135
|
|
|
129
|
-
export { DeepPartial, FieldChanged, FieldErrors, FieldFocusOptions, FieldTouched, NestedState, RegisterFunction, UseFormOptionsProps, UseFormProps, UseFormReturn, ValidationMode, ValidatorFunction, ValidatorsSchema };
|
|
136
|
+
export { DeepPartial, FieldChanged, FieldErrors, FieldFocusOptions, FieldTouched, NestedState, RegisterFunction, RegisterOptions, UseFormOptionsProps, UseFormProps, UseFormReturn, ValidationMode, ValidatorFunction, ValidatorsSchema };
|
|
@@ -139,12 +139,17 @@ const useForm = _ref => {
|
|
|
139
139
|
return newValuesState;
|
|
140
140
|
});
|
|
141
141
|
}, []);
|
|
142
|
-
const register = (name,
|
|
142
|
+
const register = (name, registerOptions) => {
|
|
143
|
+
const {
|
|
144
|
+
onChange,
|
|
145
|
+
onBlur,
|
|
146
|
+
ref
|
|
147
|
+
} = registerOptions !== null && registerOptions !== void 0 ? registerOptions : {};
|
|
143
148
|
return {
|
|
144
149
|
name,
|
|
145
150
|
ref: (0, _helpers.mergeRefs)(inputElement => {
|
|
146
151
|
fieldsRef.current[name] = inputElement;
|
|
147
|
-
},
|
|
152
|
+
}, ref),
|
|
148
153
|
value: _lodash.default.get(values, name, _lodash.default.get(initialValuesRef.current, name, '')),
|
|
149
154
|
onChange: event => {
|
|
150
155
|
const {
|
|
@@ -164,8 +169,9 @@ const useForm = _ref => {
|
|
|
164
169
|
}
|
|
165
170
|
return updatedValues;
|
|
166
171
|
});
|
|
172
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(event);
|
|
167
173
|
},
|
|
168
|
-
onBlur:
|
|
174
|
+
onBlur: event => {
|
|
169
175
|
setTouched(prevStateTouched => {
|
|
170
176
|
const updated = _lodash.default.cloneDeep(prevStateTouched);
|
|
171
177
|
_lodash.default.set(updated, name, true);
|
|
@@ -174,6 +180,7 @@ const useForm = _ref => {
|
|
|
174
180
|
if (options.validationMode === 'default') {
|
|
175
181
|
validateField(name, _lodash.default.get(values, name));
|
|
176
182
|
}
|
|
183
|
+
onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
|
|
177
184
|
}
|
|
178
185
|
};
|
|
179
186
|
};
|