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

HangupMenuButton.tsx 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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, t } = this.props;
  75. return (
  76. <div className = 'toolbox-button-wth-dialog context-menu'>
  77. <Popover
  78. content = { children }
  79. headingLabel = { t('toolbar.accessibilityLabel.hangup') }
  80. onPopoverClose = { this._onCloseDialog }
  81. position = 'top'
  82. trigger = 'click'
  83. visible = { isOpen }>
  84. <HangupToggleButton
  85. buttonKey = 'hangup-menu'
  86. customClass = 'hangup-menu-button'
  87. handleClick = { this._toggleDialogVisibility }
  88. isOpen = { isOpen }
  89. notifyMode = { this.props.notifyMode }
  90. onKeyDown = { this._onEscClick } />
  91. </Popover>
  92. </div>
  93. );
  94. }
  95. /**
  96. * Callback invoked when {@code InlineDialog} signals that it should be
  97. * close.
  98. *
  99. * @private
  100. * @returns {void}
  101. */
  102. _onCloseDialog() {
  103. this.props.onVisibilityChange(false);
  104. }
  105. /**
  106. * Callback invoked to signal that an event has occurred that should change
  107. * the visibility of the {@code InlineDialog} component.
  108. *
  109. * @private
  110. * @returns {void}
  111. */
  112. _toggleDialogVisibility() {
  113. sendAnalytics(createToolbarEvent('hangup'));
  114. this.props.onVisibilityChange(!this.props.isOpen);
  115. }
  116. }
  117. export default translate(HangupMenuButton);