您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

OverflowMenuItem.web.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // @flow
  2. import Tooltip from '@atlaskit/tooltip';
  3. import React, { Component } from 'react';
  4. import { Icon } from '../../icons';
  5. /**
  6. * The type of the React {@code Component} props of {@link OverflowMenuItem}.
  7. */
  8. type Props = {
  9. /**
  10. * A succinct description of what the item does. Used by accessibility tools
  11. * and torture tests.
  12. */
  13. accessibilityLabel: string,
  14. /**
  15. * Whether menu item is disabled or not.
  16. */
  17. disabled: boolean,
  18. /**
  19. * A React Element to display at the end of {@code OverflowMenuItem}.
  20. */
  21. elementAfter?: React$Node,
  22. /**
  23. * The icon class to use for displaying an icon before the link text.
  24. */
  25. icon: Object,
  26. /**
  27. * Id of the icon to be rendered.
  28. */
  29. iconId?: string,
  30. /**
  31. * The callback to invoke when {@code OverflowMenuItem} is clicked.
  32. */
  33. onClick: Function,
  34. /**
  35. * The text to display in the {@code OverflowMenuItem}.
  36. */
  37. text: string,
  38. /**
  39. * The text to display in the tooltip.
  40. */
  41. tooltip?: string,
  42. /**
  43. * From which direction the tooltip should appear, relative to the button.
  44. */
  45. tooltipPosition: string
  46. };
  47. /**
  48. * A React {@code Component} for displaying a link to interact with other
  49. * features of the application.
  50. *
  51. * @extends Component
  52. */
  53. class OverflowMenuItem extends Component<Props> {
  54. /**
  55. * Default values for {@code OverflowMenuItem} component's properties.
  56. *
  57. * @static
  58. */
  59. static defaultProps = {
  60. tooltipPosition: 'left',
  61. disabled: false
  62. };
  63. /**
  64. * Implements React's {@link Component#render()}.
  65. *
  66. * @inheritdoc
  67. * @returns {ReactElement}
  68. */
  69. render() {
  70. const { accessibilityLabel, disabled, elementAfter, icon, iconId, onClick } = this.props;
  71. let className = 'overflow-menu-item';
  72. className += this.props.disabled ? ' disabled' : '';
  73. return (
  74. <li
  75. aria-label = { accessibilityLabel }
  76. className = { className }
  77. onClick = { disabled ? null : onClick }>
  78. <span className = 'overflow-menu-item-icon'>
  79. <Icon
  80. id = { iconId }
  81. src = { icon } />
  82. </span>
  83. { this._renderText() }
  84. {
  85. elementAfter || null
  86. }
  87. </li>
  88. );
  89. }
  90. /**
  91. * Renders the text label to display in the {@code OverflowMenuItem}.
  92. *
  93. * @private
  94. * @returns {ReactElement}
  95. */
  96. _renderText() {
  97. const textElement = (
  98. <span className = 'overflow-menu-item-text'>
  99. { this.props.text }
  100. </span>
  101. );
  102. if (this.props.tooltip) {
  103. return (
  104. <Tooltip
  105. content = { this.props.tooltip }
  106. position = { this.props.tooltipPosition }>
  107. { textElement }
  108. </Tooltip>
  109. );
  110. }
  111. return textElement;
  112. }
  113. }
  114. export default OverflowMenuItem;