forked from carbon-app/carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorPicker.js
53 lines (47 loc) · 1.48 KB
/
ColorPicker.js
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
import React from 'react'
import SketchPicker from 'react-color/lib/Sketch'
import { COLORS } from '../lib/constants'
import { stringifyColor } from '../lib/util'
const pickerStyle = {
backgroundColor: COLORS.BLACK,
padding: '8px 8px 0',
margin: '0 auto 1px',
}
export default function ColorPicker(props) {
const [color, setColor] = React.useState(props.color)
const { onChange = () => {}, presets, style, disableAlpha } = props
return (
<React.Fragment>
<SketchPicker
styles={{ picker: style || pickerStyle }}
onChange={setColor}
color={typeof color === 'string' ? color : stringifyColor(color)}
onChangeComplete={onChange}
presetColors={presets}
disableAlpha={disableAlpha}
/>
<style jsx>
{`
/* react-color overrides */
:global(.sketch-picker > div:nth-child(3) > div > div > input) {
width: 100% !important;
box-shadow: none;
outline: none;
border-radius: 2px;
background: ${COLORS.DARK_GRAY};
color: #fff !important;
}
:global(.sketch-picker
> div:nth-child(2)
> div:nth-child(1)
> div:nth-child(2), .sketch-picker > div:nth-child(2) > div:nth-child(2)) {
background: #fff;
}
:global(.sketch-picker label) {
color: ${COLORS.SECONDARY} !important;
}
`}
</style>
</React.Fragment>
)
}