-
Notifications
You must be signed in to change notification settings - Fork 4
/
Saturation.tsx
56 lines (49 loc) 路 1.46 KB
/
Saturation.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import React, { useCallback } from 'react'
import { HslColor, HsvColor } from '../../types'
import usePosition, { Position } from '../../hooks/usePosition'
import * as styles from './Saturation.style'
export type SaturationProps = {
hsl: HslColor
onChange?: (color: HsvColor) => void
}
const Saturation = ({ hsl, onChange }: SaturationProps) => {
const handleMove = useCallback(
({ left, top }: Position) =>
onChange &&
onChange({
...hsl,
s: left,
v: 1 - top,
}),
[onChange]
)
const { ref, handleStart } = usePosition({
onMove: handleMove,
})
return (
<div
style={styles.color}
ref={ref}
onTouchStart={handleStart}
onMouseDown={handleStart}
>
<style>{`
.rpc-saturation-white {
background: -webkit-linear-gradient(to right, #fff, rgba(255,255,255,0));
background: linear-gradient(to right, #fff, rgba(255,255,255,0));
}
.rpc-saturation-black {
background: -webkit-linear-gradient(to top, #000, rgba(0,0,0,0));
background: linear-gradient(to top, #000, rgba(0,0,0,0));
}
`}</style>
<div style={styles.gradient} className="rpc-saturation-white">
<div style={styles.gradient} className="rpc-saturation-black" />
<div style={styles.pointer}>
<div style={styles.circle} />
</div>
</div>
</div>
)
}
export default React.memo(Saturation) as typeof Saturation