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

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