react-color
Version:
A Collection of Color Pickers from Sketch, Photoshop, Chrome & more
213 lines (177 loc) • 7.75 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Photoshop = undefined;
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; }; }();
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _reactcss = require('reactcss');
var _reactcss2 = _interopRequireDefault(_reactcss);
var _merge = require('lodash/merge');
var _merge2 = _interopRequireDefault(_merge);
var _common = require('../common');
var _PhotoshopFields = require('./PhotoshopFields');
var _PhotoshopFields2 = _interopRequireDefault(_PhotoshopFields);
var _PhotoshopPointerCircle = require('./PhotoshopPointerCircle');
var _PhotoshopPointerCircle2 = _interopRequireDefault(_PhotoshopPointerCircle);
var _PhotoshopPointer = require('./PhotoshopPointer');
var _PhotoshopPointer2 = _interopRequireDefault(_PhotoshopPointer);
var _PhotoshopButton = require('./PhotoshopButton');
var _PhotoshopButton2 = _interopRequireDefault(_PhotoshopButton);
var _PhotoshopPreviews = require('./PhotoshopPreviews');
var _PhotoshopPreviews2 = _interopRequireDefault(_PhotoshopPreviews);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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; }
var Photoshop = exports.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 = (0, _reactcss2.default)((0, _merge2.default)({
'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 _react2.default.createElement(
'div',
{ style: styles.picker, className: 'photoshop-picker ' + className },
_react2.default.createElement(
'div',
{ style: styles.head },
this.props.header
),
_react2.default.createElement(
'div',
{ style: styles.body, className: 'flexbox-fix' },
_react2.default.createElement(
'div',
{ style: styles.saturation },
_react2.default.createElement(_common.Saturation, {
hsl: this.props.hsl,
hsv: this.props.hsv,
pointer: _PhotoshopPointerCircle2.default,
onChange: this.props.onChange
})
),
_react2.default.createElement(
'div',
{ style: styles.hue },
_react2.default.createElement(_common.Hue, {
direction: 'vertical',
hsl: this.props.hsl,
pointer: _PhotoshopPointer2.default,
onChange: this.props.onChange
})
),
_react2.default.createElement(
'div',
{ style: styles.controls },
_react2.default.createElement(
'div',
{ style: styles.top, className: 'flexbox-fix' },
_react2.default.createElement(
'div',
{ style: styles.previews },
_react2.default.createElement(_PhotoshopPreviews2.default, {
rgb: this.props.rgb,
currentColor: this.state.currentColor
})
),
_react2.default.createElement(
'div',
{ style: styles.actions },
_react2.default.createElement(_PhotoshopButton2.default, { label: 'OK', onClick: this.props.onAccept, active: true }),
_react2.default.createElement(_PhotoshopButton2.default, { label: 'Cancel', onClick: this.props.onCancel }),
_react2.default.createElement(_PhotoshopFields2.default, {
onChange: this.props.onChange,
rgb: this.props.rgb,
hsv: this.props.hsv,
hex: this.props.hex
})
)
)
)
)
);
}
}]);
return Photoshop;
}(_react2.default.Component);
Photoshop.propTypes = {
header: _propTypes2.default.string,
styles: _propTypes2.default.object
};
Photoshop.defaultProps = {
header: 'Color Picker',
styles: {}
};
exports.default = (0, _common.ColorWrap)(Photoshop);