UNPKG

react-tabs

Version:

An accessible and easy tab component for ReactJS

65 lines (53 loc) 2.59 kB
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; } import PropTypes from 'prop-types'; import React, { Component } from 'react'; import cx from 'classnames'; var DEFAULT_CLASS = 'react-tabs__tab-panel'; var TabPanel = /*#__PURE__*/ function (_Component) { _inheritsLoose(TabPanel, _Component); function TabPanel() { return _Component.apply(this, arguments) || this; } var _proto = TabPanel.prototype; _proto.render = function render() { var _cx; var _this$props = this.props, children = _this$props.children, className = _this$props.className, forceRender = _this$props.forceRender, id = _this$props.id, selected = _this$props.selected, selectedClassName = _this$props.selectedClassName, tabId = _this$props.tabId, attributes = _objectWithoutPropertiesLoose(_this$props, ["children", "className", "forceRender", "id", "selected", "selectedClassName", "tabId"]); return React.createElement("div", _extends({}, attributes, { className: cx(className, (_cx = {}, _cx[selectedClassName] = selected, _cx)), role: "tabpanel", id: id, "aria-labelledby": tabId }), forceRender || selected ? children : null); }; return TabPanel; }(Component); TabPanel.defaultProps = { className: DEFAULT_CLASS, forceRender: false, selectedClassName: DEFAULT_CLASS + "--selected" }; export { TabPanel as default }; TabPanel.propTypes = process.env.NODE_ENV !== "production" ? { children: PropTypes.node, className: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object]), forceRender: PropTypes.bool, id: PropTypes.string, // private selected: PropTypes.bool, // private selectedClassName: PropTypes.string, tabId: PropTypes.string // private } : {}; TabPanel.tabsRole = 'TabPanel';