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.web.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 = 'Overflow'
  67. iconName = { iconClasses }
  68. onClick = { this._onToggleDialogVisibility }
  69. tooltip = { t('toolbar.moreActions') } />
  70. </InlineDialog>
  71. </div>
  72. );
  73. }
  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. /**
  85. * Callback invoked to signal that an event has occurred that should change
  86. * the visibility of the {@code InlineDialog} component.
  87. *
  88. * @private
  89. * @returns {void}
  90. */
  91. _onToggleDialogVisibility() {
  92. sendAnalytics(createToolbarEvent('overflow'));
  93. this.props.onVisibilityChange(!this.props.isOpen);
  94. }
  95. }
  96. export default translate(OverflowMenuButton);