You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

OverlayContainer.tsx 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import { IReduxState } from '../../../app/types';
  4. import { getOverlayToRender } from '../../functions.web';
  5. /**
  6. * The type of the React {@link Component} props of {@code OverlayContainer}.
  7. */
  8. interface IProps {
  9. /**
  10. * The React {@link Component} type of overlay to be rendered by the
  11. * associated {@code OverlayContainer}.
  12. */
  13. overlay: any;
  14. }
  15. /**
  16. * Implements a React {@link Component} that will display the correct overlay
  17. * when needed.
  18. */
  19. class OverlayContainer extends Component<IProps> {
  20. /**
  21. * Implements React's {@link Component#render()}.
  22. *
  23. * @inheritdoc
  24. * @public
  25. * @returns {ReactElement|null}
  26. */
  27. render() {
  28. const { overlay } = this.props;
  29. return overlay ? React.createElement(overlay, {}) : null;
  30. }
  31. }
  32. /**
  33. * Maps (parts of) the redux state to the associated {@code OverlayContainer}'s
  34. * props.
  35. *
  36. * @param {Object} state - The redux state.
  37. * @private
  38. * @returns {{
  39. * overlay: ?Object
  40. * }}
  41. */
  42. function _mapStateToProps(state: IReduxState) {
  43. return {
  44. /**
  45. * The React {@link Component} type of overlay to be rendered by the
  46. * associated {@code OverlayContainer}.
  47. */
  48. overlay: getOverlayToRender(state)
  49. };
  50. }
  51. export default connect(_mapStateToProps)(OverlayContainer);