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.9KB

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