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

ToolboxItem.web.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // @flow
  2. import Tooltip from '@atlaskit/tooltip';
  3. import React, { Fragment } from 'react';
  4. import AbstractToolboxItem from './AbstractToolboxItem';
  5. import type { Props } from './AbstractToolboxItem';
  6. /**
  7. * Web implementation of {@code AbstractToolboxItem}.
  8. */
  9. export default class ToolboxItem extends AbstractToolboxItem<Props> {
  10. /**
  11. * Handles rendering of the actual item. If the label is being shown, which
  12. * is controlled with the `showLabel` prop, the item is rendered for its
  13. * display in an overflow menu, otherwise it will only have an icon, which
  14. * can be displayed on any toolbar.
  15. *
  16. * @protected
  17. * @returns {ReactElement}
  18. */
  19. _renderItem() {
  20. const {
  21. disabled,
  22. elementAfter,
  23. onClick,
  24. showLabel,
  25. tooltipPosition
  26. } = this.props;
  27. const className = showLabel ? 'overflow-menu-item' : 'toolbox-button';
  28. const props = {
  29. 'aria-label': this.accessibilityLabel,
  30. className: className + (disabled ? ' disabled' : ''),
  31. onClick: disabled ? undefined : onClick
  32. };
  33. const elementType = showLabel ? 'li' : 'div';
  34. const useTooltip = this.tooltip && this.tooltip.length > 0;
  35. // eslint-disable-next-line no-extra-parens
  36. let children = (
  37. <Fragment>
  38. { this._renderIcon() }
  39. { showLabel && <span>
  40. { this.label }
  41. </span> }
  42. { elementAfter }
  43. </Fragment>
  44. );
  45. if (useTooltip) {
  46. // eslint-disable-next-line no-extra-parens
  47. children = (
  48. <Tooltip
  49. content = { this.tooltip }
  50. position = { tooltipPosition }>
  51. { children }
  52. </Tooltip>
  53. );
  54. }
  55. return React.createElement(elementType, props, children);
  56. }
  57. /**
  58. * Helper function to render the item's icon.
  59. *
  60. * @private
  61. * @returns {ReactElement}
  62. */
  63. _renderIcon() {
  64. const { iconName, showLabel } = this.props;
  65. const icon = <i className = { iconName } />;
  66. const elementType = showLabel ? 'span' : 'div';
  67. const className
  68. = showLabel ? 'overflow-menu-item-icon' : 'toolbox-icon';
  69. return React.createElement(elementType, { className }, icon);
  70. }
  71. }