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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import InlineDialog from '@atlaskit/inline-dialog';
  2. import PropTypes from 'prop-types';
  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. * A React {@code Component} for opening or closing the {@code OverflowMenu}.
  9. *
  10. * @extends Component
  11. */
  12. class OverflowMenuButton extends Component {
  13. /**
  14. * {@code OverflowMenuButton} component's property types.
  15. *
  16. * @static
  17. */
  18. static propTypes = {
  19. /**
  20. * A child React Element to display within {@code InlineDialog}.
  21. */
  22. children: PropTypes.object,
  23. /**
  24. * Whether or not the OverflowMenu popover should display.
  25. */
  26. isOpen: PropTypes.bool,
  27. /**
  28. * Calback to change the visiblility of the overflow menu.
  29. */
  30. onVisibilityChange: PropTypes.func,
  31. /**
  32. * Invoked to obtain translated strings.
  33. */
  34. t: PropTypes.func
  35. };
  36. /**
  37. * Initializes a new {@code OverflowMenuButton} instance.
  38. *
  39. * @param {Object} props - The read-only properties with which the new
  40. * instance is to be initialized.
  41. */
  42. constructor(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._onToggleDialogVisibility
  47. = this._onToggleDialogVisibility.bind(this);
  48. }
  49. /**
  50. * Implements React's {@link Component#render()}.
  51. *
  52. * @inheritdoc
  53. * @returns {ReactElement}
  54. */
  55. render() {
  56. const { children, isOpen, t } = this.props;
  57. const iconClasses = `icon-thumb-menu ${isOpen ? 'toggled' : ''}`;
  58. return (
  59. <div className = 'toolbox-button-wth-dialog'>
  60. <InlineDialog
  61. content = { children }
  62. isOpen = { isOpen }
  63. onClose = { this._onCloseDialog }
  64. position = { 'top right' }>
  65. <ToolbarButton
  66. accessibilityLabel =
  67. { t('toolbar.accessibilityLabel.moreActions') }
  68. iconName = { iconClasses }
  69. onClick = { this._onToggleDialogVisibility }
  70. tooltip = { t('toolbar.moreActions') } />
  71. </InlineDialog>
  72. </div>
  73. );
  74. }
  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. /**
  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);