1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
3 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
4 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
5 | import _inherits from 'babel-runtime/helpers/inherits';
|
6 | import React from 'react';
|
7 | import PropTypes from 'prop-types';
|
8 | import requiredForA11y from 'prop-types-extra/lib/isRequiredForA11y';
|
9 | import uncontrollable from 'uncontrollable';
|
10 |
|
11 | import Nav from './Nav';
|
12 | import NavItem from './NavItem';
|
13 | import UncontrolledTabContainer from './TabContainer';
|
14 | import TabContent from './TabContent';
|
15 | import { bsClass as setBsClass } from './utils/bootstrapUtils';
|
16 | import ValidComponentChildren from './utils/ValidComponentChildren';
|
17 |
|
18 | var TabContainer = UncontrolledTabContainer.ControlledComponent;
|
19 |
|
20 | var propTypes = {
|
21 | |
22 |
|
23 |
|
24 |
|
25 |
|
26 | activeKey: PropTypes.any,
|
27 |
|
28 | |
29 |
|
30 |
|
31 | bsStyle: PropTypes.oneOf(['tabs', 'pills']),
|
32 |
|
33 | animation: PropTypes.bool,
|
34 |
|
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 |
|
62 | var defaultProps = {
|
63 | bsStyle: 'tabs',
|
64 | animation: true,
|
65 | mountOnEnter: false,
|
66 | unmountOnExit: false
|
67 | };
|
68 |
|
69 | function getDefaultActiveKey(children) {
|
70 | var defaultActiveKey = void 0;
|
71 | ValidComponentChildren.forEach(children, function (child) {
|
72 | if (defaultActiveKey == null) {
|
73 | defaultActiveKey = child.props.eventKey;
|
74 | }
|
75 | });
|
76 |
|
77 | return defaultActiveKey;
|
78 | }
|
79 |
|
80 | var Tabs = function (_React$Component) {
|
81 | _inherits(Tabs, _React$Component);
|
82 |
|
83 | function Tabs() {
|
84 | _classCallCheck(this, Tabs);
|
85 |
|
86 | return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
|
87 | }
|
88 |
|
89 | Tabs.prototype.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(
|
101 | NavItem,
|
102 | { eventKey: eventKey, disabled: disabled, className: tabClassName },
|
103 | title
|
104 | );
|
105 | };
|
106 |
|
107 | Tabs.prototype.render = function render() {
|
108 | var _props = this.props,
|
109 | id = _props.id,
|
110 | onSelect = _props.onSelect,
|
111 | animation = _props.animation,
|
112 | mountOnEnter = _props.mountOnEnter,
|
113 | unmountOnExit = _props.unmountOnExit,
|
114 | bsClass = _props.bsClass,
|
115 | className = _props.className,
|
116 | style = _props.style,
|
117 | children = _props.children,
|
118 | _props$activeKey = _props.activeKey,
|
119 | activeKey = _props$activeKey === undefined ? getDefaultActiveKey(children) : _props$activeKey,
|
120 | props = _objectWithoutProperties(_props, ['id', 'onSelect', 'animation', 'mountOnEnter', 'unmountOnExit', 'bsClass', 'className', 'style', 'children', 'activeKey']);
|
121 |
|
122 | return React.createElement(
|
123 | TabContainer,
|
124 | {
|
125 | id: id,
|
126 | activeKey: activeKey,
|
127 | onSelect: onSelect,
|
128 | className: className,
|
129 | style: style
|
130 | },
|
131 | React.createElement(
|
132 | 'div',
|
133 | null,
|
134 | React.createElement(
|
135 | Nav,
|
136 | _extends({}, props, { role: 'tablist' }),
|
137 | ValidComponentChildren.map(children, this.renderTab)
|
138 | ),
|
139 | React.createElement(
|
140 | TabContent,
|
141 | {
|
142 | bsClass: bsClass,
|
143 | animation: animation,
|
144 | mountOnEnter: mountOnEnter,
|
145 | unmountOnExit: unmountOnExit
|
146 | },
|
147 | children
|
148 | )
|
149 | )
|
150 | );
|
151 | };
|
152 |
|
153 | return Tabs;
|
154 | }(React.Component);
|
155 |
|
156 | Tabs.propTypes = propTypes;
|
157 | Tabs.defaultProps = defaultProps;
|
158 |
|
159 | setBsClass('tab', Tabs);
|
160 |
|
161 | export default uncontrollable(Tabs, { activeKey: 'onSelect' }); |
\ | No newline at end of file |