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.js 1.4KB

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