2017-11-29 11:48:10 +01:00
|
|
|
// @flow
|
2017-11-16 12:26:14 -06:00
|
|
|
|
2017-01-31 14:58:48 -06:00
|
|
|
import React, { Component } from 'react';
|
2019-03-21 17:38:29 +01:00
|
|
|
|
|
|
|
|
import { connect } from '../../base/redux';
|
2017-01-31 14:58:48 -06:00
|
|
|
|
2018-06-14 11:14:32 +02:00
|
|
|
import { getOverlayToRender } from '../functions';
|
2017-01-31 14:58:48 -06:00
|
|
|
|
2017-11-29 11:48:10 +01:00
|
|
|
declare var interfaceConfig: Object;
|
|
|
|
|
|
2017-01-31 14:58:48 -06:00
|
|
|
/**
|
2017-11-29 22:13:24 -06:00
|
|
|
* The type of the React {@link Component} props of {@code OverlayContainer}.
|
2017-01-31 14:58:48 -06:00
|
|
|
*/
|
2017-11-29 11:48:10 +01:00
|
|
|
type Props = {
|
|
|
|
|
|
2017-01-31 14:58:48 -06:00
|
|
|
/**
|
2017-11-29 22:13:24 -06:00
|
|
|
* The React {@link Component} type of overlay to be rendered by the
|
|
|
|
|
* associated {@code OverlayContainer}.
|
2017-01-31 14:58:48 -06:00
|
|
|
*/
|
2017-11-29 22:13:24 -06:00
|
|
|
overlay: ?React$ComponentType<*>
|
2017-11-29 11:48:10 +01:00
|
|
|
}
|
2017-01-31 14:58:48 -06:00
|
|
|
|
2017-11-29 11:48:10 +01:00
|
|
|
/**
|
|
|
|
|
* Implements a React {@link Component} that will display the correct overlay
|
|
|
|
|
* when needed.
|
|
|
|
|
*/
|
|
|
|
|
class OverlayContainer extends Component<Props> {
|
2017-01-31 14:58:48 -06:00
|
|
|
/**
|
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
|
*
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
* @public
|
2017-11-27 16:08:12 -06:00
|
|
|
* @returns {ReactElement|null}
|
2017-01-31 14:58:48 -06:00
|
|
|
*/
|
|
|
|
|
render() {
|
2017-11-09 14:34:42 +01:00
|
|
|
const { overlay } = this.props;
|
2017-01-31 14:58:48 -06:00
|
|
|
|
2017-11-09 14:34:42 +01:00
|
|
|
return overlay ? React.createElement(overlay, {}) : null;
|
2017-01-31 14:58:48 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-11-27 16:08:12 -06:00
|
|
|
* Maps (parts of) the redux state to the associated {@code OverlayContainer}'s
|
|
|
|
|
* props.
|
2017-01-31 14:58:48 -06:00
|
|
|
*
|
2017-06-05 13:19:25 -05:00
|
|
|
* @param {Object} state - The redux state.
|
2017-11-27 16:08:12 -06:00
|
|
|
* @private
|
2017-01-31 14:58:48 -06:00
|
|
|
* @returns {{
|
2017-11-27 16:08:12 -06:00
|
|
|
* overlay: ?Object
|
2017-01-31 14:58:48 -06:00
|
|
|
* }}
|
|
|
|
|
*/
|
|
|
|
|
function _mapStateToProps(state) {
|
2017-11-09 14:34:42 +01:00
|
|
|
return {
|
2017-01-31 14:58:48 -06:00
|
|
|
/**
|
2017-11-27 20:50:56 -06:00
|
|
|
* The React {@link Component} type of overlay to be rendered by the
|
|
|
|
|
* associated {@code OverlayContainer}.
|
2017-01-31 14:58:48 -06:00
|
|
|
*/
|
2018-06-14 11:14:32 +02:00
|
|
|
overlay: getOverlayToRender(state)
|
2017-01-31 14:58:48 -06:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(_mapStateToProps)(OverlayContainer);
|