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