1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.default = void 0;
|
5 |
|
6 | var _classnames = _interopRequireDefault(require("classnames"));
|
7 |
|
8 | var _css = _interopRequireDefault(require("dom-helpers/css"));
|
9 |
|
10 | var _height = _interopRequireDefault(require("dom-helpers/height"));
|
11 |
|
12 | var _transitionEnd = _interopRequireDefault(require("dom-helpers/transitionEnd"));
|
13 |
|
14 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
15 |
|
16 | var _react = _interopRequireDefault(require("react"));
|
17 |
|
18 | var _Transition = _interopRequireWildcard(require("react-transition-group/Transition"));
|
19 |
|
20 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
21 |
|
22 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
23 |
|
24 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
25 |
|
26 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
27 |
|
28 | const transitionClasses = {
|
29 | [_Transition.ENTERING]: 'rw-slide-transition-entering',
|
30 | [_Transition.EXITING]: 'rw-slide-transition-exiting',
|
31 | [_Transition.EXITED]: 'rw-slide-transition-exited'
|
32 | };
|
33 |
|
34 | class SlideDownTransition extends _react.default.Component {
|
35 | constructor(...args) {
|
36 | super(...args);
|
37 |
|
38 | this.setContainerHeight = elem => {
|
39 | elem.style.height = this.getHeight(elem) + 'px';
|
40 | };
|
41 |
|
42 | this.clearContainerHeight = elem => {
|
43 | elem.style.height = '';
|
44 | };
|
45 |
|
46 | this.handleEntered = elem => {
|
47 | this.clearContainerHeight(elem);
|
48 | if (this.props.onEntered) this.props.onEntered();
|
49 | };
|
50 |
|
51 | this.handleEntering = () => {
|
52 | if (this.props.onEntering) this.props.onEntering();
|
53 | };
|
54 |
|
55 | this.handleExit = elem => {
|
56 | this.setContainerHeight(elem);
|
57 | if (this.props.onExit) this.props.onExit();
|
58 | };
|
59 |
|
60 | this.handleExited = elem => {
|
61 | this.clearContainerHeight(elem);
|
62 | if (this.props.onExited) this.props.onExited();
|
63 | };
|
64 |
|
65 | this.handleTransitionEnd = (el, done) => {
|
66 | (0, _transitionEnd.default)(el.firstChild, done);
|
67 | };
|
68 | }
|
69 |
|
70 | getHeight(container) {
|
71 | let content = container.firstChild;
|
72 | let margin = parseInt((0, _css.default)(content, 'margin-top'), 10) + parseInt((0, _css.default)(content, 'margin-bottom'), 10);
|
73 | let old = container.style.display;
|
74 | let height;
|
75 | container.style.display = 'block';
|
76 | height = ((0, _height.default)(content) || 0) + (isNaN(margin) ? 0 : margin);
|
77 | container.style.display = old;
|
78 | return height;
|
79 | }
|
80 |
|
81 | render() {
|
82 | const {
|
83 | children,
|
84 | className,
|
85 | dropUp
|
86 | } = this.props;
|
87 | return _react.default.createElement(_Transition.default, {
|
88 | appear: true,
|
89 | in: this.props.in,
|
90 | onEnter: this.setContainerHeight,
|
91 | onEntering: this.handleEntering,
|
92 | onEntered: this.handleEntered,
|
93 | onExit: this.handleExit,
|
94 | onExited: this.handleExited,
|
95 | addEndListener: this.handleTransitionEnd,
|
96 | timeout: undefined
|
97 |
|
98 |
|
99 | }, (status, innerProps) => _react.default.createElement("div", _extends({}, innerProps, {
|
100 | className: (0, _classnames.default)(className, dropUp && 'rw-dropup', transitionClasses[status])
|
101 | }), _react.default.cloneElement(children, {
|
102 | className: (0, _classnames.default)('rw-slide-transition', children.props.className)
|
103 | })));
|
104 | }
|
105 |
|
106 | }
|
107 |
|
108 | SlideDownTransition.propTypes = {
|
109 | in: _propTypes.default.bool.isRequired,
|
110 | innerClassName: _propTypes.default.string,
|
111 | dropUp: _propTypes.default.bool,
|
112 | onExit: _propTypes.default.func,
|
113 | onExited: _propTypes.default.func,
|
114 | onEntering: _propTypes.default.func,
|
115 | onEntered: _propTypes.default.func
|
116 | };
|
117 | var _default = SlideDownTransition;
|
118 | exports.default = _default; |
\ | No newline at end of file |