2016-09-12 19:47:28 +02:00
|
|
|
import React from 'react'
|
2016-09-13 20:30:03 +02:00
|
|
|
import inputStyle from './input.js'
|
2016-12-17 21:52:27 +01:00
|
|
|
import { getColor } from 'react-colorpickr/dist/colorfunc'
|
2016-12-17 22:08:24 +01:00
|
|
|
import ChromePicker from '../chromepicker.jsx'
|
2016-12-17 21:25:00 +01:00
|
|
|
|
|
|
|
function formatColor(color) {
|
2016-12-17 21:52:27 +01:00
|
|
|
const rgb = color.rgb
|
|
|
|
return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${rgb.a})`
|
2016-12-17 21:25:00 +01:00
|
|
|
}
|
2016-09-12 19:47:28 +02:00
|
|
|
|
|
|
|
/*** Number fields with support for min, max and units and documentation*/
|
|
|
|
class ColorField extends React.Component {
|
|
|
|
static propTypes = {
|
2016-09-12 20:10:49 +02:00
|
|
|
onChange: React.PropTypes.func.isRequired,
|
2016-12-17 21:25:00 +01:00
|
|
|
name: React.PropTypes.string.isRequired,
|
2016-09-13 20:30:03 +02:00
|
|
|
value: React.PropTypes.string,
|
2016-09-12 19:47:28 +02:00
|
|
|
default: React.PropTypes.number,
|
|
|
|
doc: React.PropTypes.string,
|
|
|
|
}
|
|
|
|
|
2016-12-17 21:25:00 +01:00
|
|
|
render() {
|
|
|
|
return <div style={{...inputStyle.property, position: 'relative'}}>
|
|
|
|
<div style={{
|
|
|
|
position: 'absolute',
|
|
|
|
left: 200
|
|
|
|
}}>
|
2016-12-17 21:52:27 +01:00
|
|
|
<ChromePicker
|
|
|
|
color={getColor(this.props.value)}
|
2016-12-17 21:25:00 +01:00
|
|
|
onChange={c => this.props.onChange(formatColor(c))}
|
|
|
|
/>
|
|
|
|
</div>
|
2016-09-12 20:29:53 +02:00
|
|
|
|
2016-12-17 21:25:00 +01:00
|
|
|
<label style={inputStyle.label}>{this.props.name}</label>
|
|
|
|
<input
|
|
|
|
style={inputStyle.input}
|
|
|
|
name={this.props.name}
|
|
|
|
placeholder={this.props.default}
|
|
|
|
value={this.props.value ? this.props.value : ""}
|
|
|
|
onChange={(e) => this.props.onChange(e.target.value)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
}
|
2016-09-12 19:47:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default ColorField
|