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 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import InlineDialog from '@atlaskit/inline-dialog';
  2. import PropTypes from 'prop-types';
  3. import React, { Component } from 'react';
  4. import { translate } from '../../base/i18n';
  5. import ToolbarButtonV2 from './ToolbarButtonV2';
  6. /**
  7. * A React {@code Component} for opening or closing the {@code OverflowMenu}.
  8. *
  9. * @extends Component
  10. */
  11. class OverflowMenuButton extends Component {
  12. /**
  13. * {@code OverflowMenuButton} component's property types.
  14. *
  15. * @static
  16. */
  17. static propTypes = {
  18. /**
  19. * A child React Element to display within {@code InlineDialog}.
  20. */
  21. children: PropTypes.object,
  22. /**
  23. * Whether or not the OverflowMenu popover should display.
  24. */
  25. isOpen: PropTypes.bool,
  26. /**
  27. * Calback to change the visiblility of the overflow menu.
  28. */
  29. onVisibilityChange: PropTypes.func,
  30. /**
  31. * Invoked to obtain translated strings.
  32. */
  33. t: PropTypes.func
  34. };
  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) {
  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. const iconClasses = `icon-thumb-menu ${isOpen ? 'toggled' : ''}`;
  57. return (
  58. <div className = 'toolbox-button-wth-dialog'>
  59. <InlineDialog
  60. content = { children }
  61. isOpen = { isOpen }
  62. onClose = { this._onCloseDialog }
  63. position = { 'top right' }>
  64. <ToolbarButtonV2
  65. iconName = { iconClasses }
  66. onClick = { this._onToggleDialogVisibility }
  67. tooltip = { t('toolbar.moreActions') } />
  68. </InlineDialog>
  69. </div>
  70. );
  71. }
  72. /**
  73. * Callback invoked when {@code InlineDialog} signals that it should be
  74. * close.
  75. *
  76. * @private
  77. * @returns {void}
  78. */
  79. _onCloseDialog() {
  80. this.props.onVisibilityChange(false);
  81. }
  82. /**
  83. * Callback invoked to signal that an event has occurred that should change
  84. * the visibility of the {@code InlineDialog} component.
  85. *
  86. * @private
  87. * @returns {void}
  88. */
  89. _onToggleDialogVisibility() {
  90. this.props.onVisibilityChange(!this.props.isOpen);
  91. }
  92. }
  93. export default translate(OverflowMenuButton);