mirror of https://github.com/sgoudham/carbon.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.0 KiB
JavaScript
80 lines
2.0 KiB
JavaScript
8 years ago
|
import React from 'react'
|
||
8 years ago
|
import enhanceWithClickOutside from 'react-click-outside'
|
||
8 years ago
|
import { BlockPicker } from 'react-color'
|
||
|
|
||
8 years ago
|
class ColorPicker extends React.Component {
|
||
8 years ago
|
constructor() {
|
||
|
super()
|
||
8 years ago
|
this.state = { isVisible: false }
|
||
8 years ago
|
this.toggle = this.toggle.bind(this)
|
||
|
this.handlePickColor = this.handlePickColor.bind(this)
|
||
|
}
|
||
|
|
||
|
toggle() {
|
||
|
this.setState({ isVisible: !this.state.isVisible })
|
||
|
}
|
||
|
|
||
8 years ago
|
handleClickOutside() {
|
||
8 years ago
|
this.setState({ isVisible: false })
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
handlePickColor(color) {
|
||
8 years ago
|
this.setState({ isVisible: false })
|
||
8 years ago
|
this.props.onChange(color.hex)
|
||
8 years ago
|
}
|
||
|
|
||
|
render() {
|
||
|
return (
|
||
|
<div className="colorpicker-container">
|
||
|
<div className="colorpicker-display">
|
||
|
<div className="colorpicker-label">
|
||
|
<span>BG</span>
|
||
|
</div>
|
||
8 years ago
|
<div className="bg-color" style={{background: this.props.bg}} onClick={this.toggle}></div>
|
||
8 years ago
|
</div>
|
||
|
<div className="colorpicker-picker" hidden={!this.state.isVisible}>
|
||
8 years ago
|
<BlockPicker color={this.props.bg} onChangeComplete={this.handlePickColor} />
|
||
8 years ago
|
</div>
|
||
|
<style jsx>{`
|
||
|
.colorpicker-container {
|
||
8 years ago
|
height: 100%;
|
||
8 years ago
|
}
|
||
|
|
||
|
.colorpicker-display {
|
||
|
display: flex;
|
||
|
height: 100%;
|
||
|
width: 72px;
|
||
8 years ago
|
border: 0.5px solid #000;
|
||
8 years ago
|
border-radius: 3px;
|
||
|
}
|
||
|
|
||
|
.colorpicker-label {
|
||
|
display: flex;
|
||
|
align-items: center;
|
||
|
justify-content: center;
|
||
|
user-select: none;
|
||
|
cursor: default;
|
||
|
height: 100%;
|
||
|
width: 36px;
|
||
|
}
|
||
|
|
||
|
.bg-color {
|
||
|
cursor: pointer;
|
||
|
height: 100%;
|
||
|
width: 36px;
|
||
|
border-radius: 0px 2px 2px 0px;
|
||
|
}
|
||
|
|
||
|
.colorpicker-picker {
|
||
8 years ago
|
position: absolute;
|
||
8 years ago
|
margin-left: -32px;
|
||
|
margin-top: 9px;
|
||
|
}
|
||
|
`}</style>
|
||
|
</div>
|
||
|
)
|
||
|
}
|
||
|
}
|
||
8 years ago
|
|
||
|
export default enhanceWithClickOutside(ColorPicker)
|