1 | 'use strict';
|
2 |
|
3 | exports.__esModule = true;
|
4 |
|
5 | var _extends2 = require('babel-runtime/helpers/extends');
|
6 |
|
7 | var _extends3 = _interopRequireDefault(_extends2);
|
8 |
|
9 | var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
|
10 |
|
11 | var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
|
12 |
|
13 | var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
|
14 |
|
15 | var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
16 |
|
17 | var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
|
18 |
|
19 | var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
|
20 |
|
21 | var _inherits2 = require('babel-runtime/helpers/inherits');
|
22 |
|
23 | var _inherits3 = _interopRequireDefault(_inherits2);
|
24 |
|
25 | var _classnames = require('classnames');
|
26 |
|
27 | var _classnames2 = _interopRequireDefault(_classnames);
|
28 |
|
29 | var _react = require('react');
|
30 |
|
31 | var _react2 = _interopRequireDefault(_react);
|
32 |
|
33 | var _propTypes = require('prop-types');
|
34 |
|
35 | var _propTypes2 = _interopRequireDefault(_propTypes);
|
36 |
|
37 | var _elementType = require('prop-types-extra/lib/elementType');
|
38 |
|
39 | var _elementType2 = _interopRequireDefault(_elementType);
|
40 |
|
41 | var _bootstrapUtils = require('./utils/bootstrapUtils');
|
42 |
|
43 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
44 |
|
45 | var propTypes = {
|
46 | componentClass: _elementType2.default,
|
47 |
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 | animation: _propTypes2.default.oneOfType([_propTypes2.default.bool, _elementType2.default]),
|
54 |
|
55 | |
56 |
|
57 |
|
58 | mountOnEnter: _propTypes2.default.bool,
|
59 |
|
60 | |
61 |
|
62 |
|
63 | unmountOnExit: _propTypes2.default.bool
|
64 | };
|
65 |
|
66 | var defaultProps = {
|
67 | componentClass: 'div',
|
68 | animation: true,
|
69 | mountOnEnter: false,
|
70 | unmountOnExit: false
|
71 | };
|
72 |
|
73 | var contextTypes = {
|
74 | $bs_tabContainer: _propTypes2.default.shape({
|
75 | activeKey: _propTypes2.default.any
|
76 | })
|
77 | };
|
78 |
|
79 | var childContextTypes = {
|
80 | $bs_tabContent: _propTypes2.default.shape({
|
81 | bsClass: _propTypes2.default.string,
|
82 | animation: _propTypes2.default.oneOfType([_propTypes2.default.bool, _elementType2.default]),
|
83 | activeKey: _propTypes2.default.any,
|
84 | mountOnEnter: _propTypes2.default.bool,
|
85 | unmountOnExit: _propTypes2.default.bool,
|
86 | onPaneEnter: _propTypes2.default.func.isRequired,
|
87 | onPaneExited: _propTypes2.default.func.isRequired,
|
88 | exiting: _propTypes2.default.bool.isRequired
|
89 | })
|
90 | };
|
91 |
|
92 | var TabContent = function (_React$Component) {
|
93 | (0, _inherits3.default)(TabContent, _React$Component);
|
94 |
|
95 | function TabContent(props, context) {
|
96 | (0, _classCallCheck3.default)(this, TabContent);
|
97 |
|
98 | var _this = (0, _possibleConstructorReturn3.default)(this, _React$Component.call(this, props, context));
|
99 |
|
100 | _this.handlePaneEnter = _this.handlePaneEnter.bind(_this);
|
101 | _this.handlePaneExited = _this.handlePaneExited.bind(_this);
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | _this.state = {
|
107 | activeKey: null,
|
108 | activeChild: null
|
109 | };
|
110 | return _this;
|
111 | }
|
112 |
|
113 | TabContent.prototype.getChildContext = function getChildContext() {
|
114 | var _props = this.props,
|
115 | bsClass = _props.bsClass,
|
116 | animation = _props.animation,
|
117 | mountOnEnter = _props.mountOnEnter,
|
118 | unmountOnExit = _props.unmountOnExit;
|
119 |
|
120 |
|
121 | var stateActiveKey = this.state.activeKey;
|
122 | var containerActiveKey = this.getContainerActiveKey();
|
123 |
|
124 | var activeKey = stateActiveKey != null ? stateActiveKey : containerActiveKey;
|
125 | var exiting = stateActiveKey != null && stateActiveKey !== containerActiveKey;
|
126 |
|
127 | return {
|
128 | $bs_tabContent: {
|
129 | bsClass: bsClass,
|
130 | animation: animation,
|
131 | activeKey: activeKey,
|
132 | mountOnEnter: mountOnEnter,
|
133 | unmountOnExit: unmountOnExit,
|
134 | onPaneEnter: this.handlePaneEnter,
|
135 | onPaneExited: this.handlePaneExited,
|
136 | exiting: exiting
|
137 | }
|
138 | };
|
139 | };
|
140 |
|
141 | TabContent.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
|
142 | if (!nextProps.animation && this.state.activeChild) {
|
143 | this.setState({ activeKey: null, activeChild: null });
|
144 | }
|
145 | };
|
146 |
|
147 | TabContent.prototype.componentWillUnmount = function componentWillUnmount() {
|
148 | this.isUnmounted = true;
|
149 | };
|
150 |
|
151 | TabContent.prototype.getContainerActiveKey = function getContainerActiveKey() {
|
152 | var tabContainer = this.context.$bs_tabContainer;
|
153 | return tabContainer && tabContainer.activeKey;
|
154 | };
|
155 |
|
156 | TabContent.prototype.handlePaneEnter = function handlePaneEnter(child, childKey) {
|
157 | if (!this.props.animation) {
|
158 | return false;
|
159 | }
|
160 |
|
161 |
|
162 | if (childKey !== this.getContainerActiveKey()) {
|
163 | return false;
|
164 | }
|
165 |
|
166 | this.setState({
|
167 | activeKey: childKey,
|
168 | activeChild: child
|
169 | });
|
170 |
|
171 | return true;
|
172 | };
|
173 |
|
174 | TabContent.prototype.handlePaneExited = function handlePaneExited(child) {
|
175 |
|
176 | if (this.isUnmounted) {
|
177 | return;
|
178 | }
|
179 |
|
180 | this.setState(function (_ref) {
|
181 | var activeChild = _ref.activeChild;
|
182 |
|
183 | if (activeChild !== child) {
|
184 | return null;
|
185 | }
|
186 |
|
187 | return {
|
188 | activeKey: null,
|
189 | activeChild: null
|
190 | };
|
191 | });
|
192 | };
|
193 |
|
194 | TabContent.prototype.render = function render() {
|
195 | var _props2 = this.props,
|
196 | Component = _props2.componentClass,
|
197 | className = _props2.className,
|
198 | props = (0, _objectWithoutProperties3.default)(_props2, ['componentClass', 'className']);
|
199 |
|
200 | var _splitBsPropsAndOmit = (0, _bootstrapUtils.splitBsPropsAndOmit)(props, ['animation', 'mountOnEnter', 'unmountOnExit']),
|
201 | bsProps = _splitBsPropsAndOmit[0],
|
202 | elementProps = _splitBsPropsAndOmit[1];
|
203 |
|
204 | return _react2.default.createElement(Component, (0, _extends3.default)({}, elementProps, {
|
205 | className: (0, _classnames2.default)(className, (0, _bootstrapUtils.prefix)(bsProps, 'content'))
|
206 | }));
|
207 | };
|
208 |
|
209 | return TabContent;
|
210 | }(_react2.default.Component);
|
211 |
|
212 | TabContent.propTypes = propTypes;
|
213 | TabContent.defaultProps = defaultProps;
|
214 | TabContent.contextTypes = contextTypes;
|
215 | TabContent.childContextTypes = childContextTypes;
|
216 |
|
217 | exports.default = (0, _bootstrapUtils.bsClass)('tab', TabContent);
|
218 | module.exports = exports['default']; |
\ | No newline at end of file |