wix-style-react
Version:
wix-style-react
105 lines (86 loc) • 4.23 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; }; }();
var _class, _temp;
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return 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; }
import React from 'react';
import color from 'color';
import { object, func } from 'prop-types';
import mapValue from '../utils/operators/mapValue';
import WixComponent from '../BaseComponents/WixComponent';
import Input from '../Input';
import css from './ColorPickerConverter.scss';
var ColorPickerConverterRGB = (_temp = _class = function (_WixComponent) {
_inherits(ColorPickerConverterRGB, _WixComponent);
function ColorPickerConverterRGB(props) {
_classCallCheck(this, ColorPickerConverterRGB);
var _this = _possibleConstructorReturn(this, (ColorPickerConverterRGB.__proto__ || Object.getPrototypeOf(ColorPickerConverterRGB)).call(this, props));
_this.state = mapValue(props.current.rgb().object(), Math.round);
return _this;
}
_createClass(ColorPickerConverterRGB, [{
key: 'render',
value: function render() {
var _this2 = this;
return React.createElement(
'div',
{ className: css.root },
React.createElement(
'div',
{ className: css.distribute },
React.createElement(Input, {
size: 'small',
value: this.state.r,
onChange: function onChange(e) {
return _this2.change('r', e);
}
}),
React.createElement(Input, {
size: 'small',
value: this.state.g,
onChange: function onChange(e) {
return _this2.change('g', e);
}
}),
React.createElement(Input, {
size: 'small',
value: this.state.b,
onChange: function onChange(e) {
return _this2.change('b', e);
}
})
)
);
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(props) {
this.setState(mapValue(props.current.rgb().object(), Math.round));
}
}, {
key: 'change',
value: function change(part, _ref) {
var _this3 = this;
var value = _ref.target.value;
this.setState(_defineProperty({}, part, value), function () {
var _color = safeColor(_this3.state);
if (_color) {
_this3.props.onChange(_color);
}
});
}
}]);
return ColorPickerConverterRGB;
}(WixComponent), _class.propTypes = {
current: object.isRequired,
onChange: func.isRequired
}, _temp);
export { ColorPickerConverterRGB as default };
function safeColor(input) {
try {
return color(input);
} catch (error) {
return null;
}
}