@react-aria/color 3.0.0-beta.26 → 3.0.0-beta.27
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/import.mjs +76 -65
- package/dist/main.js +77 -65
- package/dist/main.js.map +1 -1
- package/dist/module.js +76 -65
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/useColorArea.ts +5 -5
- package/src/useColorField.ts +27 -16
- package/src/useColorWheel.ts +4 -4
package/src/useColorField.ts
CHANGED
|
@@ -20,11 +20,13 @@ import {
|
|
|
20
20
|
useState
|
|
21
21
|
} from 'react';
|
|
22
22
|
import {mergeProps, useId} from '@react-aria/utils';
|
|
23
|
+
import {privateValidationStateProp} from '@react-stately/form';
|
|
23
24
|
import {useFocusWithin, useScrollWheel} from '@react-aria/interactions';
|
|
24
25
|
import {useFormattedTextField} from '@react-aria/textfield';
|
|
25
26
|
import {useSpinButton} from '@react-aria/spinbutton';
|
|
27
|
+
import {ValidationResult} from '@react-types/shared';
|
|
26
28
|
|
|
27
|
-
export interface ColorFieldAria {
|
|
29
|
+
export interface ColorFieldAria extends ValidationResult {
|
|
28
30
|
/** Props for the label element. */
|
|
29
31
|
labelProps: LabelHTMLAttributes<HTMLLabelElement>,
|
|
30
32
|
/** Props for the input element. */
|
|
@@ -43,17 +45,18 @@ export function useColorField(
|
|
|
43
45
|
let {
|
|
44
46
|
isDisabled,
|
|
45
47
|
isReadOnly,
|
|
46
|
-
isRequired
|
|
48
|
+
isRequired,
|
|
49
|
+
validationBehavior = 'aria'
|
|
47
50
|
} = props;
|
|
48
51
|
|
|
49
52
|
let {
|
|
50
53
|
colorValue,
|
|
51
54
|
inputValue,
|
|
52
|
-
commit,
|
|
53
55
|
increment,
|
|
54
56
|
decrement,
|
|
55
57
|
incrementToMax,
|
|
56
|
-
decrementToMin
|
|
58
|
+
decrementToMin,
|
|
59
|
+
commit
|
|
57
60
|
} = state;
|
|
58
61
|
|
|
59
62
|
let inputId = useId();
|
|
@@ -96,27 +99,35 @@ export function useColorField(
|
|
|
96
99
|
}
|
|
97
100
|
};
|
|
98
101
|
|
|
99
|
-
let {
|
|
102
|
+
let {inputProps, ...otherProps} = useFormattedTextField(
|
|
100
103
|
mergeProps(props, {
|
|
101
104
|
id: inputId,
|
|
102
105
|
value: inputValue,
|
|
103
106
|
defaultValue: undefined,
|
|
107
|
+
validate: undefined,
|
|
108
|
+
[privateValidationStateProp]: state,
|
|
104
109
|
type: 'text',
|
|
105
110
|
autoComplete: 'off',
|
|
106
111
|
onChange
|
|
107
112
|
}), state, ref);
|
|
108
113
|
|
|
114
|
+
inputProps = mergeProps(inputProps, spinButtonProps, focusWithinProps, {
|
|
115
|
+
role: 'textbox',
|
|
116
|
+
'aria-valuemax': null,
|
|
117
|
+
'aria-valuemin': null,
|
|
118
|
+
'aria-valuenow': null,
|
|
119
|
+
'aria-valuetext': null,
|
|
120
|
+
autoCorrect: 'off',
|
|
121
|
+
spellCheck: 'false',
|
|
122
|
+
onBlur: commit
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
if (validationBehavior === 'native') {
|
|
126
|
+
inputProps['aria-required'] = undefined;
|
|
127
|
+
}
|
|
128
|
+
|
|
109
129
|
return {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
role: 'textbox',
|
|
113
|
-
'aria-valuemax': null,
|
|
114
|
-
'aria-valuemin': null,
|
|
115
|
-
'aria-valuenow': null,
|
|
116
|
-
'aria-valuetext': null,
|
|
117
|
-
autoCorrect: 'off',
|
|
118
|
-
spellCheck: 'false',
|
|
119
|
-
onBlur: commit
|
|
120
|
-
})
|
|
130
|
+
inputProps,
|
|
131
|
+
...otherProps
|
|
121
132
|
};
|
|
122
133
|
}
|
package/src/useColorWheel.ts
CHANGED
|
@@ -59,7 +59,7 @@ export function useColorWheel(props: AriaColorWheelOptions, state: ColorWheelSta
|
|
|
59
59
|
|
|
60
60
|
useFormReset(inputRef, state.hue, state.setHue);
|
|
61
61
|
|
|
62
|
-
let currentPosition = useRef<{x: number, y: number}>(null);
|
|
62
|
+
let currentPosition = useRef<{x: number, y: number} | null>(null);
|
|
63
63
|
|
|
64
64
|
let {keyboardProps} = useKeyboard({
|
|
65
65
|
onKeyDown(e) {
|
|
@@ -108,7 +108,7 @@ export function useColorWheel(props: AriaColorWheelOptions, state: ColorWheelSta
|
|
|
108
108
|
}
|
|
109
109
|
},
|
|
110
110
|
onMoveEnd() {
|
|
111
|
-
isOnTrack.current =
|
|
111
|
+
isOnTrack.current = false;
|
|
112
112
|
state.setDragging(false);
|
|
113
113
|
focusInput();
|
|
114
114
|
}
|
|
@@ -135,7 +135,7 @@ export function useColorWheel(props: AriaColorWheelOptions, state: ColorWheelSta
|
|
|
135
135
|
}
|
|
136
136
|
});
|
|
137
137
|
|
|
138
|
-
let onThumbDown = (id: number | null) => {
|
|
138
|
+
let onThumbDown = (id: number | null | undefined) => {
|
|
139
139
|
if (!state.isDragging) {
|
|
140
140
|
currentPointer.current = id;
|
|
141
141
|
focusInput();
|
|
@@ -167,7 +167,7 @@ export function useColorWheel(props: AriaColorWheelOptions, state: ColorWheelSta
|
|
|
167
167
|
}
|
|
168
168
|
};
|
|
169
169
|
|
|
170
|
-
let onTrackDown = (track: Element, id: number | null, pageX: number, pageY: number) => {
|
|
170
|
+
let onTrackDown = (track: Element, id: number | null | undefined, pageX: number, pageY: number) => {
|
|
171
171
|
let rect = track.getBoundingClientRect();
|
|
172
172
|
let x = pageX - rect.x - rect.width / 2;
|
|
173
173
|
let y = pageY - rect.y - rect.height / 2;
|