UNPKG

react-color

Version:

A Collection of Color Pickers from Sketch, Photoshop, Chrome & more

196 lines (181 loc) 5.48 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.PhotoshopPicker = undefined; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _reactcss = require('reactcss'); var _reactcss2 = _interopRequireDefault(_reactcss); var _color = require('../../helpers/color'); var color = _interopRequireWildcard(_color); var _common = require('../common'); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var PhotoshopPicker = exports.PhotoshopPicker = function PhotoshopPicker(_ref) { var onChange = _ref.onChange, rgb = _ref.rgb, hsv = _ref.hsv, hex = _ref.hex; var styles = (0, _reactcss2.default)({ 'default': { fields: { paddingTop: '5px', paddingBottom: '9px', width: '80px', position: 'relative' }, divider: { height: '5px' }, RGBwrap: { position: 'relative' }, RGBinput: { marginLeft: '40%', width: '40%', height: '18px', border: '1px solid #888888', boxShadow: 'inset 0 1px 1px rgba(0,0,0,.1), 0 1px 0 0 #ECECEC', marginBottom: '5px', fontSize: '13px', paddingLeft: '3px', marginRight: '10px' }, RGBlabel: { left: '0px', top: '0px', width: '34px', textTransform: 'uppercase', fontSize: '13px', height: '18px', lineHeight: '22px', position: 'absolute' }, HEXwrap: { position: 'relative' }, HEXinput: { marginLeft: '20%', width: '80%', height: '18px', border: '1px solid #888888', boxShadow: 'inset 0 1px 1px rgba(0,0,0,.1), 0 1px 0 0 #ECECEC', marginBottom: '6px', fontSize: '13px', paddingLeft: '3px' }, HEXlabel: { position: 'absolute', top: '0px', left: '0px', width: '14px', textTransform: 'uppercase', fontSize: '13px', height: '18px', lineHeight: '22px' }, fieldSymbols: { position: 'absolute', top: '5px', right: '-7px', fontSize: '13px' }, symbol: { height: '20px', lineHeight: '22px', paddingBottom: '7px' } } }); var handleChange = function handleChange(data, e) { if (data['#']) { color.isValidHex(data['#']) && onChange({ hex: data['#'], source: 'hex' }, e); } else if (data.r || data.g || data.b) { onChange({ r: data.r || rgb.r, g: data.g || rgb.g, b: data.b || rgb.b, source: 'rgb' }, e); } else if (data.h || data.s || data.v) { onChange({ h: data.h || hsv.h, s: data.s || hsv.s, v: data.v || hsv.v, source: 'hsv' }, e); } }; return _react2.default.createElement( 'div', { style: styles.fields }, _react2.default.createElement(_common.EditableInput, { style: { wrap: styles.RGBwrap, input: styles.RGBinput, label: styles.RGBlabel }, label: 'h', value: Math.round(hsv.h), onChange: handleChange }), _react2.default.createElement(_common.EditableInput, { style: { wrap: styles.RGBwrap, input: styles.RGBinput, label: styles.RGBlabel }, label: 's', value: Math.round(hsv.s * 100), onChange: handleChange }), _react2.default.createElement(_common.EditableInput, { style: { wrap: styles.RGBwrap, input: styles.RGBinput, label: styles.RGBlabel }, label: 'v', value: Math.round(hsv.v * 100), onChange: handleChange }), _react2.default.createElement('div', { style: styles.divider }), _react2.default.createElement(_common.EditableInput, { style: { wrap: styles.RGBwrap, input: styles.RGBinput, label: styles.RGBlabel }, label: 'r', value: rgb.r, onChange: handleChange }), _react2.default.createElement(_common.EditableInput, { style: { wrap: styles.RGBwrap, input: styles.RGBinput, label: styles.RGBlabel }, label: 'g', value: rgb.g, onChange: handleChange }), _react2.default.createElement(_common.EditableInput, { style: { wrap: styles.RGBwrap, input: styles.RGBinput, label: styles.RGBlabel }, label: 'b', value: rgb.b, onChange: handleChange }), _react2.default.createElement('div', { style: styles.divider }), _react2.default.createElement(_common.EditableInput, { style: { wrap: styles.HEXwrap, input: styles.HEXinput, label: styles.HEXlabel }, label: '#', value: hex.replace('#', ''), onChange: handleChange }), _react2.default.createElement( 'div', { style: styles.fieldSymbols }, _react2.default.createElement( 'div', { style: styles.symbol }, '\xB0' ), _react2.default.createElement( 'div', { style: styles.symbol }, '%' ), _react2.default.createElement( 'div', { style: styles.symbol }, '%' ) ) ); }; exports.default = PhotoshopPicker;