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.

HangupMenuButton.tsx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import React, { Component } from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import { createToolbarEvent } from '../../../analytics/AnalyticsEvents';
  4. import { sendAnalytics } from '../../../analytics/functions';
  5. import { translate } from '../../../base/i18n/functions';
  6. import Popover from '../../../base/popover/components/Popover.web';
  7. import HangupToggleButton from './HangupToggleButton';
  8. /**
  9. * The type of the React {@code Component} props of {@link HangupMenuButton}.
  10. */
  11. interface IProps extends WithTranslation {
  12. /**
  13. * ID of the menu that is controlled by this button.
  14. */
  15. ariaControls: String;
  16. /**
  17. * A child React Element to display within {@code InlineDialog}.
  18. */
  19. children: React.ReactNode;
  20. /**
  21. * Whether or not the HangupMenu popover should display.
  22. */
  23. isOpen: boolean;
  24. /**
  25. * Notify mode for `toolbarButtonClicked` event -
  26. * whether to only notify or to also prevent button click routine.
  27. */
  28. notifyMode?: string;
  29. /**
  30. * Callback to change the visibility of the hangup menu.
  31. */
  32. onVisibilityChange: Function;
  33. }
  34. /**
  35. * A React {@code Component} for opening or closing the {@code HangupMenu}.
  36. *
  37. * @augments Component
  38. */
  39. class HangupMenuButton extends Component<IProps> {
  40. /**
  41. * Initializes a new {@code HangupMenuButton} instance.
  42. *
  43. * @param {Object} props - The read-only properties with which the new
  44. * instance is to be initialized.
  45. */
  46. constructor(props: IProps) {
  47. super(props);
  48. // Bind event handlers so they are only bound once per instance.
  49. this._onCloseDialog = this._onCloseDialog.bind(this);
  50. this._toggleDialogVisibility
  51. = this._toggleDialogVisibility.bind(this);
  52. this._onEscClick = this._onEscClick.bind(this);
  53. }
  54. /**
  55. * Click handler for the more actions entries.
  56. *
  57. * @param {KeyboardEvent} event - Esc key click to close the popup.
  58. * @returns {void}
  59. */
  60. _onEscClick(event: KeyboardEvent) {
  61. if (event.key === 'Escape' && this.props.isOpen) {
  62. event.preventDefault();
  63. event.stopPropagation();
  64. this._onCloseDialog();
  65. }
  66. }
  67. /**
  68. * Implements React's {@link Component#render()}.
  69. *
  70. * @inheritdoc
  71. * @returns {ReactElement}
  72. */
  73. render() {
  74. const { children, isOpen } = this.props;
  75. return (
  76. <div className = 'toolbox-button-wth-dialog context-menu'>
  77. <Popover
  78. content = { children }
  79. onPopoverClose = { this._onCloseDialog }
  80. position = 'top'
  81. trigger = 'click'
  82. visible = { isOpen }>
  83. <HangupToggleButton
  84. buttonKey = 'hangup-menu'
  85. customClass = 'hangup-menu-button'
  86. handleClick = { this._toggleDialogVisibility }
  87. isOpen = { isOpen }
  88. notifyMode = { this.props.notifyMode }
  89. onKeyDown = { this._onEscClick } />
  90. </Popover>
  91. </div>
  92. );
  93. }
  94. /**
  95. * Callback invoked when {@code InlineDialog} signals that it should be
  96. * close.
  97. *
  98. * @private
  99. * @returns {void}
  100. */
  101. _onCloseDialog() {
  102. this.props.onVisibilityChange(false);
  103. }
  104. /**
  105. * Callback invoked to signal that an event has occurred that should change
  106. * the visibility of the {@code InlineDialog} component.
  107. *
  108. * @private
  109. * @returns {void}
  110. */
  111. _toggleDialogVisibility() {
  112. sendAnalytics(createToolbarEvent('hangup'));
  113. this.props.onVisibilityChange(!this.props.isOpen);
  114. }
  115. }
  116. export default translate(HangupMenuButton);