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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. * Callback to change the visibility of the hangup menu.
  26. */
  27. onVisibilityChange: Function;
  28. }
  29. /**
  30. * A React {@code Component} for opening or closing the {@code HangupMenu}.
  31. *
  32. * @augments Component
  33. */
  34. class HangupMenuButton extends Component<IProps> {
  35. /**
  36. * Initializes a new {@code HangupMenuButton} instance.
  37. *
  38. * @param {Object} props - The read-only properties with which the new
  39. * instance is to be initialized.
  40. */
  41. constructor(props: IProps) {
  42. super(props);
  43. // Bind event handlers so they are only bound once per instance.
  44. this._onCloseDialog = this._onCloseDialog.bind(this);
  45. this._toggleDialogVisibility
  46. = this._toggleDialogVisibility.bind(this);
  47. this._onEscClick = this._onEscClick.bind(this);
  48. }
  49. /**
  50. * Click handler for the more actions entries.
  51. *
  52. * @param {KeyboardEvent} event - Esc key click to close the popup.
  53. * @returns {void}
  54. */
  55. _onEscClick(event: KeyboardEvent) {
  56. if (event.key === 'Escape' && this.props.isOpen) {
  57. event.preventDefault();
  58. event.stopPropagation();
  59. this._onCloseDialog();
  60. }
  61. }
  62. /**
  63. * Implements React's {@link Component#render()}.
  64. *
  65. * @inheritdoc
  66. * @returns {ReactElement}
  67. */
  68. render() {
  69. const { children, isOpen } = this.props;
  70. return (
  71. <div className = 'toolbox-button-wth-dialog context-menu'>
  72. <Popover
  73. content = { children }
  74. onPopoverClose = { this._onCloseDialog }
  75. position = 'top'
  76. trigger = 'click'
  77. visible = { isOpen }>
  78. <HangupToggleButton
  79. customClass = 'hangup-menu-button'
  80. handleClick = { this._toggleDialogVisibility }
  81. isOpen = { isOpen }
  82. onKeyDown = { this._onEscClick } />
  83. </Popover>
  84. </div>
  85. );
  86. }
  87. /**
  88. * Callback invoked when {@code InlineDialog} signals that it should be
  89. * close.
  90. *
  91. * @private
  92. * @returns {void}
  93. */
  94. _onCloseDialog() {
  95. this.props.onVisibilityChange(false);
  96. }
  97. /**
  98. * Callback invoked to signal that an event has occurred that should change
  99. * the visibility of the {@code InlineDialog} component.
  100. *
  101. * @private
  102. * @returns {void}
  103. */
  104. _toggleDialogVisibility() {
  105. sendAnalytics(createToolbarEvent('hangup'));
  106. this.props.onVisibilityChange(!this.props.isOpen);
  107. }
  108. }
  109. export default translate(HangupMenuButton);