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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. /**
  26. * Implements React's {@link Component#render()}.
  27. *
  28. * @inheritdoc
  29. * @returns {ReactElement}
  30. */
  31. render() {
  32. const { _component: component } = this.props;
  33. return (
  34. component
  35. ? React.createElement(component, this.props._componentProps)
  36. : null);
  37. }
  38. }
  39. /**
  40. * Maps (parts of) the redux state to the associated {@code DialogContainer}'s
  41. * props.
  42. *
  43. * @param {Object} state - The redux state.
  44. * @private
  45. * @returns {{
  46. * _component: React.Component,
  47. * _componentProps: Object
  48. * }}
  49. */
  50. function _mapStateToProps(state) {
  51. const stateFeaturesBaseDialog = state['features/base/dialog'];
  52. return {
  53. _component: stateFeaturesBaseDialog.component,
  54. _componentProps: stateFeaturesBaseDialog.componentProps
  55. };
  56. }
  57. export default connect(_mapStateToProps)(DialogContainer);