-
Notifications
You must be signed in to change notification settings - Fork 1
/
ColorPickerSystem.jsx
67 lines (56 loc) · 1.59 KB
/
ColorPickerSystem.jsx
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
57
58
59
60
61
62
63
64
65
66
67
import React, { useState } from 'react';
import Button from '@material-ui/core/Button';
import { SketchPicker } from 'react-color';
const ColorPickerPopover = (props) => {
const {
color,
handleUpdateColor,
colorPickerPopoverState,
setColorPickerPopoverState,
} = props;
const colorPickerPopoverStyle = {
position: 'absolute',
zIndex: '100',
};
const colorPickerCoverStyle = {
position: 'fixed',
top: '0px',
right: '0px',
bottom: '0px',
left: '0px',
};
const handleCloseColorPickerPopover = () => {
setColorPickerPopoverState(false);
};
if (colorPickerPopoverState)
return (
<div style={colorPickerPopoverStyle}>
<div style={colorPickerCoverStyle} onClick={handleCloseColorPickerPopover} />
<SketchPicker color={color} onChangeComplete={(e) => handleUpdateColor(e)} />
</div>
);
return <div />;
};
const ColorPickerSystem = (props) => {
const { color, handleUpdateColor } = props;
const [colorPickerPopoverState, setColorPickerPopoverState] = useState(false);
const handleClickColorPicker = () => {
setColorPickerPopoverState((oldState) => !oldState);
};
return (
<>
<Button
variant="contained"
style={{ height: '100%', backgroundColor: color }}
onClick={handleClickColorPicker}
/>
<ColorPickerPopover
color={color}
colorPickerPopoverState={colorPickerPopoverState}
setColorPickerPopoverState={setColorPickerPopoverState}
handleUpdateColor={handleUpdateColor}
/>
</>
);
};
export default ColorPickerSystem;