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.

BaseIndicator.js 2.4KB

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