UNPKG

@attivio/suit

Version:

Attivio SUIT, the Search UI Toolkit, is a library for creating search clients for searching the Attivio platform.

96 lines (76 loc) 3.39 kB
var _class2, _temp; 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; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } import React from 'react'; import PropTypes from 'prop-types'; import { withRouter } from 'react-router-dom'; export var NavTabInfo = function NavTabInfo(label, route) { _classCallCheck(this, NavTabInfo); this.label = label; this.route = route; }; /** * A set of buttons to use within the Masthead component for * navigation within the application. Clicking one will update * the application’s router with the button’s route. */ var MastheadNavTabs = (_temp = _class2 = function (_React$Component) { _inherits(MastheadNavTabs, _React$Component); function MastheadNavTabs(props) { _classCallCheck(this, MastheadNavTabs); var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); var initialTab = _this.props.initialTab; if (!initialTab) { if (_this.props.tabInfo && _this.props.tabInfo.length > 0 && _this.props.tabInfo[0]) { initialTab = _this.props.tabInfo[0].route; } } _this.state = { currentTab: initialTab }; _this.routeTo = _this.routeTo.bind(_this); return _this; } MastheadNavTabs.prototype.routeTo = function routeTo(route) { var _this2 = this; this.setState({ currentTab: route }, function () { _this2.props.history.push({ pathname: route, search: _this2.props.location.search }); }); }; MastheadNavTabs.prototype.render = function render() { var _this3 = this; var tabs = []; this.props.tabInfo.forEach(function (tabInfo) { var liClass = tabInfo.route === _this3.state.currentTab ? 'active' : ''; var clickHandler = tabInfo.route === _this3.state.currentTab ? null : function () { _this3.routeTo(tabInfo.route); }; tabs.push(React.createElement( 'li', { key: tabInfo.route, className: liClass }, React.createElement( 'a', { onClick: clickHandler, role: 'button', tabIndex: 0 }, tabInfo.label ) )); }); return React.createElement( 'div', { className: 'attivio-tabpanel-radio attivio-tabpanel-radio-navbar attivio-globalmast-tabpanel' }, React.createElement( 'ul', { className: 'nav nav-tabs' }, tabs ) ); }; return MastheadNavTabs; }(React.Component), _class2.defaultProps = { initialTab: null }, _class2.displayName = 'MastheadNavTabs', _temp); MastheadNavTabs.NavTabInfo = NavTabInfo; export default withRouter(MastheadNavTabs);