Skip to content

Commit 3dd06c3

Browse files
committed
fix(adobe#1118): remove unnecessary cloning of color value
1 parent 0480162 commit 3dd06c3

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ export function useColorAreaState(props: ColorAreaProps): ColorAreaState {
9494
if (!xChannel) {
9595
switch (yChannel) {
9696
case 'red':
97-
xChannel = 'blue';
9897
case 'green':
9998
xChannel = 'blue';
10099
break;
@@ -107,12 +106,12 @@ export function useColorAreaState(props: ColorAreaProps): ColorAreaState {
107106
}
108107
} else if (!yChannel) {
109108
switch (xChannel) {
110-
case 'blue':
111-
yChannel = 'red';
112-
break;
113109
case 'red':
114110
yChannel = 'green';
115111
break;
112+
case 'blue':
113+
yChannel = 'red';
114+
break;
116115
default:
117116
xChannel = 'blue';
118117
yChannel = 'green';
@@ -134,6 +133,7 @@ export function useColorAreaState(props: ColorAreaProps): ColorAreaState {
134133
break;
135134
case 'brightness':
136135
xChannel = 'saturation';
136+
break;
137137
default:
138138
xChannel = 'saturation';
139139
yChannel = 'brightness';
@@ -146,6 +146,7 @@ export function useColorAreaState(props: ColorAreaProps): ColorAreaState {
146146
break;
147147
case 'brightness':
148148
yChannel = 'saturation';
149+
break;
149150
default:
150151
xChannel = 'saturation';
151152
yChannel = 'brightness';
@@ -231,10 +232,10 @@ export function useColorAreaState(props: ColorAreaProps): ColorAreaState {
231232
let newYValue = snapValueToStep(minValueY + ((height - clamp(y, 0, height)) / height) * (maxValueY - minValueY), minValueY, maxValueY, step);
232233
let newColor:Color;
233234
if (newXValue !== xValue) {
234-
newColor = color.clone().withChannelValue(xChannel, newXValue);
235+
newColor = color.withChannelValue(xChannel, newXValue);
235236
}
236237
if (newYValue !== yValue) {
237-
newColor = (newColor || color.clone()).withChannelValue(yChannel, newYValue);
238+
newColor = (newColor || color).withChannelValue(yChannel, newYValue);
238239
}
239240
if (newColor) {
240241
setColor(newColor);

0 commit comments

Comments
 (0)