Skip to content

Commit 65a6792

Browse files
authored
Color release audit (#2916)
* Color release audit
1 parent 320c699 commit 65a6792

File tree

6 files changed

+24
-14
lines changed

6 files changed

+24
-14
lines changed

packages/@react-aria/color/src/useColorArea.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,25 @@ interface ColorAreaAria {
3333
yInputProps: InputHTMLAttributes<HTMLInputElement>
3434
}
3535

36+
interface ColorAreaAriaProps extends AriaColorAreaProps {
37+
/** A ref to the input that represents the x axis of the color area. */
38+
inputXRef: RefObject<HTMLElement>,
39+
/** A ref to the input that represents the y axis of the color area. */
40+
inputYRef: RefObject<HTMLElement>,
41+
/** A ref to the color area containing element. */
42+
containerRef: RefObject<HTMLElement>
43+
}
44+
3645
/**
3746
* Provides the behavior and accessibility implementation for a color wheel component.
3847
* Color wheels allow users to adjust the hue of an HSL or HSB color value on a circular track.
3948
*/
40-
export function useColorArea(props: AriaColorAreaProps, state: ColorAreaState, inputXRef: RefObject<HTMLElement>, inputYRef: RefObject<HTMLElement>, containerRef: RefObject<HTMLElement>): ColorAreaAria {
49+
export function useColorArea(props: ColorAreaAriaProps, state: ColorAreaState): ColorAreaAria {
4150
let {
42-
isDisabled
51+
isDisabled,
52+
inputXRef,
53+
inputYRef,
54+
containerRef
4355
} = props;
4456
let formatMessage = useMessageFormatter(intlMessages);
4557

packages/@react-spectrum/color/src/ColorArea.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ function ColorArea(props: SpectrumColorAreaProps, ref: FocusableRef<HTMLDivEleme
3030
let size = props.size && dimensionValue(props.size);
3131
let {styleProps} = useStyleProps(props);
3232

33-
let xInputRef = useRef(null);
34-
let yInputRef = useRef(null);
35-
let containerRef = useFocusableRef(ref, xInputRef);
33+
let inputXRef = useRef();
34+
let inputYRef = useRef();
35+
let containerRef = useFocusableRef(ref, inputXRef);
3636

3737
let state = useColorAreaState(props);
3838

@@ -43,7 +43,7 @@ function ColorArea(props: SpectrumColorAreaProps, ref: FocusableRef<HTMLDivEleme
4343
xInputProps,
4444
yInputProps,
4545
thumbProps
46-
} = useColorArea(props, state, xInputRef, yInputRef, containerRef);
46+
} = useColorArea({...props, inputXRef, inputYRef, containerRef}, state);
4747
let {direction} = useLocale();
4848
let {colorAreaStyleProps, gradientStyleProps, thumbStyleProps} = useGradients({direction, state, xChannel, zChannel, isDisabled: props.isDisabled});
4949

@@ -80,8 +80,8 @@ function ColorArea(props: SpectrumColorAreaProps, ref: FocusableRef<HTMLDivEleme
8080
{...thumbProps}
8181
{...thumbStyleProps}>
8282
<div role="presentation">
83-
<input className={classNames(styles, 'spectrum-ColorArea-slider')} {...mergeProps(xInputProps, focusProps)} ref={xInputRef} />
84-
<input className={classNames(styles, 'spectrum-ColorArea-slider')} {...mergeProps(yInputProps, focusProps)} ref={yInputRef} />
83+
<input className={classNames(styles, 'spectrum-ColorArea-slider')} {...mergeProps(xInputProps, focusProps)} ref={inputXRef} />
84+
<input className={classNames(styles, 'spectrum-ColorArea-slider')} {...mergeProps(yInputProps, focusProps)} ref={inputYRef} />
8585
</div>
8686
</ColorThumb>
8787
</div>

packages/@react-stately/color/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"@babel/runtime": "^7.6.2",
2121
"@internationalized/message": "^3.0.2",
2222
"@internationalized/number": "^3.0.3",
23-
"@react-aria/utils": "^3.9.0",
2423
"@react-stately/slider": "^3.0.3",
2524
"@react-stately/utils": "^3.3.0",
2625
"@react-types/color": "3.0.0-beta.5",

packages/@react-stately/color/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
export * from './Color';
13+
export {parseColor} from './Color';
1414
export * from './useColorAreaState';
1515
export * from './useColorSliderState';
1616
export * from './useColorWheelState';

packages/@react-stately/color/src/useColorAreaState.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {clamp, snapValueToStep} from '@react-aria/utils';
13+
import {clamp, snapValueToStep, useControlledState} from '@react-stately/utils';
1414
import {Color, ColorAreaProps, ColorChannel} from '@react-types/color';
1515
import {normalizeColor, parseColor} from './Color';
16-
import {useControlledState} from '@react-stately/utils';
1716
import {useMemo, useRef, useState} from 'react';
1817

1918
export interface ColorAreaState {

packages/@react-stately/color/src/useColorWheelState.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,15 @@ export function useColorWheelState(props: ColorWheelProps): ColorWheelState {
138138
getThumbPosition(radius) {
139139
return angleToCartesian(value.getChannelValue('hue'), radius);
140140
},
141-
increment(stepSize) {
141+
increment(stepSize = 1) {
142142
let newValue = hue + Math.max(stepSize, step);
143143
if (newValue > maxValueX) {
144144
// Make sure you can always get back to 0.
145145
newValue = minValueX;
146146
}
147147
setHue(newValue);
148148
},
149-
decrement(stepSize) {
149+
decrement(stepSize = 1) {
150150
let s = Math.max(stepSize, step);
151151
if (hue === 0) {
152152
// We can't just subtract step because this might be the case:

0 commit comments

Comments
 (0)