react-color
Version:
A Collection of Color Pickers from Sketch, Photoshop, Chrome & more
178 lines (162 loc) • 6.65 kB
JavaScript
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
import React from 'react';
import PropTypes from 'prop-types';
import reactCSS from 'reactcss';
import merge from 'lodash-es/merge';
import { ColorWrap, Saturation, Hue } from '../common';
import PhotoshopFields from './PhotoshopFields';
import PhotoshopPointerCircle from './PhotoshopPointerCircle';
import PhotoshopPointer from './PhotoshopPointer';
import PhotoshopButton from './PhotoshopButton';
import PhotoshopPreviews from './PhotoshopPreviews';
export var Photoshop = function (_React$Component) {
_inherits(Photoshop, _React$Component);
function Photoshop(props) {
_classCallCheck(this, Photoshop);
var _this = _possibleConstructorReturn(this, (Photoshop.__proto__ || Object.getPrototypeOf(Photoshop)).call(this));
_this.state = {
currentColor: props.hex
};
return _this;
}
_createClass(Photoshop, [{
key: 'render',
value: function render() {
var _props = this.props,
_props$styles = _props.styles,
passedStyles = _props$styles === undefined ? {} : _props$styles,
_props$className = _props.className,
className = _props$className === undefined ? '' : _props$className;
var styles = reactCSS(merge({
'default': {
picker: {
background: '#DCDCDC',
borderRadius: '4px',
boxShadow: '0 0 0 1px rgba(0,0,0,.25), 0 8px 16px rgba(0,0,0,.15)',
boxSizing: 'initial',
width: '513px'
},
head: {
backgroundImage: 'linear-gradient(-180deg, #F0F0F0 0%, #D4D4D4 100%)',
borderBottom: '1px solid #B1B1B1',
boxShadow: 'inset 0 1px 0 0 rgba(255,255,255,.2), inset 0 -1px 0 0 rgba(0,0,0,.02)',
height: '23px',
lineHeight: '24px',
borderRadius: '4px 4px 0 0',
fontSize: '13px',
color: '#4D4D4D',
textAlign: 'center'
},
body: {
padding: '15px 15px 0',
display: 'flex'
},
saturation: {
width: '256px',
height: '256px',
position: 'relative',
border: '2px solid #B3B3B3',
borderBottom: '2px solid #F0F0F0',
overflow: 'hidden'
},
hue: {
position: 'relative',
height: '256px',
width: '19px',
marginLeft: '10px',
border: '2px solid #B3B3B3',
borderBottom: '2px solid #F0F0F0'
},
controls: {
width: '180px',
marginLeft: '10px'
},
top: {
display: 'flex'
},
previews: {
width: '60px'
},
actions: {
flex: '1',
marginLeft: '20px'
}
}
}, passedStyles));
return React.createElement(
'div',
{ style: styles.picker, className: 'photoshop-picker ' + className },
React.createElement(
'div',
{ style: styles.head },
this.props.header
),
React.createElement(
'div',
{ style: styles.body, className: 'flexbox-fix' },
React.createElement(
'div',
{ style: styles.saturation },
React.createElement(Saturation, {
hsl: this.props.hsl,
hsv: this.props.hsv,
pointer: PhotoshopPointerCircle,
onChange: this.props.onChange
})
),
React.createElement(
'div',
{ style: styles.hue },
React.createElement(Hue, {
direction: 'vertical',
hsl: this.props.hsl,
pointer: PhotoshopPointer,
onChange: this.props.onChange
})
),
React.createElement(
'div',
{ style: styles.controls },
React.createElement(
'div',
{ style: styles.top, className: 'flexbox-fix' },
React.createElement(
'div',
{ style: styles.previews },
React.createElement(PhotoshopPreviews, {
rgb: this.props.rgb,
currentColor: this.state.currentColor
})
),
React.createElement(
'div',
{ style: styles.actions },
React.createElement(PhotoshopButton, { label: 'OK', onClick: this.props.onAccept, active: true }),
React.createElement(PhotoshopButton, { label: 'Cancel', onClick: this.props.onCancel }),
React.createElement(PhotoshopFields, {
onChange: this.props.onChange,
rgb: this.props.rgb,
hsv: this.props.hsv,
hex: this.props.hex
})
)
)
)
)
);
}
}]);
return Photoshop;
}(React.Component);
Photoshop.propTypes = {
header: PropTypes.string,
styles: PropTypes.object
};
Photoshop.defaultProps = {
header: 'Color Picker',
styles: {}
};
export default ColorWrap(Photoshop);