wix-style-react
Version:
152 lines (134 loc) • 5.62 kB
JavaScript
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 Tabs from '../Tabs';
import ColorPickerConverterHex from './ColorPickerConverterHex';
import ColorPickerConverterRGB from './ColorPickerConverterRGB';
import ColorPickerConverterHsb from './ColorPickerConverterHsb';
import { WixStyleReactContext } from '../WixStyleReactProvider/context';
var HEX = 'HEX';
var RGB = 'RGB';
var HSB = 'HSB';
var tabs = [{
id: HEX,
title: HEX
}, {
id: RGB,
title: RGB
}, {
id: HSB,
title: HSB
}];
var ColorPickerConverter = /*#__PURE__*/function (_React$PureComponent) {
_inherits(ColorPickerConverter, _React$PureComponent);
var _super = _createSuper(ColorPickerConverter);
function ColorPickerConverter(props) {
var _this;
_classCallCheck(this, ColorPickerConverter);
_this = _super.call(this, props);
_defineProperty(_assertThisInitialized(_this), "state", {
activeTab: HEX
});
_this.changeTab = _this.changeTab.bind(_assertThisInitialized(_this));
return _this;
}
_createClass(ColorPickerConverter, [{
key: "render",
value: function render() {
var _this2 = this;
var _this$props = this.props,
dataHook = _this$props.dataHook,
current = _this$props.current,
showConverter = _this$props.showConverter,
showInput = _this$props.showInput,
addTooltipContent = _this$props.addTooltipContent,
allowEmpty = _this$props.allowEmpty,
hexPlaceholder = _this$props.hexPlaceholder;
var dataHooks = {
hex: 'color-picker-hex-input',
rgb: 'color-picker-rgb-inputs',
hsb: 'color-picker-hsb-inputs'
};
if (!showConverter && !showInput) {
return null;
}
if (!showConverter) {
return /*#__PURE__*/React.createElement(ColorPickerConverterHex, {
placeholder: hexPlaceholder,
dataHook: dataHooks.hex,
current: current,
onChange: this.props.onChange,
onEnter: this.props.onEnter,
onAdd: this.props.onAdd,
addTooltipContent: addTooltipContent,
allowEmpty: allowEmpty
});
}
var activeTab = this.state.activeTab;
return /*#__PURE__*/React.createElement("div", {
"data-hook": dataHook
}, /*#__PURE__*/React.createElement(WixStyleReactContext.Consumer, null, function (_ref) {
var reducedSpacingAndImprovedLayout = _ref.reducedSpacingAndImprovedLayout;
return /*#__PURE__*/React.createElement(Tabs, {
minWidth: 0,
items: tabs,
activeId: activeTab,
type: "uniformFull",
onClick: _this2.changeTab,
size: reducedSpacingAndImprovedLayout ? 'small' : undefined
});
}), activeTab === HEX && /*#__PURE__*/React.createElement(ColorPickerConverterHex, {
placeholder: hexPlaceholder,
dataHook: dataHooks.hex,
current: current,
onChange: this.props.onChange,
onAdd: this.props.onAdd,
onEnter: this.props.onEnter,
addTooltipContent: addTooltipContent,
allowEmpty: allowEmpty
}), activeTab === RGB && /*#__PURE__*/React.createElement(ColorPickerConverterRGB, {
dataHook: dataHooks.rgb,
current: current,
onChange: this.props.onChange,
onAdd: this.props.onAdd,
addTooltipContent: addTooltipContent,
allowEmpty: allowEmpty
}), activeTab === HSB && /*#__PURE__*/React.createElement(ColorPickerConverterHsb, {
dataHook: dataHooks.hsb,
current: current,
onChange: this.props.onChange,
onAdd: this.props.onAdd,
addTooltipContent: addTooltipContent,
allowEmpty: allowEmpty
}));
}
}, {
key: "changeTab",
value: function changeTab(_ref2) {
var id = _ref2.id;
this.setState({
activeTab: id
});
}
}]);
return ColorPickerConverter;
}(React.PureComponent);
_defineProperty(ColorPickerConverter, "propTypes", {
current: PropTypes.object.isRequired,
showConverter: PropTypes.bool.isRequired,
showInput: PropTypes.bool.isRequired,
onChange: PropTypes.func.isRequired,
onEnter: PropTypes.func.isRequired,
onAdd: PropTypes.func,
allowEmpty: PropTypes.bool,
hexPlaceholder: PropTypes.string
});
export { ColorPickerConverter as default };