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.tsx 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { ModalTransition } from '@atlaskit/modal-dialog';
  2. import React, { Component, ComponentType } from 'react';
  3. import { IReduxState } from '../../../../app/types';
  4. import { IReactionEmojiProps } from '../../../../reactions/constants';
  5. import JitsiPortal from '../../../../toolbox/components/web/JitsiPortal';
  6. import { showOverflowDrawer } from '../../../../toolbox/functions.web';
  7. import { connect } from '../../../redux/functions';
  8. import DialogTransition from './DialogTransition';
  9. interface IProps {
  10. /**
  11. * The component to render.
  12. */
  13. _component: ComponentType;
  14. /**
  15. * The props to pass to the component that will be rendered.
  16. */
  17. _componentProps: Object;
  18. /**
  19. * Whether the dialog is using the new component.
  20. */
  21. _isNewDialog: boolean;
  22. /**
  23. * Whether the overflow drawer should be used.
  24. */
  25. _overflowDrawer: boolean;
  26. /**
  27. * Array of reactions to be displayed.
  28. */
  29. _reactionsQueue: Array<IReactionEmojiProps>;
  30. /**
  31. * True if the UI is in a compact state where we don't show dialogs.
  32. */
  33. _reducedUI: boolean;
  34. }
  35. /**
  36. * Implements a DialogContainer responsible for showing all dialogs. Necessary
  37. * for supporting @atlaskit's modal animations.
  38. *
  39. */
  40. class DialogContainer extends Component<IProps> {
  41. /**
  42. * Returns the dialog to be displayed.
  43. *
  44. * @private
  45. * @returns {ReactElement|null}
  46. */
  47. _renderDialogContent() {
  48. const {
  49. _component: component,
  50. _reducedUI: reducedUI
  51. } = this.props;
  52. return (
  53. component && !reducedUI
  54. ? React.createElement(component, this.props._componentProps)
  55. : null);
  56. }
  57. /**
  58. * Implements React's {@link Component#render()}.
  59. *
  60. * @inheritdoc
  61. * @returns {ReactElement}
  62. */
  63. render() {
  64. return this.props._isNewDialog ? (
  65. <DialogTransition>
  66. {this.props._overflowDrawer
  67. ? <JitsiPortal>{this._renderDialogContent()}</JitsiPortal>
  68. : this._renderDialogContent() }
  69. </DialogTransition>
  70. ) : (
  71. <ModalTransition>
  72. { this._renderDialogContent() }
  73. </ModalTransition>
  74. );
  75. }
  76. }
  77. /**
  78. * Maps (parts of) the redux state to the associated
  79. * {@code AbstractDialogContainer}'s props.
  80. *
  81. * @param {Object} state - The redux state.
  82. * @private
  83. * @returns {IProps}
  84. */
  85. function mapStateToProps(state: IReduxState) {
  86. const stateFeaturesBaseDialog = state['features/base/dialog'];
  87. const { reducedUI } = state['features/base/responsive-ui'];
  88. const overflowDrawer = showOverflowDrawer(state);
  89. return {
  90. _component: stateFeaturesBaseDialog.component,
  91. _componentProps: stateFeaturesBaseDialog.componentProps,
  92. _isNewDialog: stateFeaturesBaseDialog.isNewDialog,
  93. _overflowDrawer: overflowDrawer,
  94. _reducedUI: reducedUI
  95. };
  96. }
  97. export default connect(mapStateToProps)(DialogContainer);