UNPKG

wix-style-react

Version:
135 lines (116 loc) 5.34 kB
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 { any, string } from 'prop-types'; import classNames from 'classnames'; import WixComponent from '../../BaseComponents/WixComponent'; import Button from '../Button/Button'; import tpaStyleInjector from '../TpaStyleInjector'; 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 = React.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 React.createElement( Button, { key: child.props.id, onClick: function onClick() { return _this2.handleTabClick(child.props.id); }, className: classNames(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 React.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 React.Children.map(children, function (child) { var _activeId = _this3.getActiveId(activeId, children); var className = child.props.id === _activeId ? 'active' : ''; return React.createElement( 'div', { className: classNames(className, styles.locals['wix-style-react-floating-tab-item'], contentClassName) }, child ); }); } }, { key: 'render', value: function render() { return React.createElement( 'div', { className: styles.locals['wix-style-react-floating-tabs'] }, this.renderButtons(), this.renderContent() ); } }]); return FloatingTabs; }(WixComponent), _class.propTypes = { children: any, tabClassName: string, contentClassName: string, activeTabClassName: string }, _class.defaultProps = { tabClassName: '', contentClassName: '', activeTabClassName: '' }, _temp); FloatingTabs.displayName = 'FloatingTabs'; export default tpaStyleInjector(FloatingTabs, styles);