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.

AbstractDialogContainer.js 1.6KB

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