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.

OverflowMenuButton.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* @flow */
  2. import InlineDialog from '@atlaskit/inline-dialog';
  3. import React, { Component } from 'react';
  4. import { createToolbarEvent, sendAnalytics } from '../../../analytics';
  5. import { translate } from '../../../base/i18n';
  6. import { IconMenuThumb } from '../../../base/icons';
  7. import ToolbarButton from './ToolbarButton';
  8. /**
  9. * The type of the React {@code Component} props of {@link OverflowMenuButton}.
  10. */
  11. type Props = {
  12. /**
  13. * A child React Element to display within {@code InlineDialog}.
  14. */
  15. children: React$Node,
  16. /**
  17. * Whether or not the OverflowMenu popover should display.
  18. */
  19. isOpen: boolean,
  20. /**
  21. * Calback to change the visibility of the overflow menu.
  22. */
  23. onVisibilityChange: Function,
  24. /**
  25. * Invoked to obtain translated strings.
  26. */
  27. t: Function
  28. };
  29. /**
  30. * A React {@code Component} for opening or closing the {@code OverflowMenu}.
  31. *
  32. * @extends Component
  33. */
  34. class OverflowMenuButton extends Component<Props> {
  35. /**
  36. * Initializes a new {@code OverflowMenuButton} instance.
  37. *
  38. * @param {Object} props - The read-only properties with which the new
  39. * instance is to be initialized.
  40. */
  41. constructor(props: Props) {
  42. super(props);
  43. // Bind event handlers so they are only bound once per instance.
  44. this._onCloseDialog = this._onCloseDialog.bind(this);
  45. this._onToggleDialogVisibility
  46. = this._onToggleDialogVisibility.bind(this);
  47. }
  48. /**
  49. * Implements React's {@link Component#render()}.
  50. *
  51. * @inheritdoc
  52. * @returns {ReactElement}
  53. */
  54. render() {
  55. const { children, isOpen, t } = this.props;
  56. return (
  57. <div className = 'toolbox-button-wth-dialog'>
  58. <InlineDialog
  59. content = { children }
  60. isOpen = { isOpen }
  61. onClose = { this._onCloseDialog }
  62. position = { 'top right' }>
  63. <ToolbarButton
  64. accessibilityLabel =
  65. { t('toolbar.accessibilityLabel.moreActions') }
  66. icon = { IconMenuThumb }
  67. onClick = { this._onToggleDialogVisibility }
  68. toggled = { isOpen }
  69. tooltip = { t('toolbar.moreActions') } />
  70. </InlineDialog>
  71. </div>
  72. );
  73. }
  74. _onCloseDialog: () => void;
  75. /**
  76. * Callback invoked when {@code InlineDialog} signals that it should be
  77. * close.
  78. *
  79. * @private
  80. * @returns {void}
  81. */
  82. _onCloseDialog() {
  83. this.props.onVisibilityChange(false);
  84. }
  85. _onToggleDialogVisibility: () => void;
  86. /**
  87. * Callback invoked to signal that an event has occurred that should change
  88. * the visibility of the {@code InlineDialog} component.
  89. *
  90. * @private
  91. * @returns {void}
  92. */
  93. _onToggleDialogVisibility() {
  94. sendAnalytics(createToolbarEvent('overflow'));
  95. this.props.onVisibilityChange(!this.props.isOpen);
  96. }
  97. }
  98. export default translate(OverflowMenuButton);