MetaInfoText.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { css } from '@emotion/css';
  2. import React, { memo } from 'react';
  3. import { GrafanaTheme2 } from '@grafana/data';
  4. import { useStyles2 } from '@grafana/ui';
  5. const getStyles = (theme: GrafanaTheme2) => ({
  6. metaContainer: css`
  7. flex: 1;
  8. color: ${theme.colors.text.secondary};
  9. margin-bottom: ${theme.spacing(2)};
  10. min-width: 30%;
  11. display: flex;
  12. flex-wrap: wrap;
  13. `,
  14. metaItem: css`
  15. margin-right: ${theme.spacing(2)};
  16. margin-top: ${theme.spacing(0.5)};
  17. display: flex;
  18. align-items: baseline;
  19. .logs-meta-item__error {
  20. color: ${theme.colors.error.text};
  21. }
  22. `,
  23. metaLabel: css`
  24. margin-right: calc(${theme.spacing(2)} / 2);
  25. font-size: ${theme.typography.bodySmall.fontSize};
  26. font-weight: ${theme.typography.fontWeightMedium};
  27. `,
  28. metaValue: css`
  29. font-family: ${theme.typography.fontFamilyMonospace};
  30. font-size: ${theme.typography.bodySmall.fontSize};
  31. `,
  32. });
  33. export interface MetaItemProps {
  34. label?: string;
  35. value: string | JSX.Element;
  36. }
  37. const MetaInfoItem = memo(function MetaInfoItem(props: MetaItemProps) {
  38. const style = useStyles2(getStyles);
  39. const { label, value } = props;
  40. return (
  41. <div data-testid="meta-info-text-item" className={style.metaItem}>
  42. {label && <span className={style.metaLabel}>{label}:</span>}
  43. <span className={style.metaValue}>{value}</span>
  44. </div>
  45. );
  46. });
  47. interface MetaInfoTextProps {
  48. metaItems: MetaItemProps[];
  49. }
  50. export const MetaInfoText = memo(function MetaInfoText(props: MetaInfoTextProps) {
  51. const style = useStyles2(getStyles);
  52. const { metaItems } = props;
  53. return (
  54. <div className={style.metaContainer} data-testid="meta-info-text">
  55. {metaItems.map((item, index) => (
  56. <MetaInfoItem key={`${index}-${item.label}`} label={item.label} value={item.value} />
  57. ))}
  58. </div>
  59. );
  60. });