wix-style-react
Version:
wix-style-react
93 lines (74 loc) • 4.2 kB
JavaScript
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
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; }; }();
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 PropTypes from 'prop-types';
import classNames from 'classnames';
import pick from '../../../utils/operators/pick';
import withTooltip from '../withTooltip';
import * as TabPropTypes from '../constants/tab-prop-types';
import styles from '../../Tabs.scss';
var TabItem = function (_React$Component) {
_inherits(TabItem, _React$Component);
function TabItem() {
_classCallCheck(this, TabItem);
return _possibleConstructorReturn(this, (TabItem.__proto__ || Object.getPrototypeOf(TabItem)).apply(this, arguments));
}
_createClass(TabItem, [{
key: 'getItemStyle',
value: function getItemStyle() {
var _props = this.props,
type = _props.type,
width = _props.width,
itemMaxWidth = _props.itemMaxWidth;
return {
uniformSide: { width: width },
compactSide: itemMaxWidth ? { maxWidth: itemMaxWidth + 'pt' } : {}
}[type] || {};
}
}, {
key: 'render',
value: function render() {
var _props2 = this.props,
item = _props2.item,
onItemClick = _props2.onItemClick,
isActive = _props2.isActive,
initHasTooltip = _props2.initHasTooltip,
dynamicProperties = _props2.dynamicProperties;
var containerProps = _extends({
key: item.id,
onClick: function onClick() {
return onItemClick(item);
},
className: classNames(styles.tab, _defineProperty({}, styles.active, isActive)),
style: this.getItemStyle()
}, pick(this.props, dynamicProperties));
return React.createElement(
'li',
_extends({}, containerProps, { 'data-hook': item.dataHook }),
React.createElement(
'span',
{ ref: function ref(el) {
return initHasTooltip(el);
} },
item.title
)
);
}
}]);
return TabItem;
}(React.Component);
TabItem.propTypes = {
itemMaxWidth: PropTypes.number,
isActive: PropTypes.bool,
item: TabPropTypes.item.isRequired,
onItemClick: TabPropTypes.onClick,
type: TabPropTypes.type,
width: TabPropTypes.width,
initHasTooltip: PropTypes.func.isRequired,
dynamicProperties: PropTypes.array
};
export default withTooltip(TabItem);