UNPKG

wix-style-react

Version:
125 lines (106 loc) 4.83 kB
import _extends from "@babel/runtime/helpers/extends"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } import React from 'react'; import PropTypes from 'prop-types'; import Input from '../Input'; import { classes } from './ColorPickerConverter.st.css'; import ColorPickerConverterViewer from './ColorPickerConverterViewer'; import { safeColor, getRgbOrEmpty } from './utils'; var ColorPickerConverterRGB = /*#__PURE__*/function (_React$PureComponent) { _inherits(ColorPickerConverterRGB, _React$PureComponent); var _super = _createSuper(ColorPickerConverterRGB); function ColorPickerConverterRGB() { var _this; _classCallCheck(this, ColorPickerConverterRGB); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _super.call.apply(_super, [this].concat(args)); _defineProperty(_assertThisInitialized(_this), "state", getRgbOrEmpty(_this.props.current)); return _this; } _createClass(ColorPickerConverterRGB, [{ key: "isInputsEmpty", value: function isInputsEmpty() { var _this$state = this.state, r = _this$state.r, g = _this$state.g, b = _this$state.b; return [r, g, b].every(function (value) { return value === ''; }); } }, { key: "render", value: function render() { var _this2 = this; var dataHook = this.props.dataHook; return /*#__PURE__*/React.createElement("div", { className: classes.root, "data-hook": dataHook }, /*#__PURE__*/React.createElement("div", { className: classes.distribute }, /*#__PURE__*/React.createElement(Input, { size: "small", value: this.state.r, onChange: function onChange(e) { return _this2.change('r', e); }, placeholder: "R", className: classes.distributedItem }), /*#__PURE__*/React.createElement(Input, { size: "small", value: this.state.g, onChange: function onChange(e) { return _this2.change('g', e); }, placeholder: "G", className: classes.distributedItem }), /*#__PURE__*/React.createElement(Input, { size: "small", value: this.state.b, onChange: function onChange(e) { return _this2.change('b', e); }, placeholder: "B", className: classes.distributedItem })), /*#__PURE__*/React.createElement(ColorPickerConverterViewer, _extends({}, this.props, { color: this.props.current }))); } }, { key: "UNSAFE_componentWillReceiveProps", value: function UNSAFE_componentWillReceiveProps(props) { this.setState(getRgbOrEmpty(props.current)); } }, { key: "change", value: function change(part, _ref) { var _this3 = this; var value = _ref.target.value; this.setState(_defineProperty({}, part, value), function () { var isMissingData = _this3.state.r === '' || _this3.state.g === '' || _this3.state.b === ''; var _color = safeColor(isMissingData && _this3.props.allowEmpty ? '' : _this3.state, _this3.props.allowEmpty); if (!isMissingData || _this3.isInputsEmpty()) { _this3.props.onChange(_color); } }); } }]); return ColorPickerConverterRGB; }(React.PureComponent); _defineProperty(ColorPickerConverterRGB, "propTypes", { dataHook: PropTypes.string, current: PropTypes.object.isRequired, onChange: PropTypes.func.isRequired, onAdd: PropTypes.func }); export { ColorPickerConverterRGB as default };