@react-stately/color 3.0.0-beta.8 → 3.0.0-beta.9
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/main.js +51 -55
- package/dist/main.js.map +1 -1
- package/dist/module.js +51 -55
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/Color.ts +25 -1
- package/src/useColorAreaState.ts +4 -37
- package/src/useColorWheelState.ts +1 -1
package/src/useColorAreaState.ts
CHANGED
|
@@ -63,9 +63,6 @@ export interface ColorAreaState {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
const DEFAULT_COLOR = parseColor('#ffffff');
|
|
66
|
-
const RGBSet: Set<ColorChannel> = new Set(['red', 'green', 'blue']);
|
|
67
|
-
let difference = <T>(a: Set<T>, b: Set<T>): Set<T> => new Set([...a].filter(x => !b.has(x)));
|
|
68
|
-
|
|
69
66
|
/**
|
|
70
67
|
* Provides state management for a color area component.
|
|
71
68
|
* Color area allows users to adjust two channels of an HSL, HSB or RGB color value against a two-dimensional gradient background.
|
|
@@ -88,38 +85,10 @@ export function useColorAreaState(props: ColorAreaProps): ColorAreaState {
|
|
|
88
85
|
let valueRef = useRef(color);
|
|
89
86
|
valueRef.current = color;
|
|
90
87
|
|
|
91
|
-
let channels = useMemo(() =>
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
case 'green':
|
|
96
|
-
xChannel = 'blue';
|
|
97
|
-
break;
|
|
98
|
-
case 'blue':
|
|
99
|
-
xChannel = 'red';
|
|
100
|
-
break;
|
|
101
|
-
default:
|
|
102
|
-
xChannel = 'blue';
|
|
103
|
-
yChannel = 'green';
|
|
104
|
-
}
|
|
105
|
-
} else if (!yChannel) {
|
|
106
|
-
switch (xChannel) {
|
|
107
|
-
case 'red':
|
|
108
|
-
yChannel = 'green';
|
|
109
|
-
break;
|
|
110
|
-
case 'blue':
|
|
111
|
-
yChannel = 'red';
|
|
112
|
-
break;
|
|
113
|
-
default:
|
|
114
|
-
xChannel = 'blue';
|
|
115
|
-
yChannel = 'green';
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
let xyChannels: Set<ColorChannel> = new Set([xChannel, yChannel]);
|
|
119
|
-
let zChannel = difference(RGBSet, xyChannels).values().next().value;
|
|
120
|
-
|
|
121
|
-
return {xChannel, yChannel, zChannel};
|
|
122
|
-
}, [xChannel, yChannel]);
|
|
88
|
+
let channels = useMemo(() =>
|
|
89
|
+
valueRef.current.getColorSpaceAxes({xChannel, yChannel}),
|
|
90
|
+
[xChannel, yChannel]
|
|
91
|
+
);
|
|
123
92
|
|
|
124
93
|
let xChannelRange = color.getChannelRange(channels.xChannel);
|
|
125
94
|
let yChannelRange = color.getChannelRange(channels.yChannel);
|
|
@@ -163,8 +132,6 @@ export function useColorAreaState(props: ColorAreaProps): ColorAreaState {
|
|
|
163
132
|
yValue,
|
|
164
133
|
setYValue,
|
|
165
134
|
setColorFromPoint(x: number, y: number) {
|
|
166
|
-
let {minValue: minValueX, maxValue: maxValueX} = color.getChannelRange(channels.xChannel);
|
|
167
|
-
let {minValue: minValueY, maxValue: maxValueY} = color.getChannelRange(channels.yChannel);
|
|
168
135
|
let newXValue = minValueX + clamp(x, 0, 1) * (maxValueX - minValueX);
|
|
169
136
|
let newYValue = minValueY + (1 - clamp(y, 0, 1)) * (maxValueY - minValueY);
|
|
170
137
|
let newColor:Color;
|
|
@@ -168,7 +168,7 @@ export function useColorWheelState(props: ColorWheelProps): ColorWheelState {
|
|
|
168
168
|
},
|
|
169
169
|
isDragging,
|
|
170
170
|
getDisplayColor() {
|
|
171
|
-
return value.withChannelValue('saturation', 100).withChannelValue('lightness', 50);
|
|
171
|
+
return value.toFormat('hsl').withChannelValue('saturation', 100).withChannelValue('lightness', 50);
|
|
172
172
|
}
|
|
173
173
|
};
|
|
174
174
|
}
|