UNPKG

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