wix-style-react
Version:
wix-style-react
117 lines (95 loc) • 4.53 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 _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 { object, bool, func } from 'prop-types';
import WixComponent from '../BaseComponents/WixComponent';
import Tabs from '../Tabs';
import ColorPickerConverterHex from './ColorPickerConverterHex';
import ColorPickerConverterRGB from './ColorPickerConverterRGB';
import ColorPickerConverterHsb from './ColorPickerConverterHsb';
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 = (_temp = _class = function (_WixComponent) {
_inherits(ColorPickerConverter, _WixComponent);
function ColorPickerConverter(props) {
_classCallCheck(this, ColorPickerConverter);
var _this = _possibleConstructorReturn(this, (ColorPickerConverter.__proto__ || Object.getPrototypeOf(ColorPickerConverter)).call(this, props));
_this.state = {
activeTab: HEX
};
_this.changeTab = _this.changeTab.bind(_this);
return _this;
}
_createClass(ColorPickerConverter, [{
key: 'render',
value: function render() {
var _props = this.props,
current = _props.current,
showConverter = _props.showConverter,
showInput = _props.showInput;
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 React.createElement(ColorPickerConverterHex, {
dataHook: dataHooks.hex,
current: current,
onChange: this.props.onChange,
onEnter: this.props.onEnter
});
}
var activeTab = this.state.activeTab;
return React.createElement(
'div',
null,
React.createElement(Tabs, {
minWidth: 0,
items: tabs,
activeId: activeTab,
type: 'uniformFull',
onClick: this.changeTab
}),
activeTab === HEX && React.createElement(ColorPickerConverterHex, {
dataHook: dataHooks.hex,
current: current,
onChange: this.props.onChange,
onEnter: this.props.onEnter
}),
activeTab === RGB && React.createElement(ColorPickerConverterRGB, {
dataHook: dataHooks.rgb,
current: current,
onChange: this.props.onChange
}),
activeTab === HSB && React.createElement(ColorPickerConverterHsb, {
dataHook: dataHooks.hsb,
current: current,
onChange: this.props.onChange
})
);
}
}, {
key: 'changeTab',
value: function changeTab(_ref) {
var id = _ref.id;
this.setState({ activeTab: id });
}
}]);
return ColorPickerConverter;
}(WixComponent), _class.propTypes = {
current: object.isRequired,
showConverter: bool.isRequired,
showInput: bool.isRequired,
onChange: func.isRequired,
onEnter: func.isRequired
}, _temp);
export { ColorPickerConverter as default };