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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 ToolbarButton from './ToolbarButton';
  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. <ToolbarButton
  65. accessibilityLabel = 'Overflow'
  66. iconName = { iconClasses }
  67. onClick = { this._onToggleDialogVisibility }
  68. tooltip = { t('toolbar.moreActions') } />
  69. </InlineDialog>
  70. </div>
  71. );
  72. }
  73. /**
  74. * Callback invoked when {@code InlineDialog} signals that it should be
  75. * close.
  76. *
  77. * @private
  78. * @returns {void}
  79. */
  80. _onCloseDialog() {
  81. this.props.onVisibilityChange(false);
  82. }
  83. /**
  84. * Callback invoked to signal that an event has occurred that should change
  85. * the visibility of the {@code InlineDialog} component.
  86. *
  87. * @private
  88. * @returns {void}
  89. */
  90. _onToggleDialogVisibility() {
  91. this.props.onVisibilityChange(!this.props.isOpen);
  92. }
  93. }
  94. export default translate(OverflowMenuButton);