Skip to content

Commit 4c2c38b

Browse files
committed
fix(Saturation): fix hsva props issue. #176
1 parent 22b3566 commit 4c2c38b

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

packages/color-saturation/src/index.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ const Saturation = React.forwardRef<HTMLDivElement, SaturationProps>((props, ref
2424
position: 'relative',
2525
};
2626

27-
const [interaction, setInteraction] = useState<Interaction>({ left: 0, top: 0, x: 0, y: 0, width: 0, height: 0 });
2827
const handleChange = (interaction: Interaction, event: MouseEvent | TouchEvent) => {
29-
setInteraction(interaction);
3028
onChange &&
3129
hsva &&
3230
onChange({
@@ -40,22 +38,16 @@ const Saturation = React.forwardRef<HTMLDivElement, SaturationProps>((props, ref
4038

4139
const pointerElement = useMemo(() => {
4240
if (!hsva) return null;
43-
var ponitX = `${clamp(interaction.x, 0, interaction.width)}px`;
44-
var ponitY = `${clamp(interaction.y, 0, interaction.height)}px`;
45-
if (interaction.width === 0 || interaction.height === 0) {
46-
ponitX = `${hsva.s}%`;
47-
ponitY = `${100 - hsva.v}%`;
48-
}
4941
const comProps = {
50-
top: ponitY,
51-
left: ponitX,
42+
top: `${100 - hsva.v}%`,
43+
left: `${hsva.s}%`,
5244
color: hsvaToHslaString(hsva),
5345
};
5446
if (pointer && typeof pointer === 'function') {
5547
return pointer({ prefixCls, ...comProps });
5648
}
5749
return <Pointer prefixCls={prefixCls} {...comProps} />;
58-
}, [hsva, interaction, pointer, prefixCls]);
50+
}, [hsva, pointer, prefixCls]);
5951

6052
return (
6153
<Interactive

packages/color-sketch/README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,28 @@ import React, { useState } from 'react';
2323
import Sketch from '@uiw/react-color-sketch';
2424

2525
function Demo() {
26-
const [hex, setHex] = useState("#fff");
26+
const [hsva, setHsva] = useState({ h: 214, s: 43, v: 90, a: 1 });
2727
const [disableAlpha, setDisableAlpha] = useState(false);
2828
return (
2929
<div>
30-
<Sketch
31-
style={{ marginLeft: 20 }}
32-
color={hex}
33-
disableAlpha={disableAlpha}
34-
onChange={(color) => {
35-
setHex(color.hex);
36-
}}
37-
/>
30+
<div style={{ display: 'flex' }}>
31+
<Sketch
32+
style={{ marginLeft: 20 }}
33+
color={hsva}
34+
disableAlpha={disableAlpha}
35+
onChange={(color) => {
36+
setHsva(color.hsva);
37+
}}
38+
/>
39+
<Sketch
40+
style={{ marginLeft: 20 }}
41+
color={hsva}
42+
disableAlpha={disableAlpha}
43+
onChange={(color) => {
44+
setHsva(color.hsva);
45+
}}
46+
/>
47+
</div>
3848
<button onClick={() => setDisableAlpha(!disableAlpha)}>
3949
disableAlpha={disableAlpha.toString()}
4050
</button>

0 commit comments

Comments
 (0)