選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

OverflowMenuButton.tsx 4.7KB

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