UNPKG

2.84 kBJavaScriptView Raw
1import _objectWithoutPropertiesLoose from "@babel/runtime-corejs2/helpers/esm/objectWithoutPropertiesLoose";
2import _inheritsLoose from "@babel/runtime-corejs2/helpers/esm/inheritsLoose";
3import _extends from "@babel/runtime-corejs2/helpers/esm/extends";
4import classNames from 'classnames';
5import React, { cloneElement } from 'react';
6import PropTypes from 'prop-types';
7import BaseOverlay from 'react-overlays/lib/Overlay';
8import elementType from 'prop-types-extra/lib/elementType';
9import Fade from './Fade';
10
11var propTypes = _extends({}, BaseOverlay.propTypes, {
12 /**
13 * Set the visibility of the Overlay
14 */
15 show: PropTypes.bool,
16
17 /**
18 * Specify whether the overlay should trigger onHide when the user clicks outside the overlay
19 */
20 rootClose: PropTypes.bool,
21
22 /**
23 * A callback invoked by the overlay when it wishes to be hidden. Required if
24 * `rootClose` is specified.
25 */
26 onHide: PropTypes.func,
27
28 /**
29 * Use animation
30 */
31 animation: PropTypes.oneOfType([PropTypes.bool, elementType]),
32
33 /**
34 * Callback fired before the Overlay transitions in
35 */
36 onEnter: PropTypes.func,
37
38 /**
39 * Callback fired as the Overlay begins to transition in
40 */
41 onEntering: PropTypes.func,
42
43 /**
44 * Callback fired after the Overlay finishes transitioning in
45 */
46 onEntered: PropTypes.func,
47
48 /**
49 * Callback fired right before the Overlay transitions out
50 */
51 onExit: PropTypes.func,
52
53 /**
54 * Callback fired as the Overlay begins to transition out
55 */
56 onExiting: PropTypes.func,
57
58 /**
59 * Callback fired after the Overlay finishes transitioning out
60 */
61 onExited: PropTypes.func,
62
63 /**
64 * Sets the direction of the Overlay.
65 */
66 placement: PropTypes.oneOf(['top', 'right', 'bottom', 'left'])
67});
68
69var defaultProps = {
70 animation: Fade,
71 rootClose: false,
72 show: false,
73 placement: 'right'
74};
75
76var Overlay =
77/*#__PURE__*/
78function (_React$Component) {
79 _inheritsLoose(Overlay, _React$Component);
80
81 function Overlay() {
82 return _React$Component.apply(this, arguments) || this;
83 }
84
85 var _proto = Overlay.prototype;
86
87 _proto.render = function render() {
88 var _this$props = this.props,
89 animation = _this$props.animation,
90 children = _this$props.children,
91 props = _objectWithoutPropertiesLoose(_this$props, ["animation", "children"]);
92
93 var transition = animation === true ? Fade : animation || null;
94 var child;
95
96 if (!transition) {
97 child = cloneElement(children, {
98 className: classNames(children.props.className, 'in')
99 });
100 } else {
101 child = children;
102 }
103
104 return React.createElement(BaseOverlay, _extends({}, props, {
105 transition: transition
106 }), child);
107 };
108
109 return Overlay;
110}(React.Component);
111
112Overlay.propTypes = propTypes;
113Overlay.defaultProps = defaultProps;
114export default Overlay;
\No newline at end of file