UNPKG

wix-style-react

Version:
131 lines (112 loc) 4.97 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, getHsbOrEmpty } from './utils'; var ColorPickerConverterHsb = /*#__PURE__*/function (_React$PureComponent) { _inherits(ColorPickerConverterHsb, _React$PureComponent); var _super = _createSuper(ColorPickerConverterHsb); function ColorPickerConverterHsb() { var _this; _classCallCheck(this, ColorPickerConverterHsb); 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", getHsbOrEmpty(_this.props.current)); return _this; } _createClass(ColorPickerConverterHsb, [{ key: "isInputsEmpty", value: function isInputsEmpty() { var _this$state = this.state, h = _this$state.h, s = _this$state.s, l = _this$state.l; return [h, s, l].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.h, onChange: function onChange(e) { return _this2.change('h', e); }, placeholder: 'H', className: classes.distributedItem }), /*#__PURE__*/React.createElement(Input, { size: "small", value: this.state.s, onChange: function onChange(e) { return _this2.change('s', e); }, placeholder: 'S', className: classes.distributedItem }), /*#__PURE__*/React.createElement(Input, { size: "small", value: this.state.l, onChange: function onChange(e) { return _this2.change('l', 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(getHsbOrEmpty(props.current)); } }, { key: "change", value: function change(part, _ref) { var _this3 = this; var value = _ref.target.value; this.setState(_defineProperty({}, part, value), function () { var _this3$state = _this3.state, h = _this3$state.h, s = _this3$state.s, l = _this3$state.l; var isMissingData = [h, s, l].some(function (_value) { return _value === ''; }); var _color = safeColor(isMissingData && _this3.props.allowEmpty ? '' : _this3.state, _this3.props.allowEmpty); if (!isMissingData || _this3.isInputsEmpty()) { _this3.props.onChange(_color); } }); } }]); return ColorPickerConverterHsb; }(React.PureComponent); _defineProperty(ColorPickerConverterHsb, "propTypes", { dataHook: PropTypes.string, current: PropTypes.object.isRequired, onChange: PropTypes.func.isRequired, onAdd: PropTypes.func }); export { ColorPickerConverterHsb as default };