UNPKG

react-bootstrap

Version:

Bootstrap 4 components built with React

81 lines (69 loc) 2.37 kB
import _extends from "@babel/runtime/helpers/esm/extends"; import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose"; import React from 'react'; import { uncontrollable } from 'uncontrollable'; import TabContext from './TabContext'; import SelectableContext from './SelectableContext'; var TabContainer = /*#__PURE__*/ function (_React$Component) { _inheritsLoose(TabContainer, _React$Component); function TabContainer(props) { var _this; _this = _React$Component.call(this, props) || this; _this.getControlledId = function (key) { return _this.getKey(key, 'tabpane'); }; _this.getControllerId = function (key) { return _this.getKey(key, 'tab'); }; _this.state = { tabContext: { onSelect: _this.props.onSelect, activeKey: _this.props.activeKey, transition: _this.props.transition, mountOnEnter: _this.props.mountOnEnter, unmountOnExit: _this.props.unmountOnExit, getControlledId: _this.getControlledId, getControllerId: _this.getControllerId } }; return _this; } TabContainer.getDerivedStateFromProps = function getDerivedStateFromProps(_ref, prevState) { var activeKey = _ref.activeKey, mountOnEnter = _ref.mountOnEnter, unmountOnExit = _ref.unmountOnExit, transition = _ref.transition; return { tabContext: _extends({}, prevState.tabContext, { activeKey: activeKey, mountOnEnter: mountOnEnter, unmountOnExit: unmountOnExit, transition: transition }) }; }; var _proto = TabContainer.prototype; _proto.getKey = function getKey(key, type) { var _this$props = this.props, generateChildId = _this$props.generateChildId, id = _this$props.id; if (generateChildId) return generateChildId(key, type); return id ? id + "-" + type + "-" + key : null; }; _proto.render = function render() { var _this$props2 = this.props, children = _this$props2.children, onSelect = _this$props2.onSelect; return React.createElement(TabContext.Provider, { value: this.state.tabContext }, React.createElement(SelectableContext.Provider, { value: onSelect }, children)); }; return TabContainer; }(React.Component); export default uncontrollable(TabContainer, { activeKey: 'onSelect' });