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

BaseIndicator.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import PropTypes from 'prop-types';
  2. import React, { Component } from 'react';
  3. import Tooltip from '@atlaskit/tooltip';
  4. import { translate } from '../../../base/i18n';
  5. /**
  6. * React {@code Component} for showing an icon with a tooltip.
  7. *
  8. * @extends Component
  9. */
  10. class BaseIndicator extends Component {
  11. /**
  12. * Default values for {@code BaseIndicator} component's properties.
  13. *
  14. * @static
  15. */
  16. static defaultProps = {
  17. className: '',
  18. iconClassName: '',
  19. iconSize: 'auto',
  20. id: '',
  21. tooltipPosition: 'top'
  22. };
  23. /**
  24. * {@code BaseIndicator} component's property types.
  25. *
  26. * @static
  27. */
  28. static propTypes = {
  29. /**
  30. * Additional CSS class names to set on the icon container.
  31. */
  32. className: PropTypes.string,
  33. /**
  34. * The CSS classnames to set on the icon element of the component.
  35. */
  36. iconClassName: PropTypes.string,
  37. /**
  38. * The font size for the icon.
  39. */
  40. iconSize: PropTypes.string,
  41. /**
  42. * The ID attribue to set on the root element of the component.
  43. */
  44. id: PropTypes.string,
  45. /**
  46. * Invoked to obtain translated strings.
  47. */
  48. t: PropTypes.func,
  49. /**
  50. * The translation key to use for displaying a tooltip when hovering
  51. * over the component.
  52. */
  53. tooltipKey: PropTypes.string,
  54. /**
  55. * From which side of the indicator the tooltip should appear from.
  56. * Defaults to "top".
  57. */
  58. tooltipPosition: PropTypes.string
  59. };
  60. /**
  61. * Implements React's {@link Component#render()}.
  62. *
  63. * @inheritdoc
  64. * @returns {ReactElement}
  65. */
  66. render() {
  67. const {
  68. className,
  69. iconClassName,
  70. iconSize,
  71. id,
  72. t,
  73. tooltipKey,
  74. tooltipPosition
  75. } = this.props;
  76. const iconContainerClassName = `indicator-icon-container ${className}`;
  77. return (
  78. <div className = 'indicator-container'>
  79. <Tooltip
  80. description = { t(tooltipKey) }
  81. position = { tooltipPosition }>
  82. <span
  83. className = { iconContainerClassName }
  84. id = { id }>
  85. <i
  86. className = { iconClassName }
  87. style = {{ fontSize: iconSize }} />
  88. </span>
  89. </Tooltip>
  90. </div>
  91. );
  92. }
  93. }
  94. export default translate(BaseIndicator);