1 | import _extends from "@babel/runtime-corejs2/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime-corejs2/helpers/esm/objectWithoutPropertiesLoose";
|
3 | import _inheritsLoose from "@babel/runtime-corejs2/helpers/esm/inheritsLoose";
|
4 | import React from 'react';
|
5 | import PropTypes from 'prop-types';
|
6 | import requiredForA11y from 'prop-types-extra/lib/isRequiredForA11y';
|
7 | import uncontrollable from 'uncontrollable';
|
8 | import elementType from 'prop-types-extra/lib/elementType';
|
9 | import Nav from './Nav';
|
10 | import NavItem from './NavItem';
|
11 | import UncontrolledTabContainer from './TabContainer';
|
12 | import TabContent from './TabContent';
|
13 | import { bsClass as setBsClass } from './utils/bootstrapUtils';
|
14 | import ValidComponentChildren from './utils/ValidComponentChildren';
|
15 | var TabContainer = UncontrolledTabContainer.ControlledComponent;
|
16 | var propTypes = {
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 | activeKey: PropTypes.any,
|
23 |
|
24 | |
25 |
|
26 |
|
27 | bsStyle: PropTypes.oneOf(['tabs', 'pills']),
|
28 |
|
29 | |
30 |
|
31 |
|
32 |
|
33 |
|
34 | animation: PropTypes.oneOfType([PropTypes.bool, elementType]),
|
35 | id: requiredForA11y(PropTypes.oneOfType([PropTypes.string, PropTypes.number])),
|
36 |
|
37 | |
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | onSelect: PropTypes.func,
|
50 |
|
51 | |
52 |
|
53 |
|
54 | mountOnEnter: PropTypes.bool,
|
55 |
|
56 | |
57 |
|
58 |
|
59 | unmountOnExit: PropTypes.bool
|
60 | };
|
61 | var defaultProps = {
|
62 | bsStyle: 'tabs',
|
63 | animation: true,
|
64 | mountOnEnter: false,
|
65 | unmountOnExit: false
|
66 | };
|
67 |
|
68 | function getDefaultActiveKey(children) {
|
69 | var defaultActiveKey;
|
70 | ValidComponentChildren.forEach(children, function (child) {
|
71 | if (defaultActiveKey == null) {
|
72 | defaultActiveKey = child.props.eventKey;
|
73 | }
|
74 | });
|
75 | return defaultActiveKey;
|
76 | }
|
77 |
|
78 | var Tabs =
|
79 |
|
80 | function (_React$Component) {
|
81 | _inheritsLoose(Tabs, _React$Component);
|
82 |
|
83 | function Tabs() {
|
84 | return _React$Component.apply(this, arguments) || this;
|
85 | }
|
86 |
|
87 | var _proto = Tabs.prototype;
|
88 |
|
89 | _proto.renderTab = function renderTab(child) {
|
90 | var _child$props = child.props,
|
91 | title = _child$props.title,
|
92 | eventKey = _child$props.eventKey,
|
93 | disabled = _child$props.disabled,
|
94 | tabClassName = _child$props.tabClassName;
|
95 |
|
96 | if (title == null) {
|
97 | return null;
|
98 | }
|
99 |
|
100 | return React.createElement(NavItem, {
|
101 | eventKey: eventKey,
|
102 | disabled: disabled,
|
103 | className: tabClassName
|
104 | }, title);
|
105 | };
|
106 |
|
107 | _proto.render = function render() {
|
108 | var _this$props = this.props,
|
109 | id = _this$props.id,
|
110 | onSelect = _this$props.onSelect,
|
111 | animation = _this$props.animation,
|
112 | mountOnEnter = _this$props.mountOnEnter,
|
113 | unmountOnExit = _this$props.unmountOnExit,
|
114 | bsClass = _this$props.bsClass,
|
115 | className = _this$props.className,
|
116 | style = _this$props.style,
|
117 | children = _this$props.children,
|
118 | _this$props$activeKey = _this$props.activeKey,
|
119 | activeKey = _this$props$activeKey === void 0 ? getDefaultActiveKey(children) : _this$props$activeKey,
|
120 | props = _objectWithoutPropertiesLoose(_this$props, ["id", "onSelect", "animation", "mountOnEnter", "unmountOnExit", "bsClass", "className", "style", "children", "activeKey"]);
|
121 |
|
122 | return React.createElement(TabContainer, {
|
123 | id: id,
|
124 | activeKey: activeKey,
|
125 | onSelect: onSelect,
|
126 | className: className,
|
127 | style: style
|
128 | }, React.createElement("div", null, React.createElement(Nav, _extends({}, props, {
|
129 | role: "tablist"
|
130 | }), ValidComponentChildren.map(children, this.renderTab)), React.createElement(TabContent, {
|
131 | bsClass: bsClass,
|
132 | animation: animation,
|
133 | mountOnEnter: mountOnEnter,
|
134 | unmountOnExit: unmountOnExit
|
135 | }, children)));
|
136 | };
|
137 |
|
138 | return Tabs;
|
139 | }(React.Component);
|
140 |
|
141 | Tabs.propTypes = propTypes;
|
142 | Tabs.defaultProps = defaultProps;
|
143 | setBsClass('tab', Tabs);
|
144 | export default uncontrollable(Tabs, {
|
145 | activeKey: 'onSelect'
|
146 | }); |
\ | No newline at end of file |