Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

HangupMenuButton.tsx 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* eslint-disable lines-around-comment */
  2. import InlineDialog from '@atlaskit/inline-dialog';
  3. import React, { Component } from 'react';
  4. import { WithTranslation } from 'react-i18next';
  5. import { createToolbarEvent } from '../../../analytics/AnalyticsEvents';
  6. import { sendAnalytics } from '../../../analytics/functions';
  7. import { translate } from '../../../base/i18n/functions';
  8. import HangupToggleButton from './HangupToggleButton';
  9. /**
  10. * The type of the React {@code Component} props of {@link HangupMenuButton}.
  11. */
  12. interface Props extends WithTranslation {
  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. /**
  31. * A React {@code Component} for opening or closing the {@code HangupMenu}.
  32. *
  33. * @augments Component
  34. */
  35. class HangupMenuButton extends Component<Props> {
  36. /**
  37. * Initializes a new {@code HangupMenuButton} instance.
  38. *
  39. * @param {Object} props - The read-only properties with which the new
  40. * instance is to be initialized.
  41. */
  42. constructor(props: Props) {
  43. super(props);
  44. // Bind event handlers so they are only bound once per instance.
  45. this._onCloseDialog = this._onCloseDialog.bind(this);
  46. this._toggleDialogVisibility
  47. = this._toggleDialogVisibility.bind(this);
  48. this._onEscClick = this._onEscClick.bind(this);
  49. }
  50. /**
  51. * Click handler for the more actions entries.
  52. *
  53. * @param {KeyboardEvent} event - Esc key click to close the popup.
  54. * @returns {void}
  55. */
  56. _onEscClick(event: KeyboardEvent) {
  57. if (event.key === 'Escape' && this.props.isOpen) {
  58. event.preventDefault();
  59. event.stopPropagation();
  60. this._onCloseDialog();
  61. }
  62. }
  63. /**
  64. * Implements React's {@link Component#render()}.
  65. *
  66. * @inheritdoc
  67. * @returns {ReactElement}
  68. */
  69. render() {
  70. const { children, isOpen } = this.props;
  71. return (
  72. <div className = 'toolbox-button-wth-dialog context-menu'>
  73. <InlineDialog
  74. content = { children }
  75. isOpen = { isOpen }
  76. onClose = { this._onCloseDialog }
  77. placement = 'top-end'>
  78. <HangupToggleButton
  79. customClass = 'hangup-menu-button'
  80. handleClick = { this._toggleDialogVisibility }
  81. isOpen = { isOpen }
  82. onKeyDown = { this._onEscClick } />
  83. </InlineDialog>
  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);