1 | import _extends from "@babel/runtime/helpers/esm/extends";
|
2 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
3 | var _excluded = ["activeKey", "getControlledId", "getControllerId"],
|
4 | _excluded2 = ["bsPrefix", "className", "active", "onEnter", "onEntering", "onEntered", "onExit", "onExiting", "onExited", "mountOnEnter", "unmountOnExit", "transition", "as", "eventKey"];
|
5 | import classNames from 'classnames';
|
6 | import React, { useContext } from 'react';
|
7 | import { useBootstrapPrefix } from './ThemeProvider';
|
8 | import TabContext from './TabContext';
|
9 | import SelectableContext, { makeEventKey } from './SelectableContext';
|
10 | import Fade from './Fade';
|
11 |
|
12 | function useTabContext(props) {
|
13 | var context = useContext(TabContext);
|
14 | if (!context) return props;
|
15 |
|
16 | var activeKey = context.activeKey,
|
17 | getControlledId = context.getControlledId,
|
18 | getControllerId = context.getControllerId,
|
19 | rest = _objectWithoutPropertiesLoose(context, _excluded);
|
20 |
|
21 | var shouldTransition = props.transition !== false && rest.transition !== false;
|
22 | var key = makeEventKey(props.eventKey);
|
23 | return _extends({}, props, {
|
24 | active: props.active == null && key != null ? makeEventKey(activeKey) === key : props.active,
|
25 | id: getControlledId(props.eventKey),
|
26 | 'aria-labelledby': getControllerId(props.eventKey),
|
27 | transition: shouldTransition && (props.transition || rest.transition || Fade),
|
28 | mountOnEnter: props.mountOnEnter != null ? props.mountOnEnter : rest.mountOnEnter,
|
29 | unmountOnExit: props.unmountOnExit != null ? props.unmountOnExit : rest.unmountOnExit
|
30 | });
|
31 | }
|
32 |
|
33 | var TabPane = React.forwardRef(function (props, ref) {
|
34 | var _useTabContext = useTabContext(props),
|
35 | bsPrefix = _useTabContext.bsPrefix,
|
36 | className = _useTabContext.className,
|
37 | active = _useTabContext.active,
|
38 | onEnter = _useTabContext.onEnter,
|
39 | onEntering = _useTabContext.onEntering,
|
40 | onEntered = _useTabContext.onEntered,
|
41 | onExit = _useTabContext.onExit,
|
42 | onExiting = _useTabContext.onExiting,
|
43 | onExited = _useTabContext.onExited,
|
44 | mountOnEnter = _useTabContext.mountOnEnter,
|
45 | unmountOnExit = _useTabContext.unmountOnExit,
|
46 | Transition = _useTabContext.transition,
|
47 | _useTabContext$as = _useTabContext.as,
|
48 | Component = _useTabContext$as === void 0 ? 'div' : _useTabContext$as,
|
49 | _ = _useTabContext.eventKey,
|
50 | rest = _objectWithoutPropertiesLoose(_useTabContext, _excluded2);
|
51 |
|
52 | var prefix = useBootstrapPrefix(bsPrefix, 'tab-pane');
|
53 | if (!active && !Transition && unmountOnExit) return null;
|
54 | var pane = React.createElement(Component, _extends({}, rest, {
|
55 | ref: ref,
|
56 | role: "tabpanel",
|
57 | "aria-hidden": !active,
|
58 | className: classNames(className, prefix, {
|
59 | active: active
|
60 | })
|
61 | }));
|
62 | if (Transition) pane = React.createElement(Transition, {
|
63 | in: active,
|
64 | onEnter: onEnter,
|
65 | onEntering: onEntering,
|
66 | onEntered: onEntered,
|
67 | onExit: onExit,
|
68 | onExiting: onExiting,
|
69 | onExited: onExited,
|
70 | mountOnEnter: mountOnEnter,
|
71 | unmountOnExit: unmountOnExit
|
72 | }, pane);
|
73 |
|
74 |
|
75 | return React.createElement(TabContext.Provider, {
|
76 | value: null
|
77 | }, React.createElement(SelectableContext.Provider, {
|
78 | value: null
|
79 | }, pane));
|
80 | });
|
81 | TabPane.displayName = 'TabPane';
|
82 | export default TabPane; |
\ | No newline at end of file |