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.tsx 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import React from 'react';
  2. import { WithTranslation } from 'react-i18next';
  3. import { makeStyles } from 'tss-react/mui';
  4. import { translate } from '../../../i18n/functions';
  5. import Icon from '../../../icons/components/Icon';
  6. import Tooltip from '../../../tooltip/components/Tooltip';
  7. /**
  8. * The type of the React {@code Component} props of {@link BaseIndicator}.
  9. */
  10. interface IProps extends WithTranslation {
  11. /**
  12. * Additional CSS class name.
  13. */
  14. className?: string;
  15. /**
  16. * The icon component to use.
  17. */
  18. icon: Function;
  19. /**
  20. * The CSS classnames to set on the icon element of the component.
  21. */
  22. iconClassName?: string;
  23. /**
  24. * The color of the icon.
  25. */
  26. iconColor?: string;
  27. /**
  28. * Id of the icon to be rendered.
  29. */
  30. iconId?: string;
  31. /**
  32. * The font size for the icon.
  33. */
  34. iconSize: string;
  35. /**
  36. * The ID attribute to set on the root element of the component.
  37. */
  38. id?: string;
  39. /**
  40. * The translation key to use for displaying a tooltip when hovering over
  41. * the component.
  42. */
  43. tooltipKey: string;
  44. /**
  45. * From which side of the indicator the tooltip should appear from,
  46. * defaulting to "top".
  47. */
  48. tooltipPosition: 'top' | 'bottom' | 'left' | 'right';
  49. }
  50. const useStyles = makeStyles()(() => {
  51. return {
  52. indicator: {
  53. display: 'flex',
  54. alignItems: 'center',
  55. justifyContent: 'center'
  56. }
  57. };
  58. });
  59. /**
  60. * React {@code Component} for showing an icon with a tooltip.
  61. *
  62. * @returns {ReactElement}
  63. */
  64. const BaseIndicator = ({
  65. className = '',
  66. icon,
  67. iconClassName,
  68. iconColor,
  69. iconId,
  70. iconSize,
  71. id = '',
  72. t,
  73. tooltipKey,
  74. tooltipPosition = 'top'
  75. }: IProps) => {
  76. const { classes: styles } = useStyles();
  77. const style: any = {};
  78. if (iconSize) {
  79. style.fontSize = iconSize;
  80. }
  81. return (
  82. <div className = { styles.indicator }>
  83. <Tooltip
  84. content = { t(tooltipKey) }
  85. position = { tooltipPosition }>
  86. <span
  87. className = { className }
  88. id = { id }>
  89. <Icon
  90. className = { iconClassName }
  91. color = { iconColor }
  92. id = { iconId }
  93. src = { icon }
  94. style = { style } />
  95. </span>
  96. </Tooltip>
  97. </div>
  98. );
  99. };
  100. export default translate(BaseIndicator);