|
2 | 2 | /* These properties are validated in 'Portal' and 'Position' components */ |
3 | 3 |
|
4 | 4 | import React, { cloneElement } from 'react'; |
5 | | -import Portal from './Portal'; |
6 | | -import Position from './Position'; |
7 | | -import RootCloseWrapper from './RootCloseWrapper'; |
| 5 | +import BaseOverlay from 'react-overlays/lib/Overlay'; |
8 | 6 | import CustomPropTypes from './utils/CustomPropTypes'; |
9 | 7 | import Fade from './Fade'; |
10 | 8 | import classNames from 'classnames'; |
11 | 9 |
|
12 | 10 | class Overlay extends React.Component { |
13 | | - constructor(props, context) { |
14 | | - super(props, context); |
15 | | - |
16 | | - this.state = {exited: !props.show}; |
17 | | - this.onHiddenListener = this.handleHidden.bind(this); |
18 | | - } |
19 | | - |
20 | | - componentWillReceiveProps(nextProps) { |
21 | | - if (nextProps.show) { |
22 | | - this.setState({exited: false}); |
23 | | - } else if (!nextProps.animation) { |
24 | | - // Otherwise let handleHidden take care of marking exited. |
25 | | - this.setState({exited: true}); |
26 | | - } |
27 | | - } |
28 | 11 |
|
29 | 12 | render() { |
30 | 13 | let { |
31 | | - container |
32 | | - , containerPadding |
33 | | - , target |
34 | | - , placement |
35 | | - , rootClose |
36 | | - , children |
37 | | - , animation: Transition |
| 14 | + children: child |
| 15 | + , animation: transition |
38 | 16 | , ...props } = this.props; |
39 | 17 |
|
40 | | - if (Transition === true) { |
41 | | - Transition = Fade; |
| 18 | + if (transition === true) { |
| 19 | + transition = Fade; |
42 | 20 | } |
43 | 21 |
|
44 | | - // Don't un-render the overlay while it's transitioning out. |
45 | | - const mountOverlay = props.show || (Transition && !this.state.exited); |
46 | | - if (!mountOverlay) { |
47 | | - // Don't bother showing anything if we don't have to. |
48 | | - return null; |
49 | | - } |
50 | | - |
51 | | - let child = children; |
52 | | - |
53 | | - // Position is be inner-most because it adds inline styles into the child, |
54 | | - // which the other wrappers don't forward correctly. |
55 | | - child = ( |
56 | | - <Position {...{container, containerPadding, target, placement}}> |
57 | | - {child} |
58 | | - </Position> |
59 | | - ); |
60 | | - |
61 | | - if (Transition) { |
62 | | - let { onExit, onExiting, onEnter, onEntering, onEntered } = props; |
63 | | - |
64 | | - // This animates the child node by injecting props, so it must precede |
65 | | - // anything that adds a wrapping div. |
66 | | - child = ( |
67 | | - <Transition |
68 | | - in={props.show} |
69 | | - transitionAppear |
70 | | - onExit={onExit} |
71 | | - onExiting={onExiting} |
72 | | - onExited={this.onHiddenListener} |
73 | | - onEnter={onEnter} |
74 | | - onEntering={onEntering} |
75 | | - onEntered={onEntered} |
76 | | - > |
77 | | - {child} |
78 | | - </Transition> |
79 | | - ); |
80 | | - } else { |
| 22 | + if (!transition) { |
81 | 23 | child = cloneElement(child, { |
82 | 24 | className: classNames('in', child.props.className) |
83 | 25 | }); |
84 | 26 | } |
85 | 27 |
|
86 | | - // This goes after everything else because it adds a wrapping div. |
87 | | - if (rootClose) { |
88 | | - child = ( |
89 | | - <RootCloseWrapper onRootClose={props.onHide}> |
90 | | - {child} |
91 | | - </RootCloseWrapper> |
92 | | - ); |
93 | | - } |
94 | | - |
95 | 28 | return ( |
96 | | - <Portal container={container}> |
| 29 | + <BaseOverlay |
| 30 | + {...props} |
| 31 | + transition={transition} |
| 32 | + > |
97 | 33 | {child} |
98 | | - </Portal> |
| 34 | + </BaseOverlay> |
99 | 35 | ); |
100 | 36 | } |
101 | | - |
102 | | - handleHidden(...args) { |
103 | | - this.setState({exited: true}); |
104 | | - |
105 | | - if (this.props.onExited) { |
106 | | - this.props.onExited(...args); |
107 | | - } |
108 | | - } |
109 | 37 | } |
110 | 38 |
|
111 | 39 | Overlay.propTypes = { |
112 | | - ...Portal.propTypes, |
113 | | - ...Position.propTypes, |
| 40 | + ...BaseOverlay.propTypes, |
| 41 | + |
114 | 42 | /** |
115 | 43 | * Set the visibility of the Overlay |
116 | 44 | */ |
|
0 commit comments