@attivio/suit
Version:
Attivio SUIT, the Search UI Toolkit, is a library for creating search clients for searching the Attivio platform.
109 lines (82 loc) • 3.76 kB
JavaScript
;
exports.__esModule = true;
exports.NavTabInfo = undefined;
var _class2, _temp;
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _propTypes = require('prop-types');
var _propTypes2 = _interopRequireDefault(_propTypes);
var _reactRouterDom = require('react-router-dom');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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"); } }
var NavTabInfo = exports.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(_react2.default.createElement(
'li',
{ key: tabInfo.route, className: liClass },
_react2.default.createElement(
'a',
{ onClick: clickHandler, role: 'button', tabIndex: 0 },
tabInfo.label
)
));
});
return _react2.default.createElement(
'div',
{ className: 'attivio-tabpanel-radio attivio-tabpanel-radio-navbar attivio-globalmast-tabpanel' },
_react2.default.createElement(
'ul',
{ className: 'nav nav-tabs' },
tabs
)
);
};
return MastheadNavTabs;
}(_react2.default.Component), _class2.defaultProps = {
initialTab: null
}, _class2.displayName = 'MastheadNavTabs', _temp);
MastheadNavTabs.NavTabInfo = NavTabInfo;
exports.default = (0, _reactRouterDom.withRouter)(MastheadNavTabs);