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.

OverflowMenuItem.js 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import Tooltip from '@atlaskit/tooltip';
  2. import PropTypes from 'prop-types';
  3. import React, { Component } from 'react';
  4. /**
  5. * A React {@code Component} for displaying a link to interact with other
  6. * features of the application.
  7. *
  8. * @extends Component
  9. */
  10. class OverflowMenuItem extends Component {
  11. /**
  12. * Default values for {@code OverflowMenuItem} component's properties.
  13. *
  14. * @static
  15. */
  16. static defaultProps = {
  17. tooltipPosition: 'left',
  18. disabled: false
  19. };
  20. /**
  21. * {@code OverflowMenuItem} component's property types.
  22. *
  23. * @static
  24. */
  25. static propTypes = {
  26. /**
  27. * A succinct description of what the item does. Used by accessibility
  28. * tools and torture tests.
  29. */
  30. accessibilityLabel: PropTypes.string,
  31. /**
  32. * Whether menu item is disabled or not.
  33. */
  34. disabled: PropTypes.bool,
  35. /**
  36. * The icon class to use for displaying an icon before the link text.
  37. */
  38. icon: PropTypes.string,
  39. /**
  40. * The callback to invoke when {@code OverflowMenuItem} is clicked.
  41. */
  42. onClick: PropTypes.func,
  43. /**
  44. * The text to display in the {@code OverflowMenuItem}.
  45. */
  46. text: PropTypes.string,
  47. /**
  48. * The text to display in the tooltip.
  49. */
  50. tooltip: PropTypes.string,
  51. /**
  52. * From which direction the tooltip should appear, relative to the
  53. * button.
  54. */
  55. tooltipPosition: PropTypes.string
  56. };
  57. /**
  58. * Implements React's {@link Component#render()}.
  59. *
  60. * @inheritdoc
  61. * @returns {ReactElement}
  62. */
  63. render() {
  64. let className = 'overflow-menu-item';
  65. className += this.props.disabled ? ' disabled' : '';
  66. return (
  67. <li
  68. aria-label = { this.props.accessibilityLabel }
  69. className = { className }
  70. onClick = { this.props.disabled ? null : this.props.onClick }>
  71. <span className = 'overflow-menu-item-icon'>
  72. <i className = { this.props.icon } />
  73. </span>
  74. { this.props.tooltip
  75. ? <Tooltip
  76. content = { this.props.tooltip }
  77. position = { this.props.tooltipPosition }>
  78. <span>{ this.props.text }</span>
  79. </Tooltip>
  80. : this.props.text }
  81. </li>
  82. );
  83. }
  84. }
  85. export default OverflowMenuItem;