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