@juantroconisf/lib 1.9.2 → 2.0.0

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/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { ChangeEvent } from 'react';
3
+ import { InputProps } from '@nextui-org/react';
3
4
 
4
5
  type ValidatorFunction<T, U> = (val: T, ...args: U[]) => boolean;
5
6
  interface Validator<T, U = any> {
@@ -25,17 +26,23 @@ type ValidatorErrorMessage = {
25
26
  [K in keyof ValidatorTypes]: string;
26
27
  };
27
28
 
29
+ interface ValidationProps {
30
+ isInvalid: InputProps["isInvalid"];
31
+ errorMessage: InputProps["errorMessage"];
32
+ }
33
+ interface RegisterInputProps extends ValidationProps {
34
+ id: InputProps["id"];
35
+ onChange: InputProps["onChange"];
36
+ onBlur: InputProps["onBlur"];
37
+ value: InputProps["value"];
38
+ }
39
+
28
40
  declare function useFormChange<InitialObj extends object>(initialObj: InitialObj): {
29
41
  onChange: ({ target: { id, value }, }: ChangeEvent<HTMLInputElement>) => void;
30
42
  onBlur: ({ target: { id } }: ChangeEvent<HTMLInputElement>) => void;
31
43
  state: InitialObj;
32
44
  setState: react.Dispatch<react.SetStateAction<InitialObj>>;
33
- register: <K extends keyof InitialObj>(id: K, validations: ValidatorParams, errorMessages: ValidatorErrorMessage) => {
34
- id: K;
35
- onChange: ({ target: { id, value }, }: ChangeEvent<HTMLInputElement>) => void;
36
- onBlur: ({ target: { id } }: ChangeEvent<HTMLInputElement>) => void;
37
- value: any;
38
- };
45
+ register: <K extends keyof InitialObj>(id: K, validations: ValidatorParams, errorMessages: ValidatorErrorMessage) => RegisterInputProps;
39
46
  hasInvalidValues: () => boolean;
40
47
  touched: InitialObj;
41
48
  resetForm: () => void;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { ChangeEvent } from 'react';
3
+ import { InputProps } from '@nextui-org/react';
3
4
 
4
5
  type ValidatorFunction<T, U> = (val: T, ...args: U[]) => boolean;
5
6
  interface Validator<T, U = any> {
@@ -25,17 +26,23 @@ type ValidatorErrorMessage = {
25
26
  [K in keyof ValidatorTypes]: string;
26
27
  };
27
28
 
29
+ interface ValidationProps {
30
+ isInvalid: InputProps["isInvalid"];
31
+ errorMessage: InputProps["errorMessage"];
32
+ }
33
+ interface RegisterInputProps extends ValidationProps {
34
+ id: InputProps["id"];
35
+ onChange: InputProps["onChange"];
36
+ onBlur: InputProps["onBlur"];
37
+ value: InputProps["value"];
38
+ }
39
+
28
40
  declare function useFormChange<InitialObj extends object>(initialObj: InitialObj): {
29
41
  onChange: ({ target: { id, value }, }: ChangeEvent<HTMLInputElement>) => void;
30
42
  onBlur: ({ target: { id } }: ChangeEvent<HTMLInputElement>) => void;
31
43
  state: InitialObj;
32
44
  setState: react.Dispatch<react.SetStateAction<InitialObj>>;
33
- register: <K extends keyof InitialObj>(id: K, validations: ValidatorParams, errorMessages: ValidatorErrorMessage) => {
34
- id: K;
35
- onChange: ({ target: { id, value }, }: ChangeEvent<HTMLInputElement>) => void;
36
- onBlur: ({ target: { id } }: ChangeEvent<HTMLInputElement>) => void;
37
- value: any;
38
- };
45
+ register: <K extends keyof InitialObj>(id: K, validations: ValidatorParams, errorMessages: ValidatorErrorMessage) => RegisterInputProps;
39
46
  hasInvalidValues: () => boolean;
40
47
  touched: InitialObj;
41
48
  resetForm: () => void;
package/dist/index.js CHANGED
@@ -178,18 +178,19 @@ function useFormChange(initialObj) {
178
178
  function register(id, validations, errorMessages) {
179
179
  const [value, isTouched] = [state, touched].map(
180
180
  (obj) => getNestedValueByKey(obj, id)
181
- ), hasValidations = validations !== void 0, { isValid = false, validationProps = {} } = hasValidations ? getValidation(value, isTouched, validations, errorMessages) : {};
181
+ ), hasValidations = validations !== void 0, inputValidations = hasValidations ? getValidation(value, isTouched, validations, errorMessages) : {};
182
182
  errors2 = handleNestedChange({
183
183
  state: errors2,
184
184
  id,
185
- value: hasValidations ? !isValid : false
185
+ value: hasValidations ? !inputValidations.isValid : false
186
186
  });
187
187
  return {
188
188
  id,
189
189
  onChange,
190
- onBlur,
190
+ onBlur: (e) => onBlur(e),
191
191
  value,
192
- ...validationProps
192
+ isInvalid: hasValidations ? !inputValidations.isValid : false,
193
+ errorMessage: hasValidations ? inputValidations.validationProps.errorMessage : ""
193
194
  };
194
195
  }
195
196
  const hasInvalidValues = () => {
package/dist/index.mjs CHANGED
@@ -160,18 +160,19 @@ function useFormChange(initialObj) {
160
160
  function register(id, validations, errorMessages) {
161
161
  const [value, isTouched] = [state, touched].map(
162
162
  (obj) => getNestedValueByKey(obj, id)
163
- ), hasValidations = validations !== void 0, { isValid = false, validationProps = {} } = hasValidations ? getValidation(value, isTouched, validations, errorMessages) : {};
163
+ ), hasValidations = validations !== void 0, inputValidations = hasValidations ? getValidation(value, isTouched, validations, errorMessages) : {};
164
164
  errors2 = handleNestedChange({
165
165
  state: errors2,
166
166
  id,
167
- value: hasValidations ? !isValid : false
167
+ value: hasValidations ? !inputValidations.isValid : false
168
168
  });
169
169
  return {
170
170
  id,
171
171
  onChange,
172
- onBlur,
172
+ onBlur: (e) => onBlur(e),
173
173
  value,
174
- ...validationProps
174
+ isInvalid: hasValidations ? !inputValidations.isValid : false,
175
+ errorMessage: hasValidations ? inputValidations.validationProps.errorMessage : ""
175
176
  };
176
177
  }
177
178
  const hasInvalidValues = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juantroconisf/lib",
3
- "version": "1.9.2",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -23,6 +23,7 @@
23
23
  "typescript": "^5.5.4"
24
24
  },
25
25
  "dependencies": {
26
+ "@nextui-org/react": "^2.4.8",
26
27
  "react": "^18.3.1"
27
28
  }
28
29
  }