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 _warning = _interopRequireDefault(require("warning"));
|
25 |
|
26 | var _bootstrapUtils = require("./utils/bootstrapUtils");
|
27 |
|
28 | var _createChainedFunction = _interopRequireDefault(require("./utils/createChainedFunction"));
|
29 |
|
30 | var _Fade = _interopRequireDefault(require("./Fade"));
|
31 |
|
32 | var propTypes = {
|
33 | |
34 |
|
35 |
|
36 | eventKey: _propTypes.default.any,
|
37 |
|
38 | |
39 |
|
40 |
|
41 |
|
42 |
|
43 | animation: _propTypes.default.oneOfType([_propTypes.default.bool, _elementType.default]),
|
44 |
|
45 |
|
46 | id: _propTypes.default.string,
|
47 |
|
48 |
|
49 | 'aria-labelledby': _propTypes.default.string,
|
50 |
|
51 | |
52 |
|
53 |
|
54 |
|
55 |
|
56 | bsClass: _propTypes.default.string,
|
57 |
|
58 | |
59 |
|
60 |
|
61 | onEnter: _propTypes.default.func,
|
62 |
|
63 | |
64 |
|
65 |
|
66 | onEntering: _propTypes.default.func,
|
67 |
|
68 | |
69 |
|
70 |
|
71 | onEntered: _propTypes.default.func,
|
72 |
|
73 | |
74 |
|
75 |
|
76 | onExit: _propTypes.default.func,
|
77 |
|
78 | |
79 |
|
80 |
|
81 | onExiting: _propTypes.default.func,
|
82 |
|
83 | |
84 |
|
85 |
|
86 | onExited: _propTypes.default.func,
|
87 |
|
88 | |
89 |
|
90 |
|
91 | mountOnEnter: _propTypes.default.bool,
|
92 |
|
93 | |
94 |
|
95 |
|
96 | unmountOnExit: _propTypes.default.bool
|
97 | };
|
98 | var contextTypes = {
|
99 | $bs_tabContainer: _propTypes.default.shape({
|
100 | getTabId: _propTypes.default.func,
|
101 | getPaneId: _propTypes.default.func
|
102 | }),
|
103 | $bs_tabContent: _propTypes.default.shape({
|
104 | bsClass: _propTypes.default.string,
|
105 | animation: _propTypes.default.oneOfType([_propTypes.default.bool, _elementType.default]),
|
106 | activeKey: _propTypes.default.any,
|
107 | mountOnEnter: _propTypes.default.bool,
|
108 | unmountOnExit: _propTypes.default.bool,
|
109 | onPaneEnter: _propTypes.default.func.isRequired,
|
110 | onPaneExited: _propTypes.default.func.isRequired,
|
111 | exiting: _propTypes.default.bool.isRequired
|
112 | })
|
113 | };
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 | var childContextTypes = {
|
120 | $bs_tabContainer: _propTypes.default.oneOf([null])
|
121 | };
|
122 |
|
123 | var TabPane =
|
124 |
|
125 | function (_React$Component) {
|
126 | (0, _inheritsLoose2.default)(TabPane, _React$Component);
|
127 |
|
128 | function TabPane(props, context) {
|
129 | var _this;
|
130 |
|
131 | _this = _React$Component.call(this, props, context) || this;
|
132 | _this.handleEnter = _this.handleEnter.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
|
133 | _this.handleExited = _this.handleExited.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
|
134 | _this.in = false;
|
135 | return _this;
|
136 | }
|
137 |
|
138 | var _proto = TabPane.prototype;
|
139 |
|
140 | _proto.getChildContext = function getChildContext() {
|
141 | return {
|
142 | $bs_tabContainer: null
|
143 | };
|
144 | };
|
145 |
|
146 | _proto.componentDidMount = function componentDidMount() {
|
147 | if (this.shouldBeIn()) {
|
148 |
|
149 | this.handleEnter();
|
150 | }
|
151 | };
|
152 |
|
153 | _proto.componentDidUpdate = function componentDidUpdate() {
|
154 | if (this.in) {
|
155 | if (!this.shouldBeIn()) {
|
156 |
|
157 | this.handleExited();
|
158 | }
|
159 | } else if (this.shouldBeIn()) {
|
160 |
|
161 | this.handleEnter();
|
162 | }
|
163 | };
|
164 |
|
165 | _proto.componentWillUnmount = function componentWillUnmount() {
|
166 | if (this.in) {
|
167 |
|
168 | this.handleExited();
|
169 | }
|
170 | };
|
171 |
|
172 | _proto.getAnimation = function getAnimation() {
|
173 | if (this.props.animation != null) {
|
174 | return this.props.animation;
|
175 | }
|
176 |
|
177 | var tabContent = this.context.$bs_tabContent;
|
178 | return tabContent && tabContent.animation;
|
179 | };
|
180 |
|
181 | _proto.handleEnter = function handleEnter() {
|
182 | var tabContent = this.context.$bs_tabContent;
|
183 |
|
184 | if (!tabContent) {
|
185 | return;
|
186 | }
|
187 |
|
188 | this.in = tabContent.onPaneEnter(this, this.props.eventKey);
|
189 | };
|
190 |
|
191 | _proto.handleExited = function handleExited() {
|
192 | var tabContent = this.context.$bs_tabContent;
|
193 |
|
194 | if (!tabContent) {
|
195 | return;
|
196 | }
|
197 |
|
198 | tabContent.onPaneExited(this);
|
199 | this.in = false;
|
200 | };
|
201 |
|
202 | _proto.isActive = function isActive() {
|
203 | var tabContent = this.context.$bs_tabContent;
|
204 | var activeKey = tabContent && tabContent.activeKey;
|
205 | return this.props.eventKey === activeKey;
|
206 | };
|
207 |
|
208 | _proto.shouldBeIn = function shouldBeIn() {
|
209 | return this.getAnimation() && this.isActive();
|
210 | };
|
211 |
|
212 | _proto.render = function render() {
|
213 | var _this$props = this.props,
|
214 | eventKey = _this$props.eventKey,
|
215 | className = _this$props.className,
|
216 | onEnter = _this$props.onEnter,
|
217 | onEntering = _this$props.onEntering,
|
218 | onEntered = _this$props.onEntered,
|
219 | onExit = _this$props.onExit,
|
220 | onExiting = _this$props.onExiting,
|
221 | onExited = _this$props.onExited,
|
222 | propsMountOnEnter = _this$props.mountOnEnter,
|
223 | propsUnmountOnExit = _this$props.unmountOnExit,
|
224 | props = (0, _objectWithoutPropertiesLoose2.default)(_this$props, ["eventKey", "className", "onEnter", "onEntering", "onEntered", "onExit", "onExiting", "onExited", "mountOnEnter", "unmountOnExit"]);
|
225 | var _this$context = this.context,
|
226 | tabContent = _this$context.$bs_tabContent,
|
227 | tabContainer = _this$context.$bs_tabContainer;
|
228 |
|
229 | var _splitBsPropsAndOmit = (0, _bootstrapUtils.splitBsPropsAndOmit)(props, ['animation']),
|
230 | bsProps = _splitBsPropsAndOmit[0],
|
231 | elementProps = _splitBsPropsAndOmit[1];
|
232 |
|
233 | var active = this.isActive();
|
234 | var animation = this.getAnimation();
|
235 | var mountOnEnter = propsMountOnEnter != null ? propsMountOnEnter : tabContent && tabContent.mountOnEnter;
|
236 | var unmountOnExit = propsUnmountOnExit != null ? propsUnmountOnExit : tabContent && tabContent.unmountOnExit;
|
237 |
|
238 | if (!active && !animation && unmountOnExit) {
|
239 | return null;
|
240 | }
|
241 |
|
242 | var Transition = animation === true ? _Fade.default : animation || null;
|
243 |
|
244 | if (tabContent) {
|
245 | bsProps.bsClass = (0, _bootstrapUtils.prefix)(tabContent, 'pane');
|
246 | }
|
247 |
|
248 | var classes = (0, _extends2.default)({}, (0, _bootstrapUtils.getClassSet)(bsProps), {
|
249 | active: active
|
250 | });
|
251 |
|
252 | if (tabContainer) {
|
253 | process.env.NODE_ENV !== "production" ? (0, _warning.default)(!elementProps.id && !elementProps['aria-labelledby'], 'In the context of a `<TabContainer>`, `<TabPanes>` are given ' + 'generated `id` and `aria-labelledby` attributes for the sake of ' + 'proper component accessibility. Any provided ones will be ignored. ' + 'To control these attributes directly provide a `generateChildId` ' + 'prop to the parent `<TabContainer>`.') : void 0;
|
254 | elementProps.id = tabContainer.getPaneId(eventKey);
|
255 | elementProps['aria-labelledby'] = tabContainer.getTabId(eventKey);
|
256 | }
|
257 |
|
258 | var pane = _react.default.createElement("div", (0, _extends2.default)({}, elementProps, {
|
259 | role: "tabpanel",
|
260 | "aria-hidden": !active,
|
261 | className: (0, _classnames.default)(className, classes)
|
262 | }));
|
263 |
|
264 | if (Transition) {
|
265 | var exiting = tabContent && tabContent.exiting;
|
266 | return _react.default.createElement(Transition, {
|
267 | in: active && !exiting,
|
268 | onEnter: (0, _createChainedFunction.default)(this.handleEnter, onEnter),
|
269 | onEntering: onEntering,
|
270 | onEntered: onEntered,
|
271 | onExit: onExit,
|
272 | onExiting: onExiting,
|
273 | onExited: (0, _createChainedFunction.default)(this.handleExited, onExited),
|
274 | mountOnEnter: mountOnEnter,
|
275 | unmountOnExit: unmountOnExit
|
276 | }, pane);
|
277 | }
|
278 |
|
279 | return pane;
|
280 | };
|
281 |
|
282 | return TabPane;
|
283 | }(_react.default.Component);
|
284 |
|
285 | TabPane.propTypes = propTypes;
|
286 | TabPane.contextTypes = contextTypes;
|
287 | TabPane.childContextTypes = childContextTypes;
|
288 |
|
289 | var _default = (0, _bootstrapUtils.bsClass)('tab-pane', TabPane);
|
290 |
|
291 | exports.default = _default;
|
292 | module.exports = exports["default"]; |
\ | No newline at end of file |