diff --git a/packages/grafana-ui/src/components/VizTooltip/HeaderLabel.tsx b/packages/grafana-ui/src/components/VizTooltip/HeaderLabel.tsx
index a7341409a15..07d05347942 100644
--- a/packages/grafana-ui/src/components/VizTooltip/HeaderLabel.tsx
+++ b/packages/grafana-ui/src/components/VizTooltip/HeaderLabel.tsx
@@ -1,95 +1,16 @@
-import { css, cx } from '@emotion/css';
import React from 'react';
-import { GrafanaTheme2 } from '@grafana/data';
-
-import { HorizontalGroup, Tooltip } from '..';
-import { useStyles2 } from '../../themes';
-
+import { VizTooltipRow } from './VizTooltipRow';
import { LabelValue } from './types';
-import { getColorIndicatorClass } from './utils';
interface Props {
headerLabel: LabelValue;
}
export const HeaderLabel = ({ headerLabel }: Props) => {
- const styles = useStyles2(getStyles);
-
const { label, value, color, colorIndicator } = headerLabel;
return (
-
-
- {label}
- {color && (
-
- )}
-
- {value}
-
-
-
+
);
};
-
-const getStyles = (theme: GrafanaTheme2) => ({
- hgContainer: css({
- flexGrow: 1,
- }),
- colorIndicator: css({
- marginRight: theme.spacing(0.5),
- }),
- label: css({
- color: theme.colors.text.secondary,
- paddingRight: theme.spacing(0.5),
- fontWeight: 400,
- }),
- value: css({
- width: '12px',
- height: '12px',
- borderRadius: theme.shape.radius.default,
- }),
- series: css({
- width: '14px',
- height: '4px',
- borderRadius: theme.shape.radius.pill,
- }),
- labelValue: css({
- fontWeight: 500,
- lineHeight: '18px',
- alignSelf: 'center',
- }),
- wrapper: css({
- display: 'flex',
- alignItems: 'center',
- flexDirection: 'row',
- textOverflow: 'ellipsis',
- overflow: 'hidden',
- whiteSpace: 'nowrap',
- width: '250px',
- maskImage: 'linear-gradient(90deg, rgba(0, 0, 0, 1) 80%, transparent)',
- }),
- hexagon: css({}),
- pie_1_4: css({}),
- pie_2_4: css({}),
- pie_3_4: css({}),
- marker_sm: css({
- width: '4px',
- height: '4px',
- borderRadius: theme.shape.radius.circle,
- }),
- marker_md: css({
- width: '8px',
- height: '8px',
- borderRadius: theme.shape.radius.circle,
- }),
- marker_lg: css({
- width: '12px',
- height: '12px',
- borderRadius: theme.shape.radius.circle,
- }),
-});
diff --git a/packages/grafana-ui/src/components/VizTooltip/SeriesList.tsx b/packages/grafana-ui/src/components/VizTooltip/SeriesList.tsx
index fb5e1e28965..bb10422de22 100644
--- a/packages/grafana-ui/src/components/VizTooltip/SeriesList.tsx
+++ b/packages/grafana-ui/src/components/VizTooltip/SeriesList.tsx
@@ -1,12 +1,8 @@
-import { css, cx } from '@emotion/css';
import React from 'react';
-import { GrafanaTheme2, GraphSeriesValue } from '@grafana/data';
+import { GraphSeriesValue } from '@grafana/data';
-import { useStyles2 } from '../../themes';
-import { HorizontalGroup } from '../Layout/Layout';
-
-import { VizTooltipColorIndicator } from './VizTooltipColorIndicator';
+import { VizTooltipRow } from './VizTooltipRow';
import { ColorIndicator } from './types';
export interface SeriesListProps {
@@ -18,13 +14,19 @@ export const SeriesList = ({ series }: SeriesListProps) => {
return (
<>
{series.map((series, index) => {
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
+ const label = series.label as string;
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
+ const value = series.value as string;
return (
-
);
})}
@@ -39,31 +41,3 @@ export interface SingleSeriesProps {
isActive?: boolean;
colorIndicator?: ColorIndicator;
}
-
-const SingleSeries = ({ label, value, color, colorIndicator = ColorIndicator.series, isActive }: SingleSeriesProps) => {
- const styles = useStyles2(getStyles);
-
- return (
-
- <>
- {color && }
- {label && {label}
}
- >
- {value && {value}
}
-
- );
-};
-
-const getStyles = (theme: GrafanaTheme2) => ({
- hgContainer: css({
- flexGrow: 1,
- }),
- activeSeries: css({
- fontWeight: theme.typography.fontWeightBold,
- color: theme.colors.text.maxContrast,
- }),
- label: css({
- color: theme.colors.text.secondary,
- fontWeight: 400,
- }),
-});
diff --git a/packages/grafana-ui/src/components/VizTooltip/VizTooltipColorIndicator.tsx b/packages/grafana-ui/src/components/VizTooltip/VizTooltipColorIndicator.tsx
index 139c10d42e9..bf6d5554ff5 100644
--- a/packages/grafana-ui/src/components/VizTooltip/VizTooltipColorIndicator.tsx
+++ b/packages/grafana-ui/src/components/VizTooltip/VizTooltipColorIndicator.tsx
@@ -35,12 +35,14 @@ const getStyles = (theme: GrafanaTheme2) => ({
width: '14px',
height: '4px',
borderRadius: theme.shape.radius.pill,
+ minWidth: '14px',
}),
value: css({
width: '12px',
height: '12px',
borderRadius: theme.shape.radius.default,
fontWeight: 500,
+ minWidth: '12px',
}),
hexagon: css({}),
pie_1_4: css({}),
@@ -50,15 +52,18 @@ const getStyles = (theme: GrafanaTheme2) => ({
width: '4px',
height: '4px',
borderRadius: theme.shape.radius.circle,
+ minWidth: '4px',
}),
marker_md: css({
width: '8px',
height: '8px',
borderRadius: theme.shape.radius.circle,
+ minWidth: '8px',
}),
marker_lg: css({
width: '12px',
height: '12px',
borderRadius: theme.shape.radius.circle,
+ minWidth: '12px',
}),
});
diff --git a/packages/grafana-ui/src/components/VizTooltip/VizTooltipContent.tsx b/packages/grafana-ui/src/components/VizTooltip/VizTooltipContent.tsx
index 5df6a2f58da..ebd08a5cd28 100644
--- a/packages/grafana-ui/src/components/VizTooltip/VizTooltipContent.tsx
+++ b/packages/grafana-ui/src/components/VizTooltip/VizTooltipContent.tsx
@@ -3,15 +3,16 @@ import React, { ReactElement } from 'react';
import { GrafanaTheme2 } from '@grafana/data';
-import { HorizontalGroup } from '..';
import { useStyles2 } from '../../themes';
+import { VizTooltipRow } from './VizTooltipRow';
import { LabelValue } from './types';
interface Props {
contentLabelValue: LabelValue[];
customContent?: ReactElement | null;
}
+
export const VizTooltipContent = ({ contentLabelValue, customContent }: Props) => {
const styles = useStyles2(getStyles);
@@ -19,11 +20,17 @@ export const VizTooltipContent = ({ contentLabelValue, customContent }: Props) =
{contentLabelValue?.map((labelValue, i) => {
+ const { label, value, color, colorIndicator } = labelValue;
return (
-
- {labelValue.label}
- {labelValue.value}
-
+
);
})}
@@ -44,11 +51,4 @@ const getStyles = (theme: GrafanaTheme2) => ({
customContentPadding: css({
padding: `${theme.spacing(1)} 0`,
}),
- label: css({
- color: theme.colors.text.secondary,
- fontWeight: 400,
- }),
- value: css({
- fontWeight: 500,
- }),
});
diff --git a/packages/grafana-ui/src/components/VizTooltip/VizTooltipHeader.tsx b/packages/grafana-ui/src/components/VizTooltip/VizTooltipHeader.tsx
index 0cfb21a8981..c2e4acb1f76 100644
--- a/packages/grafana-ui/src/components/VizTooltip/VizTooltipHeader.tsx
+++ b/packages/grafana-ui/src/components/VizTooltip/VizTooltipHeader.tsx
@@ -17,17 +17,10 @@ interface Props {
export const VizTooltipHeader = ({ headerLabel, keyValuePairs, customValueDisplay }: Props) => {
const styles = useStyles2(getStyles);
- const renderValue = () => {
- if (customValueDisplay) {
- return customValueDisplay;
- }
-
- return
;
- };
return (
- {renderValue()}
+ {customValueDisplay || }
);
};
diff --git a/packages/grafana-ui/src/components/VizTooltip/VizTooltipHeaderLabelValue.tsx b/packages/grafana-ui/src/components/VizTooltip/VizTooltipHeaderLabelValue.tsx
index 909b60ef7a3..b5efda32c6f 100644
--- a/packages/grafana-ui/src/components/VizTooltip/VizTooltipHeaderLabelValue.tsx
+++ b/packages/grafana-ui/src/components/VizTooltip/VizTooltipHeaderLabelValue.tsx
@@ -1,46 +1,24 @@
-import { css } from '@emotion/css';
import React from 'react';
-import { GrafanaTheme2 } from '@grafana/data';
-
-import { HorizontalGroup } from '..';
-import { useStyles2 } from '../../themes';
-
-import { VizTooltipColorIndicator } from './VizTooltipColorIndicator';
+import { VizTooltipRow } from './VizTooltipRow';
import { LabelValue } from './types';
interface Props {
keyValuePairs?: LabelValue[];
}
-export const VizTooltipHeaderLabelValue = ({ keyValuePairs }: Props) => {
- const styles = useStyles2(getStyles);
-
- return (
- <>
- {keyValuePairs?.map((keyValuePair, i) => {
- return (
-
- {keyValuePair.label}
- <>
- {keyValuePair.color && (
-
- )}
- {keyValuePair.value}
- >
-
- );
- })}
- >
- );
-};
-
-const getStyles = (theme: GrafanaTheme2) => ({
- hgContainer: css({
- flexGrow: 1,
- }),
- label: css({
- color: theme.colors.text.secondary,
- fontWeight: 400,
- }),
-});
+export const VizTooltipHeaderLabelValue = ({ keyValuePairs }: Props) => (
+ <>
+ {keyValuePairs?.map((keyValuePair, i) => (
+
+ ))}
+ >
+);
diff --git a/packages/grafana-ui/src/components/VizTooltip/VizTooltipRow.tsx b/packages/grafana-ui/src/components/VizTooltip/VizTooltipRow.tsx
new file mode 100644
index 00000000000..74dd5de919c
--- /dev/null
+++ b/packages/grafana-ui/src/components/VizTooltip/VizTooltipRow.tsx
@@ -0,0 +1,119 @@
+import { css, cx } from '@emotion/css';
+import React, { useState } from 'react';
+
+import { GrafanaTheme2 } from '@grafana/data';
+
+import { useStyles2 } from '../../themes';
+import { Tooltip } from '../Tooltip';
+
+import { VizTooltipColorIndicator } from './VizTooltipColorIndicator';
+import { LabelValue } from './types';
+
+interface Props extends LabelValue {
+ justify?: string;
+ colorFirst?: boolean;
+ isActive?: boolean; // for series list
+ marginRight?: string;
+}
+
+export const VizTooltipRow = ({
+ label,
+ value,
+ color,
+ colorIndicator,
+ justify = 'flex-start',
+ colorFirst = true,
+ isActive = false,
+ marginRight = '0px',
+}: Props) => {
+ const styles = useStyles2(getStyles, justify, marginRight);
+
+ const [showLabelTooltip, setShowLabelTooltip] = useState(false);
+ const [showValueTooltip, setShowValueTooltip] = useState(false);
+
+ const onMouseEnterLabel = (event: React.MouseEvent
) => {
+ if (event.currentTarget.offsetWidth < event.currentTarget.scrollWidth) {
+ setShowLabelTooltip(true);
+ }
+ };
+
+ const onMouseLeaveLabel = () => setShowLabelTooltip(false);
+
+ const onMouseEnterValue = (event: React.MouseEvent) => {
+ if (event.currentTarget.offsetWidth < event.currentTarget.scrollWidth) {
+ setShowValueTooltip(true);
+ }
+ };
+
+ const onMouseLeaveValue = () => setShowValueTooltip(false);
+
+ return (
+
+ {(color || label) && (
+
+ {color && colorFirst &&
}
+
+
+ {label}
+
+
+
+ )}
+
+
+ {color && !colorFirst &&
}
+
+
+ {value}
+
+
+
+
+ );
+};
+
+const getStyles = (theme: GrafanaTheme2, justify: string, marginRight: string) => ({
+ wrapper: css({
+ display: 'flex',
+ flexDirection: 'column',
+ flex: 1,
+ gap: 4,
+ borderTop: `1px solid ${theme.colors.border.medium}`,
+ padding: theme.spacing(1),
+ }),
+ contentWrapper: css({
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: justify,
+ flexWrap: 'wrap',
+ marginRight: marginRight,
+ }),
+ customContentPadding: css({
+ padding: `${theme.spacing(1)} 0`,
+ }),
+ label: css({
+ color: theme.colors.text.secondary,
+ fontWeight: 400,
+ textOverflow: 'ellipsis',
+ overflow: 'hidden',
+ marginRight: theme.spacing(0.5),
+ }),
+ value: css({
+ fontWeight: 500,
+ textOverflow: 'ellipsis',
+ overflow: 'hidden',
+ }),
+ valueWrapper: css({
+ display: 'flex',
+ alignItems: 'center',
+ minWidth: 0,
+ }),
+ activeSeries: css({
+ fontWeight: theme.typography.fontWeightBold,
+ color: theme.colors.text.maxContrast,
+ }),
+});