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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 dialog is a raw dialog (doesn't inherit behavior from other common frameworks, such as atlaskit).
  17. */
  18. _rawDialog: boolean,
  19. /**
  20. * True if the UI is in a compact state where we don't show dialogs.
  21. */
  22. _reducedUI: boolean
  23. };
  24. /**
  25. * Implements a DialogContainer responsible for showing all dialogs.
  26. */
  27. export default class AbstractDialogContainer extends Component<Props> {
  28. /**
  29. * Returns the dialog to be displayed.
  30. *
  31. * @private
  32. * @returns {ReactElement|null}
  33. */
  34. _renderDialogContent() {
  35. const {
  36. _component: component,
  37. _reducedUI: reducedUI
  38. } = this.props;
  39. return (
  40. component && !reducedUI
  41. ? React.createElement(component, this.props._componentProps)
  42. : null);
  43. }
  44. }
  45. /**
  46. * Maps (parts of) the redux state to the associated
  47. * {@code AbstractDialogContainer}'s props.
  48. *
  49. * @param {Object} state - The redux state.
  50. * @private
  51. * @returns {Props}
  52. */
  53. export function abstractMapStateToProps(state: Object): $Shape<Props> {
  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. _rawDialog: stateFeaturesBaseDialog.rawDialog,
  60. _reducedUI: reducedUI
  61. };
  62. }