@octanejs/colorful 0.0.26 → 0.0.28
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 +4 -4
- package/src/components/HexAlphaColorPicker.tsrx +3 -2
- package/src/components/HexColorInput.tsrx +9 -7
- package/src/components/HexColorPicker.tsrx +3 -2
- package/src/components/HslColorPicker.tsrx +3 -2
- package/src/components/HslStringColorPicker.tsrx +3 -2
- package/src/components/HslaColorPicker.tsrx +3 -2
- package/src/components/HslaStringColorPicker.tsrx +3 -2
- package/src/components/HsvColorPicker.tsrx +3 -2
- package/src/components/HsvStringColorPicker.tsrx +3 -2
- package/src/components/HsvaColorPicker.tsrx +3 -2
- package/src/components/HsvaStringColorPicker.tsrx +3 -2
- package/src/components/RgbColorPicker.tsrx +3 -2
- package/src/components/RgbStringColorPicker.tsrx +3 -2
- package/src/components/RgbaColorPicker.tsrx +3 -2
- package/src/components/RgbaStringColorPicker.tsrx +3 -2
- package/src/components/common/Alpha.tsrx +21 -19
- package/src/components/common/AlphaColorPicker.tsrx +28 -24
- package/src/components/common/ColorInput.tsrx +35 -23
- package/src/components/common/ColorPicker.tsrx +27 -23
- package/src/components/common/Hue.tsrx +23 -20
- package/src/components/common/Interactive.tsrx +23 -28
- package/src/components/common/Pointer.tsrx +5 -3
- package/src/components/common/Saturation.tsrx +18 -16
- package/src/hooks/useColorManipulation.tsrx +3 -5
- package/src/hooks/useEventCallback.tsrx +1 -2
- package/src/hooks/useStyleSheet.tsrx +2 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/colorful",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.28",
|
|
4
4
|
"description": "Exact Octane binding for react-colorful 5.8.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -33,13 +33,13 @@
|
|
|
33
33
|
".": "./src/index.ts"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"octane": "^0.
|
|
36
|
+
"octane": "^0.11.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@tsrx/react": "^0.
|
|
39
|
+
"@tsrx/react": "^0.4.5",
|
|
40
40
|
"@types/react": "19.2.17",
|
|
41
41
|
"@types/react-dom": "19.2.3",
|
|
42
|
-
"octane": "0.
|
|
42
|
+
"octane": "0.11.0",
|
|
43
43
|
"playwright": "^1.61.1",
|
|
44
44
|
"react": "19.2.7",
|
|
45
45
|
"react-colorful": "5.8.0",
|
|
@@ -10,5 +10,6 @@ const colorModel: ColorModel<string> = {
|
|
|
10
10
|
equal: equalHex,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export const HexAlphaColorPicker = (props: Partial<ColorPickerBaseProps<string>>) =>
|
|
14
|
-
<AlphaColorPicker {...props} colorModel={colorModel}
|
|
13
|
+
export const HexAlphaColorPicker = (props: Partial<ColorPickerBaseProps<string>>) => (
|
|
14
|
+
<AlphaColorPicker {...props} colorModel={colorModel} />
|
|
15
|
+
);
|
|
@@ -16,11 +16,13 @@ export const HexColorInput = ({ prefixed, alpha, ...rest }: HexColorInputProps)
|
|
|
16
16
|
[alpha],
|
|
17
17
|
);
|
|
18
18
|
const validate = useCallback((value: string) => validHex(value, alpha), [alpha]);
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
return (
|
|
20
|
+
<ColorInput
|
|
21
|
+
{...rest}
|
|
22
|
+
escape={escape}
|
|
23
|
+
format={prefixed ? prefix : undefined}
|
|
24
|
+
process={prefix}
|
|
25
|
+
validate={validate}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
26
28
|
};
|
|
@@ -10,5 +10,6 @@ const colorModel: ColorModel<string> = {
|
|
|
10
10
|
equal: equalHex,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export const HexColorPicker = (props: Partial<ColorPickerBaseProps<string>>) =>
|
|
14
|
-
<ColorPicker {...props} colorModel={colorModel}
|
|
13
|
+
export const HexColorPicker = (props: Partial<ColorPickerBaseProps<string>>) => (
|
|
14
|
+
<ColorPicker {...props} colorModel={colorModel} />
|
|
15
|
+
);
|
|
@@ -10,5 +10,6 @@ const colorModel: ColorModel<HslColor> = {
|
|
|
10
10
|
equal: equalColorObjects,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export const HslColorPicker = (props: Partial<ColorPickerBaseProps<HslColor>>) =>
|
|
14
|
-
<ColorPicker {...props} colorModel={colorModel}
|
|
13
|
+
export const HslColorPicker = (props: Partial<ColorPickerBaseProps<HslColor>>) => (
|
|
14
|
+
<ColorPicker {...props} colorModel={colorModel} />
|
|
15
|
+
);
|
|
@@ -10,5 +10,6 @@ const colorModel: ColorModel<string> = {
|
|
|
10
10
|
equal: equalColorString,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export const HslStringColorPicker = (props: Partial<ColorPickerBaseProps<string>>) =>
|
|
14
|
-
<ColorPicker {...props} colorModel={colorModel}
|
|
13
|
+
export const HslStringColorPicker = (props: Partial<ColorPickerBaseProps<string>>) => (
|
|
14
|
+
<ColorPicker {...props} colorModel={colorModel} />
|
|
15
|
+
);
|
|
@@ -10,5 +10,6 @@ const colorModel: ColorModel<HslaColor> = {
|
|
|
10
10
|
equal: equalColorObjects,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export const HslaColorPicker = (props: Partial<ColorPickerBaseProps<HslaColor>>) =>
|
|
14
|
-
<AlphaColorPicker {...props} colorModel={colorModel}
|
|
13
|
+
export const HslaColorPicker = (props: Partial<ColorPickerBaseProps<HslaColor>>) => (
|
|
14
|
+
<AlphaColorPicker {...props} colorModel={colorModel} />
|
|
15
|
+
);
|
|
@@ -10,5 +10,6 @@ const colorModel: ColorModel<string> = {
|
|
|
10
10
|
equal: equalColorString,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export const HslaStringColorPicker = (props: Partial<ColorPickerBaseProps<string>>) =>
|
|
14
|
-
<AlphaColorPicker {...props} colorModel={colorModel}
|
|
13
|
+
export const HslaStringColorPicker = (props: Partial<ColorPickerBaseProps<string>>) => (
|
|
14
|
+
<AlphaColorPicker {...props} colorModel={colorModel} />
|
|
15
|
+
);
|
|
@@ -10,5 +10,6 @@ const colorModel: ColorModel<HsvColor> = {
|
|
|
10
10
|
equal: equalColorObjects,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export const HsvColorPicker = (props: Partial<ColorPickerBaseProps<HsvColor>>) =>
|
|
14
|
-
<ColorPicker {...props} colorModel={colorModel}
|
|
13
|
+
export const HsvColorPicker = (props: Partial<ColorPickerBaseProps<HsvColor>>) => (
|
|
14
|
+
<ColorPicker {...props} colorModel={colorModel} />
|
|
15
|
+
);
|
|
@@ -10,5 +10,6 @@ const colorModel: ColorModel<string> = {
|
|
|
10
10
|
equal: equalColorString,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export const HsvStringColorPicker = (props: Partial<ColorPickerBaseProps<string>>) =>
|
|
14
|
-
<ColorPicker {...props} colorModel={colorModel}
|
|
13
|
+
export const HsvStringColorPicker = (props: Partial<ColorPickerBaseProps<string>>) => (
|
|
14
|
+
<ColorPicker {...props} colorModel={colorModel} />
|
|
15
|
+
);
|
|
@@ -10,5 +10,6 @@ const colorModel: ColorModel<HsvaColor> = {
|
|
|
10
10
|
equal: equalColorObjects,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export const HsvaColorPicker = (props: Partial<ColorPickerBaseProps<HsvaColor>>) =>
|
|
14
|
-
<AlphaColorPicker {...props} colorModel={colorModel}
|
|
13
|
+
export const HsvaColorPicker = (props: Partial<ColorPickerBaseProps<HsvaColor>>) => (
|
|
14
|
+
<AlphaColorPicker {...props} colorModel={colorModel} />
|
|
15
|
+
);
|
|
@@ -10,5 +10,6 @@ const colorModel: ColorModel<string> = {
|
|
|
10
10
|
equal: equalColorString,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export const HsvaStringColorPicker = (props: Partial<ColorPickerBaseProps<string>>) =>
|
|
14
|
-
<AlphaColorPicker {...props} colorModel={colorModel}
|
|
13
|
+
export const HsvaStringColorPicker = (props: Partial<ColorPickerBaseProps<string>>) => (
|
|
14
|
+
<AlphaColorPicker {...props} colorModel={colorModel} />
|
|
15
|
+
);
|
|
@@ -10,5 +10,6 @@ const colorModel: ColorModel<RgbColor> = {
|
|
|
10
10
|
equal: equalColorObjects,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export const RgbColorPicker = (props: Partial<ColorPickerBaseProps<RgbColor>>) =>
|
|
14
|
-
<ColorPicker {...props} colorModel={colorModel}
|
|
13
|
+
export const RgbColorPicker = (props: Partial<ColorPickerBaseProps<RgbColor>>) => (
|
|
14
|
+
<ColorPicker {...props} colorModel={colorModel} />
|
|
15
|
+
);
|
|
@@ -10,5 +10,6 @@ const colorModel: ColorModel<string> = {
|
|
|
10
10
|
equal: equalColorString,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export const RgbStringColorPicker = (props: Partial<ColorPickerBaseProps<string>>) =>
|
|
14
|
-
<ColorPicker {...props} colorModel={colorModel}
|
|
13
|
+
export const RgbStringColorPicker = (props: Partial<ColorPickerBaseProps<string>>) => (
|
|
14
|
+
<ColorPicker {...props} colorModel={colorModel} />
|
|
15
|
+
);
|
|
@@ -10,5 +10,6 @@ const colorModel: ColorModel<RgbaColor> = {
|
|
|
10
10
|
equal: equalColorObjects,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export const RgbaColorPicker = (props: Partial<ColorPickerBaseProps<RgbaColor>>) =>
|
|
14
|
-
<AlphaColorPicker {...props} colorModel={colorModel}
|
|
13
|
+
export const RgbaColorPicker = (props: Partial<ColorPickerBaseProps<RgbaColor>>) => (
|
|
14
|
+
<AlphaColorPicker {...props} colorModel={colorModel} />
|
|
15
|
+
);
|
|
@@ -10,5 +10,6 @@ const colorModel: ColorModel<string> = {
|
|
|
10
10
|
equal: equalColorString,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
export const RgbaStringColorPicker = (props: Partial<ColorPickerBaseProps<string>>) =>
|
|
14
|
-
<AlphaColorPicker {...props} colorModel={colorModel}
|
|
13
|
+
export const RgbaStringColorPicker = (props: Partial<ColorPickerBaseProps<string>>) => (
|
|
14
|
+
<AlphaColorPicker {...props} colorModel={colorModel} />
|
|
15
|
+
);
|
|
@@ -21,23 +21,25 @@ export const Alpha = ({ className, hsva, onChange, onChangeEnd }: Props) => {
|
|
|
21
21
|
const gradientStyle = { backgroundImage: `linear-gradient(90deg, ${colorFrom}, ${colorTo})` };
|
|
22
22
|
const nodeClassName = formatClassName(['react-colorful__alpha', className]);
|
|
23
23
|
const ariaValue = round(hsva.a * 100);
|
|
24
|
-
return
|
|
25
|
-
<div class=
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
24
|
+
return (
|
|
25
|
+
<div class={nodeClassName}>
|
|
26
|
+
<div class="react-colorful__alpha-gradient" style={gradientStyle} />
|
|
27
|
+
<Interactive
|
|
28
|
+
onMove={handleMove}
|
|
29
|
+
onKey={handleKey}
|
|
30
|
+
onEnd={onChangeEnd}
|
|
31
|
+
aria-label="Alpha"
|
|
32
|
+
aria-valuetext={`${ariaValue}%`}
|
|
33
|
+
aria-valuenow={ariaValue}
|
|
34
|
+
aria-valuemin={0}
|
|
35
|
+
aria-valuemax={100}
|
|
36
|
+
>
|
|
37
|
+
<Pointer
|
|
38
|
+
className="react-colorful__alpha-pointer"
|
|
39
|
+
left={hsva.a}
|
|
40
|
+
color={hsvaToHslaString(hsva)}
|
|
41
|
+
/>
|
|
42
|
+
</Interactive>
|
|
43
|
+
</div>
|
|
44
|
+
);
|
|
43
45
|
};
|
|
@@ -30,23 +30,25 @@ function AlphaColorPickerRoot({
|
|
|
30
30
|
onChange,
|
|
31
31
|
onChangeEnd,
|
|
32
32
|
}: RootProps) {
|
|
33
|
-
return
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
return (
|
|
34
|
+
<div
|
|
35
|
+
{...hostProps}
|
|
36
|
+
ref={[hostProps.ref ?? null, nodeRef]}
|
|
37
|
+
class={['react-colorful', className, classValue]}
|
|
38
|
+
>
|
|
39
|
+
<Saturation hsva={hsva} onChange={onChange} onChangeEnd={onChangeEnd} />
|
|
40
|
+
<Hue hue={hsva.h} onChange={onChange} onChangeEnd={onChangeEnd} />
|
|
41
|
+
<Alpha
|
|
42
|
+
hsva={hsva}
|
|
43
|
+
onChange={onChange}
|
|
44
|
+
onChangeEnd={onChangeEnd}
|
|
45
|
+
className="react-colorful__last-control"
|
|
46
|
+
/>
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
47
49
|
}
|
|
48
50
|
|
|
49
|
-
export const AlphaColorPicker = <T extends AnyColor
|
|
51
|
+
export const AlphaColorPicker = <T extends AnyColor>({
|
|
50
52
|
class: classValue,
|
|
51
53
|
className,
|
|
52
54
|
colorModel,
|
|
@@ -63,13 +65,15 @@ export const AlphaColorPicker = <T extends AnyColor,>({
|
|
|
63
65
|
onChange,
|
|
64
66
|
onChangeEnd,
|
|
65
67
|
);
|
|
66
|
-
return
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
return (
|
|
69
|
+
<AlphaColorPickerRoot
|
|
70
|
+
hostProps={rest}
|
|
71
|
+
nodeRef={nodeRef}
|
|
72
|
+
className={className}
|
|
73
|
+
classValue={classValue}
|
|
74
|
+
hsva={hsva}
|
|
75
|
+
onChange={updateHsva}
|
|
76
|
+
onChangeEnd={commitChange}
|
|
77
|
+
/>
|
|
78
|
+
);
|
|
75
79
|
};
|
|
@@ -27,33 +27,45 @@ export const ColorInput = (props: Props) => {
|
|
|
27
27
|
FocusEvent & { currentTarget: HTMLInputElement & EventTarget }
|
|
28
28
|
>(onBlur);
|
|
29
29
|
|
|
30
|
-
const handleInput = useCallback(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
const handleInput = useCallback(
|
|
31
|
+
(
|
|
32
|
+
event: InputEvent & {
|
|
33
|
+
currentTarget: HTMLInputElement & EventTarget;
|
|
34
|
+
},
|
|
35
|
+
) => {
|
|
36
|
+
const target = event.currentTarget;
|
|
37
|
+
const inputValue = escape(target.value);
|
|
38
|
+
setValue(inputValue);
|
|
39
|
+
if (validate(inputValue)) onChangeCallback(process ? process(inputValue) : inputValue);
|
|
40
|
+
onInput?.(event);
|
|
41
|
+
},
|
|
42
|
+
[escape, process, validate, onChangeCallback, onInput],
|
|
43
|
+
);
|
|
39
44
|
|
|
40
|
-
const handleBlur = useCallback(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
const handleBlur = useCallback(
|
|
46
|
+
(
|
|
47
|
+
event: FocusEvent & {
|
|
48
|
+
currentTarget: HTMLInputElement & EventTarget;
|
|
49
|
+
},
|
|
50
|
+
) => {
|
|
51
|
+
const target = event.currentTarget;
|
|
52
|
+
if (!validate(target.value)) setValue(escape(color));
|
|
53
|
+
onBlurCallback(event);
|
|
54
|
+
},
|
|
55
|
+
[color, escape, validate, onBlurCallback],
|
|
56
|
+
);
|
|
47
57
|
|
|
48
58
|
useEffect(() => {
|
|
49
59
|
setValue(escape(color));
|
|
50
60
|
}, [color, escape]);
|
|
51
61
|
|
|
52
|
-
return
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
return (
|
|
63
|
+
<input
|
|
64
|
+
{...rest}
|
|
65
|
+
value={format ? format(value) : value}
|
|
66
|
+
spellCheck="false"
|
|
67
|
+
onInput={handleInput}
|
|
68
|
+
onBlur={handleBlur}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
59
71
|
};
|
|
@@ -29,22 +29,24 @@ function ColorPickerRoot({
|
|
|
29
29
|
onChange,
|
|
30
30
|
onChangeEnd,
|
|
31
31
|
}: RootProps) {
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
return (
|
|
33
|
+
<div
|
|
34
|
+
{...hostProps}
|
|
35
|
+
ref={[hostProps.ref ?? null, nodeRef]}
|
|
36
|
+
class={['react-colorful', className, classValue]}
|
|
37
|
+
>
|
|
38
|
+
<Saturation hsva={hsva} onChange={onChange} onChangeEnd={onChangeEnd} />
|
|
39
|
+
<Hue
|
|
40
|
+
hue={hsva.h}
|
|
41
|
+
onChange={onChange}
|
|
42
|
+
onChangeEnd={onChangeEnd}
|
|
43
|
+
className="react-colorful__last-control"
|
|
44
|
+
/>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
export const ColorPicker = <T extends AnyColor
|
|
49
|
+
export const ColorPicker = <T extends AnyColor>({
|
|
48
50
|
class: classValue,
|
|
49
51
|
className,
|
|
50
52
|
colorModel,
|
|
@@ -61,13 +63,15 @@ export const ColorPicker = <T extends AnyColor,>({
|
|
|
61
63
|
onChange,
|
|
62
64
|
onChangeEnd,
|
|
63
65
|
);
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
66
|
+
return (
|
|
67
|
+
<ColorPickerRoot
|
|
68
|
+
hostProps={rest}
|
|
69
|
+
nodeRef={nodeRef}
|
|
70
|
+
className={className}
|
|
71
|
+
classValue={classValue}
|
|
72
|
+
hsva={hsva}
|
|
73
|
+
onChange={updateHsva}
|
|
74
|
+
onChangeEnd={commitChange}
|
|
75
|
+
/>
|
|
76
|
+
);
|
|
73
77
|
};
|
|
@@ -15,27 +15,30 @@ interface Props {
|
|
|
15
15
|
|
|
16
16
|
const HueBase = ({ className, hue, onChange, onChangeEnd }: Props) => {
|
|
17
17
|
const handleMove = (interaction: Interaction) => onChange({ h: 360 * interaction.left });
|
|
18
|
-
const handleKey = (offset: Interaction) =>
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
const handleKey = (offset: Interaction) =>
|
|
19
|
+
onChange({
|
|
20
|
+
h: clamp(hue + offset.left * 360, 0, 360),
|
|
21
|
+
});
|
|
21
22
|
const nodeClassName = formatClassName(['react-colorful__hue', className]);
|
|
22
|
-
return
|
|
23
|
-
<
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
return (
|
|
24
|
+
<div class={nodeClassName}>
|
|
25
|
+
<Interactive
|
|
26
|
+
onMove={handleMove}
|
|
27
|
+
onKey={handleKey}
|
|
28
|
+
onEnd={onChangeEnd}
|
|
29
|
+
aria-label="Hue"
|
|
30
|
+
aria-valuenow={round(hue)}
|
|
31
|
+
aria-valuemax={360}
|
|
32
|
+
aria-valuemin={0}
|
|
33
|
+
>
|
|
34
|
+
<Pointer
|
|
35
|
+
className="react-colorful__hue-pointer"
|
|
36
|
+
left={hue / 360}
|
|
37
|
+
color={hsvaToHslString({ h: hue, s: 100, v: 100, a: 1 })}
|
|
38
|
+
/>
|
|
39
|
+
</Interactive>
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
39
42
|
};
|
|
40
43
|
|
|
41
44
|
export const Hue = memo(HueBase);
|
|
@@ -18,7 +18,7 @@ const getTouchPoint = (touches: TouchList, touchId: null | number): Touch => {
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
const getParentWindow = (node?: HTMLDivElement | null): Window =>
|
|
21
|
-
node && node.ownerDocument.defaultView || self;
|
|
21
|
+
(node && node.ownerDocument.defaultView) || self;
|
|
22
22
|
|
|
23
23
|
const getRelativePosition = (
|
|
24
24
|
node: HTMLDivElement,
|
|
@@ -26,8 +26,7 @@ const getRelativePosition = (
|
|
|
26
26
|
touchId: null | number,
|
|
27
27
|
): Interaction => {
|
|
28
28
|
const rect = node.getBoundingClientRect();
|
|
29
|
-
const pointer =
|
|
30
|
-
isTouch(event) ? getTouchPoint(event.touches, touchId) : event;
|
|
29
|
+
const pointer = isTouch(event) ? getTouchPoint(event.touches, touchId) : event;
|
|
31
30
|
return {
|
|
32
31
|
left: clamp((pointer.pageX - (rect.left + getParentWindow(node).pageXOffset)) / rect.width),
|
|
33
32
|
top: clamp((pointer.pageY - (rect.top + getParentWindow(node).pageYOffset)) / rect.height),
|
|
@@ -124,16 +123,8 @@ const InteractiveBase = ({
|
|
|
124
123
|
if (keyCode < 37 || keyCode > 40) return;
|
|
125
124
|
event.preventDefault();
|
|
126
125
|
onKeyCallback({
|
|
127
|
-
left: keyCode === 39
|
|
128
|
-
|
|
129
|
-
: keyCode === 37
|
|
130
|
-
? -0.05
|
|
131
|
-
: 0,
|
|
132
|
-
top: keyCode === 40
|
|
133
|
-
? 0.05
|
|
134
|
-
: keyCode === 38
|
|
135
|
-
? -0.05
|
|
136
|
-
: 0,
|
|
126
|
+
left: keyCode === 39 ? 0.05 : keyCode === 37 ? -0.05 : 0,
|
|
127
|
+
top: keyCode === 40 ? 0.05 : keyCode === 38 ? -0.05 : 0,
|
|
137
128
|
});
|
|
138
129
|
};
|
|
139
130
|
|
|
@@ -147,21 +138,25 @@ const InteractiveBase = ({
|
|
|
147
138
|
|
|
148
139
|
useEffect(() => toggleDocumentEvents, [toggleDocumentEvents]);
|
|
149
140
|
|
|
150
|
-
return
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
141
|
+
return (
|
|
142
|
+
<div
|
|
143
|
+
aria-label={ariaLabel}
|
|
144
|
+
aria-valuetext={ariaValueText}
|
|
145
|
+
aria-valuenow={ariaValueNow}
|
|
146
|
+
aria-valuemax={ariaValueMax}
|
|
147
|
+
aria-valuemin={ariaValueMin}
|
|
148
|
+
onTouchStart={handleMoveStart}
|
|
149
|
+
onMouseDown={handleMoveStart}
|
|
150
|
+
class="react-colorful__interactive"
|
|
151
|
+
ref={container}
|
|
152
|
+
onKeyDown={handleKeyDown}
|
|
153
|
+
onKeyUp={handleKeyUp}
|
|
154
|
+
tabIndex={0}
|
|
155
|
+
role="slider"
|
|
156
|
+
>
|
|
157
|
+
{children}
|
|
158
|
+
</div>
|
|
159
|
+
);
|
|
165
160
|
};
|
|
166
161
|
|
|
167
162
|
export const Interactive = memo(InteractiveBase);
|
|
@@ -10,7 +10,9 @@ interface Props {
|
|
|
10
10
|
export const Pointer = ({ className, color, left, top = 0.5 }: Props) => {
|
|
11
11
|
const nodeClassName = formatClassName(['react-colorful__pointer', className]);
|
|
12
12
|
const style = { top: `${top * 100}%`, left: `${left * 100}%` };
|
|
13
|
-
return
|
|
14
|
-
<div class=
|
|
15
|
-
|
|
13
|
+
return (
|
|
14
|
+
<div class={nodeClassName} style={style}>
|
|
15
|
+
<div class="react-colorful__pointer-fill" style={{ backgroundColor: color }} />
|
|
16
|
+
</div>
|
|
17
|
+
);
|
|
16
18
|
};
|
|
@@ -25,22 +25,24 @@ const SaturationBase = ({ hsva, onChange, onChangeEnd }: Props) => {
|
|
|
25
25
|
const containerStyle = {
|
|
26
26
|
backgroundColor: hsvaToHslString({ h: hsva.h, s: 100, v: 100, a: 1 }),
|
|
27
27
|
};
|
|
28
|
-
return
|
|
29
|
-
<
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
28
|
+
return (
|
|
29
|
+
<div class="react-colorful__saturation" style={containerStyle}>
|
|
30
|
+
<Interactive
|
|
31
|
+
onMove={handleMove}
|
|
32
|
+
onKey={handleKey}
|
|
33
|
+
onEnd={onChangeEnd}
|
|
34
|
+
aria-label="Color"
|
|
35
|
+
aria-valuetext={`Saturation ${round(hsva.s)}%, Brightness ${round(hsva.v)}%`}
|
|
36
|
+
>
|
|
37
|
+
<Pointer
|
|
38
|
+
className="react-colorful__saturation-pointer"
|
|
39
|
+
top={1 - hsva.v / 100}
|
|
40
|
+
left={hsva.s / 100}
|
|
41
|
+
color={hsvaToHslString(hsva)}
|
|
42
|
+
/>
|
|
43
|
+
</Interactive>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
44
46
|
};
|
|
45
47
|
|
|
46
48
|
export const Saturation = memo(SaturationBase);
|
|
@@ -9,10 +9,8 @@ export function useColorManipulation<T extends AnyColor>(
|
|
|
9
9
|
onChange?: (color: T) => void,
|
|
10
10
|
onChangeEnd?: (color: T) => void,
|
|
11
11
|
): [HsvaColor, (color: Partial<HsvaColor>) => void, () => void] {
|
|
12
|
-
const resolvedOnChange =
|
|
13
|
-
|
|
14
|
-
const resolvedOnChangeEnd =
|
|
15
|
-
typeof onChangeEnd === 'symbol' ? undefined : onChangeEnd;
|
|
12
|
+
const resolvedOnChange = typeof onChange === 'symbol' ? undefined : onChange;
|
|
13
|
+
const resolvedOnChangeEnd = typeof onChangeEnd === 'symbol' ? undefined : onChangeEnd;
|
|
16
14
|
const onChangeCallback = useEventCallback<T>(resolvedOnChange);
|
|
17
15
|
const onChangeEndCallback = useEventCallback<T>(resolvedOnChangeEnd);
|
|
18
16
|
const [hsva, updateHsva] = useState<HsvaColor>(() => colorModel.toHsva(color));
|
|
@@ -32,7 +30,7 @@ export function useColorManipulation<T extends AnyColor>(
|
|
|
32
30
|
let newColor: T;
|
|
33
31
|
if (
|
|
34
32
|
!equalColorObjects(hsva, cache.current.hsva) &&
|
|
35
|
-
|
|
33
|
+
!colorModel.equal((newColor = colorModel.fromHsva(hsva)), cache.current.color)
|
|
36
34
|
) {
|
|
37
35
|
cache.current = { hsva, color: newColor };
|
|
38
36
|
onChangeCallback(newColor);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { useRef } from 'octane';
|
|
2
2
|
|
|
3
3
|
export function useEventCallback<T>(handler?: (value: T) => void): (value: T) => void {
|
|
4
|
-
const resolvedHandler =
|
|
5
|
-
typeof handler === 'symbol' ? undefined : handler;
|
|
4
|
+
const resolvedHandler = typeof handler === 'symbol' ? undefined : handler;
|
|
6
5
|
const callbackRef = useRef(resolvedHandler);
|
|
7
6
|
const fn = useRef(function (value: T) {
|
|
8
7
|
callbackRef.current?.(value);
|
|
@@ -11,13 +11,11 @@ export const useStyleSheet = (nodeRef: { current: HTMLDivElement | null }): void
|
|
|
11
11
|
const node = nodeRef.current;
|
|
12
12
|
if (typeof document === 'undefined' || !node) return;
|
|
13
13
|
|
|
14
|
-
const raw =
|
|
15
|
-
node.getRootNode ? node.getRootNode() : node.ownerDocument;
|
|
14
|
+
const raw = node.getRootNode ? node.getRootNode() : node.ownerDocument;
|
|
16
15
|
const root = (raw && ('head' in raw || 'host' in raw) ? raw : node.ownerDocument) as Root;
|
|
17
16
|
if (styleElementMap.has(root)) return;
|
|
18
17
|
|
|
19
|
-
const target =
|
|
20
|
-
'head' in root ? root.head : root;
|
|
18
|
+
const target = 'head' in root ? root.head : root;
|
|
21
19
|
const styleElement = (target.ownerDocument || document).createElement('style');
|
|
22
20
|
styleElement.innerHTML = styles;
|
|
23
21
|
const nonce = getNonce();
|