@react-types/shared 3.0.0-nightly.2517 → 3.0.0-nightly.2531
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/package.json +2 -2
- package/src/inputs.d.ts +31 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-types/shared",
|
|
3
|
-
"version": "3.0.0-nightly.
|
|
3
|
+
"version": "3.0.0-nightly.2531+068ecd12e",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
"publishConfig": {
|
|
15
15
|
"access": "public"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "068ecd12e8a8c61546dfda691b04ca87cbdae687"
|
|
18
18
|
}
|
package/src/inputs.d.ts
CHANGED
|
@@ -14,16 +14,43 @@ import {ReactNode} from 'react';
|
|
|
14
14
|
|
|
15
15
|
export type ValidationState = 'valid' | 'invalid';
|
|
16
16
|
|
|
17
|
-
export
|
|
17
|
+
export type ValidationError = string | string[];
|
|
18
|
+
export type ValidationErrors = Record<string, ValidationError>;
|
|
19
|
+
export type ValidationFunction<T> = (value: T) => ValidationError | true | null | undefined;
|
|
20
|
+
|
|
21
|
+
export interface Validation<T> {
|
|
18
22
|
/** Whether user input is required on the input before form submission. */
|
|
19
23
|
isRequired?: boolean,
|
|
20
24
|
/** Whether the input value is invalid. */
|
|
21
25
|
isInvalid?: boolean,
|
|
22
26
|
/** @deprecated Use `isInvalid` instead. */
|
|
23
|
-
validationState?: ValidationState
|
|
27
|
+
validationState?: ValidationState,
|
|
28
|
+
/**
|
|
29
|
+
* Whether to use native HTML form validation to prevent form submission
|
|
30
|
+
* when the value is missing or invalid, or mark the field as required
|
|
31
|
+
* or invalid via ARIA.
|
|
32
|
+
* @default 'aria'
|
|
33
|
+
*/
|
|
34
|
+
validationBehavior?: 'aria' | 'native',
|
|
35
|
+
/**
|
|
36
|
+
* A function that returns an error message if a given value is invalid.
|
|
37
|
+
* Validation errors are displayed to the user when the form is submitted
|
|
38
|
+
* if `validationBehavior="native"`. For realtime validation, use the `isInvalid`
|
|
39
|
+
* prop instead.
|
|
40
|
+
*/
|
|
41
|
+
validate?: ValidationFunction<T>
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface ValidationResult {
|
|
45
|
+
/** Whether the input value is invalid. */
|
|
46
|
+
isInvalid: boolean,
|
|
47
|
+
/** The current error messages for the input if it is invalid, otherwise an empty array. */
|
|
48
|
+
validationErrors: string[],
|
|
49
|
+
/** The native validation details for the input. */
|
|
50
|
+
validationDetails: ValidityState
|
|
24
51
|
}
|
|
25
52
|
|
|
26
|
-
export interface SpectrumFieldValidation extends Omit<Validation
|
|
53
|
+
export interface SpectrumFieldValidation<T> extends Omit<Validation<T>, 'isInvalid' | 'validationState'> {
|
|
27
54
|
/** Whether the input should display its "valid" or "invalid" visual styling. */
|
|
28
55
|
validationState?: ValidationState
|
|
29
56
|
}
|
|
@@ -78,7 +105,7 @@ export interface HelpTextProps {
|
|
|
78
105
|
/** A description for the field. Provides a hint such as specific requirements for what to choose. */
|
|
79
106
|
description?: ReactNode,
|
|
80
107
|
/** An error message for the field. */
|
|
81
|
-
errorMessage?: ReactNode
|
|
108
|
+
errorMessage?: ReactNode | ((v: ValidationResult) => ReactNode)
|
|
82
109
|
}
|
|
83
110
|
|
|
84
111
|
// Spectrum specific types. Extends `Validation` so that the `validationState` prop is available.
|