@weser/forms 0.0.5 → 0.0.6
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/defaultIsEmpty.d.ts +1 -0
- package/dist/defaultIsEmpty.js +6 -0
- package/dist/types.d.ts +1 -1
- package/dist/useField.d.ts +2 -2
- package/dist/useField.js +3 -6
- package/dist/useForm.d.ts +1 -1
- package/package.json +4 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function defaultIsEmpty<T>(value: T): boolean | string;
|
package/dist/types.d.ts
CHANGED
|
@@ -14,6 +14,6 @@ export type Options<T> = {
|
|
|
14
14
|
touched?: boolean;
|
|
15
15
|
showValidationOn?: 'submit' | 'blur' | 'change';
|
|
16
16
|
parseValue?: (e: any) => T;
|
|
17
|
-
formatErrorMessage?: (error: ZodIssue, name?: string) => string;
|
|
17
|
+
formatErrorMessage?: (error: ZodIssue, value: T, name?: string) => string;
|
|
18
18
|
_onUpdateValue?: (value: T, dirty: boolean) => void;
|
|
19
19
|
};
|
package/dist/useField.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ChangeEvent } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { ZodType } from 'zod';
|
|
3
3
|
import { Field, Options } from './types.js';
|
|
4
|
-
export default function useField<T = string, C = ChangeEvent<HTMLInputElement>>(schema:
|
|
4
|
+
export default function useField<T = string, C = ChangeEvent<HTMLInputElement>>(schema: ZodType, { name, value, disabled, touched, showValidationOn, parseValue, formatErrorMessage, _onUpdateValue, }?: Options<T>): {
|
|
5
5
|
required: boolean;
|
|
6
6
|
valid: boolean;
|
|
7
7
|
update: (data: Partial<Field<T>>) => void;
|
package/dist/useField.js
CHANGED
|
@@ -4,12 +4,9 @@ import defaultParseValue from './defaultParseValue.js';
|
|
|
4
4
|
export default function useField(schema, { name, value = '', disabled = false, touched = false, showValidationOn = 'submit', parseValue = (defaultParseValue), formatErrorMessage = defaultFormatErrorMessage, _onUpdateValue, } = {}) {
|
|
5
5
|
const isOptional = schema.isOptional();
|
|
6
6
|
function validate(value) {
|
|
7
|
-
const
|
|
8
|
-
if (
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
else {
|
|
12
|
-
return formatErrorMessage(res.error.errors[0], name);
|
|
7
|
+
const { success, error } = schema.safeParse(value);
|
|
8
|
+
if (!success) {
|
|
9
|
+
return formatErrorMessage(error.issues[0], value, name);
|
|
13
10
|
}
|
|
14
11
|
}
|
|
15
12
|
const message = validate(value);
|
package/dist/useForm.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FormEvent, ChangeEvent } from 'react';
|
|
2
2
|
import { z, ZodObject, ZodError, ZodRawShape, ZodIssue } from 'zod';
|
|
3
3
|
import { Field, Options } from './types.js';
|
|
4
|
-
export default function useForm<S extends ZodRawShape>(schema: ZodObject<S>, formatErrorMessage?: (error: ZodIssue, name
|
|
4
|
+
export default function useForm<S extends ZodRawShape>(schema: ZodObject<S>, formatErrorMessage?: (error: ZodIssue, value: any, name: string) => string): {
|
|
5
5
|
useFormField: <T = string>(name: keyof S, options?: Omit<Options<T>, 'formatErrorMessage' | 'name' | '_onUpdateValue'>) => {
|
|
6
6
|
reset: () => void;
|
|
7
7
|
required: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weser/forms",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "React hooks for forms with zod schemas",
|
|
5
5
|
"author": "Robin Weser <robin@weser.io>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -52,7 +52,8 @@
|
|
|
52
52
|
"ava": "^6.1.3",
|
|
53
53
|
"react": "canary",
|
|
54
54
|
"rimraf": "^3.0.2",
|
|
55
|
-
"typescript": "^5.4.5"
|
|
55
|
+
"typescript": "^5.4.5",
|
|
56
|
+
"zod": "4.0.0-beta.20250505T195954"
|
|
56
57
|
},
|
|
57
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "44a3bbb88cf4c563fd606cab6c65ca99d82c00a3"
|
|
58
59
|
}
|