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