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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /* eslint-disable lines-around-comment */
  2. import InlineDialog from '@atlaskit/inline-dialog';
  3. import React, { Component } from 'react';
  4. // @ts-ignore
  5. import { createToolbarEvent, sendAnalytics } from '../../../analytics';
  6. // @ts-ignore
  7. import { translate } from '../../../base/i18n';
  8. import HangupToggleButton from './HangupToggleButton';
  9. /**
  10. * The type of the React {@code Component} props of {@link HangupMenuButton}.
  11. */
  12. type Props = {
  13. /**
  14. * ID of the menu that is controlled by this button.
  15. */
  16. ariaControls: String,
  17. /**
  18. * A child React Element to display within {@code InlineDialog}.
  19. */
  20. children: React.ReactNode,
  21. /**
  22. * Whether or not the HangupMenu popover should display.
  23. */
  24. isOpen: boolean,
  25. /**
  26. * Callback to change the visibility of the hangup menu.
  27. */
  28. onVisibilityChange: Function,
  29. /**
  30. * Invoked to obtain translated strings.
  31. */
  32. t: 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<Props> {
  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: Props) {
  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. <InlineDialog
  78. content = { children }
  79. isOpen = { isOpen }
  80. onClose = { this._onCloseDialog }
  81. placement = 'top-end'>
  82. <HangupToggleButton
  83. customClass = 'hangup-menu-button'
  84. handleClick = { this._toggleDialogVisibility }
  85. isOpen = { isOpen }
  86. onKeyDown = { this._onEscClick } />
  87. </InlineDialog>
  88. </div>
  89. );
  90. }
  91. /**
  92. * Callback invoked when {@code InlineDialog} signals that it should be
  93. * close.
  94. *
  95. * @private
  96. * @returns {void}
  97. */
  98. _onCloseDialog() {
  99. this.props.onVisibilityChange(false);
  100. }
  101. /**
  102. * Callback invoked to signal that an event has occurred that should change
  103. * the visibility of the {@code InlineDialog} component.
  104. *
  105. * @private
  106. * @returns {void}
  107. */
  108. _toggleDialogVisibility() {
  109. sendAnalytics(createToolbarEvent('hangup'));
  110. this.props.onVisibilityChange(!this.props.isOpen);
  111. }
  112. }
  113. export default translate(HangupMenuButton);