Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

OverflowMenuButton.tsx 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* eslint-disable lines-around-comment */
  2. import React, { ReactNode, useCallback } from 'react';
  3. import { useSelector } from 'react-redux';
  4. import { makeStyles } from 'tss-react/mui';
  5. import { createToolbarEvent } from '../../../analytics/AnalyticsEvents';
  6. import { sendAnalytics } from '../../../analytics/functions';
  7. import Popover from '../../../base/popover/components/Popover.web';
  8. // @ts-ignore
  9. import { ReactionEmoji, ReactionsMenu } from '../../../reactions/components';
  10. import { REACTIONS_MENU_HEIGHT } from '../../../reactions/constants';
  11. import { getReactionsQueue } from '../../../reactions/functions.any';
  12. import { DRAWER_MAX_HEIGHT } from '../../constants';
  13. import { showOverflowDrawer } from '../../functions.web';
  14. import Drawer from './Drawer';
  15. import JitsiPortal from './JitsiPortal';
  16. // @ts-ignore
  17. import OverflowToggleButton from './OverflowToggleButton';
  18. /* eslint-enable lines-around-comment */
  19. /**
  20. * The type of the React {@code Component} props of {@link OverflowMenuButton}.
  21. */
  22. interface IProps {
  23. /**
  24. * ID of the menu that is controlled by this button.
  25. */
  26. ariaControls: string;
  27. /**
  28. * A child React Element to display within {@code Popover}.
  29. */
  30. children: ReactNode;
  31. /**
  32. * Whether or not the OverflowMenu popover should display.
  33. */
  34. isOpen: boolean;
  35. /**
  36. * Callback to change the visibility of the overflow menu.
  37. */
  38. onVisibilityChange: Function;
  39. /**
  40. * Whether or not to display the reactions in the mobile menu.
  41. */
  42. showMobileReactions: boolean;
  43. }
  44. const useStyles = makeStyles()(() => {
  45. return {
  46. overflowMenuDrawer: {
  47. overflowY: 'auto' as const,
  48. height: `calc(${DRAWER_MAX_HEIGHT} - ${REACTIONS_MENU_HEIGHT}px - 16px)`
  49. }
  50. };
  51. });
  52. const OverflowMenuButton = ({
  53. children,
  54. isOpen,
  55. onVisibilityChange,
  56. showMobileReactions
  57. }: IProps) => {
  58. const { classes } = useStyles();
  59. const overflowDrawer = useSelector(showOverflowDrawer);
  60. const reactionsQueue = useSelector(getReactionsQueue);
  61. const onCloseDialog = useCallback(() => {
  62. onVisibilityChange(false);
  63. }, [ onVisibilityChange ]);
  64. const onOpenDialog = useCallback(() => {
  65. onVisibilityChange(true);
  66. }, [ onVisibilityChange ]);
  67. const onEscClick = useCallback((event: React.KeyboardEvent) => {
  68. if (event.key === 'Escape' && isOpen) {
  69. event.preventDefault();
  70. event.stopPropagation();
  71. onCloseDialog();
  72. }
  73. }, [ onCloseDialog ]);
  74. const toggleDialogVisibility = useCallback(() => {
  75. sendAnalytics(createToolbarEvent('overflow'));
  76. onVisibilityChange(!isOpen);
  77. }, [ isOpen, onVisibilityChange ]);
  78. return (
  79. <div className = 'toolbox-button-wth-dialog context-menu'>
  80. {
  81. overflowDrawer ? (
  82. <>
  83. <OverflowToggleButton
  84. handleClick = { toggleDialogVisibility }
  85. isOpen = { isOpen }
  86. onKeyDown = { onEscClick } />
  87. <JitsiPortal>
  88. <Drawer
  89. isOpen = { isOpen }
  90. onClose = { onCloseDialog }>
  91. <>
  92. <div className = { classes.overflowMenuDrawer }>
  93. {children}
  94. </div>
  95. {showMobileReactions && <ReactionsMenu overflowMenu = { true } />}
  96. </>
  97. </Drawer>
  98. {showMobileReactions && <div className = 'reactions-animations-container'>
  99. {reactionsQueue.map(({ reaction, uid }, index) => (<ReactionEmoji
  100. index = { index }
  101. key = { uid }
  102. reaction = { reaction }
  103. uid = { uid } />))}
  104. </div>}
  105. </JitsiPortal>
  106. </>
  107. ) : (
  108. <Popover
  109. content = { children }
  110. headingId = 'overflow-context-menu'
  111. onPopoverClose = { onCloseDialog }
  112. onPopoverOpen = { onOpenDialog }
  113. position = 'top'
  114. trigger = 'click'
  115. visible = { isOpen }>
  116. <OverflowToggleButton
  117. isOpen = { isOpen }
  118. onKeyDown = { onEscClick } />
  119. </Popover>
  120. )
  121. }
  122. </div>
  123. );
  124. };
  125. export default OverflowMenuButton;