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

OverflowMenuItem.js 2.9KB

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