react-accessible-tabs
Version:
Accessible React tabs component
66 lines (52 loc) • 2.7 kB
JavaScript
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, { Component } from 'react';
import PropTypes from 'prop-types';
import Tab from './Tab';
import idSafeName from '../helpers/idSafeName';
var TabList = function (_Component) {
_inherits(TabList, _Component);
function TabList() {
_classCallCheck(this, TabList);
return _possibleConstructorReturn(this, _Component.apply(this, arguments));
}
TabList.prototype.render = function render() {
var _props = this.props;
var data = _props.data;
var userInvokedSelection = _props.userInvokedSelection;
var selectedIndex = _props.selectedIndex;
var onClick = _props.onClick;
var onKeyDown = _props.onKeyDown;
var resetUserInvokedSelection = _props.resetUserInvokedSelection;
if (!data.length) {
return null;
}
return React.createElement(
'ul',
{ role: 'tablist', className: 'tabs__tab-list' },
data.map(function (tab, index) {
var id = idSafeName(tab.label, index);
return React.createElement(Tab, {
key: id,
id: id,
index: index,
label: tab.label,
userInvokedSelection: userInvokedSelection,
selectedIndex: selectedIndex,
onClick: onClick,
onKeyDown: onKeyDown,
resetUserInvokedSelection: resetUserInvokedSelection
});
})
);
};
return TabList;
}(Component);
process.env.NODE_ENV !== "production" ? TabList.propTypes = {
data: PropTypes.array,
selectedIndex: PropTypes.number,
onClick: PropTypes.func,
onKeyDown: PropTypes.func
} : void 0;
export default TabList;