UNPKG

wix-style-react

Version:
158 lines (126 loc) • 6 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); 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; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _classnames = require('classnames'); var _classnames2 = _interopRequireDefault(_classnames); var _WixComponent2 = require('../../BaseComponents/WixComponent'); var _WixComponent3 = _interopRequireDefault(_WixComponent2); var _Button = require('../Button/Button'); var _Button2 = _interopRequireDefault(_Button); var _TpaStyleInjector = require('../TpaStyleInjector'); var _TpaStyleInjector2 = _interopRequireDefault(_TpaStyleInjector); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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; } var styles = { locals: {} }; try { styles = require('!css-loader?modules&camelCase&localIdentName="[path][name]__[local]__[hash:base64:5]"!sass-loader!./FloatingTabs.scss'); } catch (e) {} var FloatingTabs = (_temp = _class = function (_WixComponent) { _inherits(FloatingTabs, _WixComponent); function FloatingTabs(props) { _classCallCheck(this, FloatingTabs); var _this = _possibleConstructorReturn(this, (FloatingTabs.__proto__ || Object.getPrototypeOf(FloatingTabs)).call(this, props)); _this.state = { selectedTabIndex: null }; return _this; } _createClass(FloatingTabs, [{ key: 'getActiveId', value: function getActiveId(activeId, items) { return activeId || items[0].props.id; } }, { key: 'handleTabClick', value: function handleTabClick(id) { this.props.onChange(id); } }, { key: 'renderButtons', value: function renderButtons() { var _this2 = this; var _props = this.props, children = _props.children, activeId = _props.activeId, tabClassName = _props.tabClassName, activeTabClassName = _props.activeTabClassName; var childrenArray = _react2.default.Children.toArray(children); var tabButtons = childrenArray.map(function (child) { var _activeId = _this2.getActiveId(activeId, children); var theme = _activeId === child.props.id ? 'fill' : 'outline'; var isActiveClass = _activeId === child.props.id ? activeTabClassName : ''; return _react2.default.createElement( _Button2.default, { key: child.props.id, onClick: function onClick() { return _this2.handleTabClick(child.props.id); }, className: (0, _classnames2.default)(styles.locals['wix-style-react-floating-tabs-button'], styles.locals['wix-style-react-floating-tabs-buttons-item'], isActiveClass, tabClassName), dataHook: 'floating-tab-item-button-' + child.props.id, theme: theme }, child.props.title ); }); return _react2.default.createElement( 'div', { className: styles.locals['wix-style-react-floating-tabs-buttons'], 'data-hook': 'floating-tab-item-buttons' }, tabButtons ); } }, { key: 'renderContent', value: function renderContent() { var _this3 = this; var _props2 = this.props, children = _props2.children, activeId = _props2.activeId, contentClassName = _props2.contentClassName; return _react2.default.Children.map(children, function (child) { var _activeId = _this3.getActiveId(activeId, children); var className = child.props.id === _activeId ? 'active' : ''; return _react2.default.createElement( 'div', { className: (0, _classnames2.default)(className, styles.locals['wix-style-react-floating-tab-item'], contentClassName) }, child ); }); } }, { key: 'render', value: function render() { return _react2.default.createElement( 'div', { className: styles.locals['wix-style-react-floating-tabs'] }, this.renderButtons(), this.renderContent() ); } }]); return FloatingTabs; }(_WixComponent3.default), _class.propTypes = { children: _propTypes.any, tabClassName: _propTypes.string, contentClassName: _propTypes.string, activeTabClassName: _propTypes.string }, _class.defaultProps = { tabClassName: '', contentClassName: '', activeTabClassName: '' }, _temp); FloatingTabs.displayName = 'FloatingTabs'; exports.default = (0, _TpaStyleInjector2.default)(FloatingTabs, styles);