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 2.6KB

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