您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DialogContainer.tsx 2.5KB

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