UNPKG

react-color

Version:

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

171 lines (154 loc) 4.73 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.Material = undefined; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _reactcss = require('reactcss'); var _reactcss2 = _interopRequireDefault(_reactcss); var _merge = require('lodash/merge'); var _merge2 = _interopRequireDefault(_merge); 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 Material = exports.Material = function Material(_ref) { var onChange = _ref.onChange, hex = _ref.hex, rgb = _ref.rgb, _ref$styles = _ref.styles, passedStyles = _ref$styles === undefined ? {} : _ref$styles, _ref$className = _ref.className, className = _ref$className === undefined ? '' : _ref$className; var styles = (0, _reactcss2.default)((0, _merge2.default)({ 'default': { material: { width: '98px', height: '98px', padding: '16px', fontFamily: 'Roboto' }, HEXwrap: { position: 'relative' }, HEXinput: { width: '100%', marginTop: '12px', fontSize: '15px', color: '#333', padding: '0px', border: '0px', borderBottom: '2px solid ' + hex, outline: 'none', height: '30px' }, HEXlabel: { position: 'absolute', top: '0px', left: '0px', fontSize: '11px', color: '#999999', textTransform: 'capitalize' }, Hex: { style: {} }, RGBwrap: { position: 'relative' }, RGBinput: { width: '100%', marginTop: '12px', fontSize: '15px', color: '#333', padding: '0px', border: '0px', borderBottom: '1px solid #eee', outline: 'none', height: '30px' }, RGBlabel: { position: 'absolute', top: '0px', left: '0px', fontSize: '11px', color: '#999999', textTransform: 'capitalize' }, split: { display: 'flex', marginRight: '-10px', paddingTop: '11px' }, third: { flex: '1', paddingRight: '10px' } } }, passedStyles)); var handleChange = function handleChange(data, e) { if (data.hex) { color.isValidHex(data.hex) && onChange({ hex: data.hex, 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); } }; return _react2.default.createElement( _common.Raised, { styles: passedStyles }, _react2.default.createElement( 'div', { style: styles.material, className: 'material-picker ' + className }, _react2.default.createElement(_common.EditableInput, { style: { wrap: styles.HEXwrap, input: styles.HEXinput, label: styles.HEXlabel }, label: 'hex', value: hex, onChange: handleChange }), _react2.default.createElement( 'div', { style: styles.split, className: 'flexbox-fix' }, _react2.default.createElement( 'div', { style: styles.third }, _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( 'div', { style: styles.third }, _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( 'div', { style: styles.third }, _react2.default.createElement(_common.EditableInput, { style: { wrap: styles.RGBwrap, input: styles.RGBinput, label: styles.RGBlabel }, label: 'b', value: rgb.b, onChange: handleChange }) ) ) ) ); }; exports.default = (0, _common.ColorWrap)(Material);