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.

DialogContainer.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. /**
  5. * The type of the React {@code Component} props of {@link DialogContainer}.
  6. */
  7. type Props = {
  8. /**
  9. * The component to render.
  10. */
  11. _component: Function,
  12. /**
  13. * The props to pass to the component that will be rendered.
  14. */
  15. _componentProps: Object,
  16. /**
  17. * True if the UI is in a compact state where we don't show dialogs.
  18. */
  19. _reducedUI: boolean
  20. };
  21. /**
  22. * Implements a DialogContainer responsible for showing all dialogs. We will
  23. * need a separate container so we can handle multiple dialogs by showing them
  24. * simultaneously or queuing them.
  25. */
  26. export class DialogContainer extends Component<Props> {
  27. /**
  28. * Implements React's {@link Component#render()}.
  29. *
  30. * @inheritdoc
  31. * @returns {ReactElement}
  32. */
  33. render() {
  34. const {
  35. _component: component,
  36. _reducedUI: reducedUI
  37. } = this.props;
  38. return (
  39. component && !reducedUI
  40. ? React.createElement(component, this.props._componentProps)
  41. : null);
  42. }
  43. }
  44. /**
  45. * Maps (parts of) the redux state to the associated {@code DialogContainer}'s
  46. * props.
  47. *
  48. * @param {Object} state - The redux state.
  49. * @private
  50. * @returns {{
  51. * _component: React.Component,
  52. * _componentProps: Object,
  53. * _reducedUI: boolean
  54. * }}
  55. */
  56. function _mapStateToProps(state) {
  57. const stateFeaturesBaseDialog = state['features/base/dialog'];
  58. const { reducedUI } = state['features/base/responsive-ui'];
  59. return {
  60. _component: stateFeaturesBaseDialog.component,
  61. _componentProps: stateFeaturesBaseDialog.componentProps,
  62. _reducedUI: reducedUI
  63. };
  64. }
  65. export default connect(_mapStateToProps)(DialogContainer);