From 2b9c9293152f660009896b95de52643f71df3611 Mon Sep 17 00:00:00 2001 From: Adela Almasan <88068998+adela-almasan@users.noreply.github.com> Date: Tue, 31 Oct 2023 12:07:52 -0500 Subject: [PATCH] Tooltips: Components update (#77410) --- .../src/components/VizTooltip/SeriesList.tsx | 69 +++++++++++++++++++ .../VizTooltip/VizTooltipColorIndicator.tsx | 64 +++++++++++++++++ .../VizTooltip/VizTooltipHeaderLabelValue.tsx | 47 ++----------- .../src/components/VizTooltip/utils.ts | 4 +- 4 files changed, 140 insertions(+), 44 deletions(-) create mode 100644 packages/grafana-ui/src/components/VizTooltip/SeriesList.tsx create mode 100644 packages/grafana-ui/src/components/VizTooltip/VizTooltipColorIndicator.tsx diff --git a/packages/grafana-ui/src/components/VizTooltip/SeriesList.tsx b/packages/grafana-ui/src/components/VizTooltip/SeriesList.tsx new file mode 100644 index 00000000000..fb5e1e28965 --- /dev/null +++ b/packages/grafana-ui/src/components/VizTooltip/SeriesList.tsx @@ -0,0 +1,69 @@ +import { css, cx } from '@emotion/css'; +import React from 'react'; + +import { GrafanaTheme2, GraphSeriesValue } from '@grafana/data'; + +import { useStyles2 } from '../../themes'; +import { HorizontalGroup } from '../Layout/Layout'; + +import { VizTooltipColorIndicator } from './VizTooltipColorIndicator'; +import { ColorIndicator } from './types'; + +export interface SeriesListProps { + series: SingleSeriesProps[]; +} + +// Based on SeriesTable, with new styling +export const SeriesList = ({ series }: SeriesListProps) => { + return ( + <> + {series.map((series, index) => { + return ( + + ); + })} + + ); +}; + +export interface SingleSeriesProps { + color?: string; + label?: React.ReactNode; + value?: string | GraphSeriesValue; + 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 new file mode 100644 index 00000000000..139c10d42e9 --- /dev/null +++ b/packages/grafana-ui/src/components/VizTooltip/VizTooltipColorIndicator.tsx @@ -0,0 +1,64 @@ +import { css, cx } from '@emotion/css'; +import React from 'react'; + +import { GrafanaTheme2 } from '@grafana/data'; + +import { useStyles2 } from '../../themes'; + +import { ColorIndicator } from './types'; +import { getColorIndicatorClass } from './utils'; + +interface Props { + color: string; + colorIndicator: ColorIndicator; +} + +export type ColorIndicatorStyles = ReturnType; + +export const VizTooltipColorIndicator = ({ color, colorIndicator = ColorIndicator.value }: Props) => { + const styles = useStyles2(getStyles); + + return ( + + ); +}; + +// @TODO Update classes/add svgs +const getStyles = (theme: GrafanaTheme2) => ({ + colorIndicator: css({ + marginRight: theme.spacing(0.5), + }), + series: css({ + width: '14px', + height: '4px', + borderRadius: theme.shape.radius.pill, + }), + value: css({ + width: '12px', + height: '12px', + borderRadius: theme.shape.radius.default, + fontWeight: 500, + }), + 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/VizTooltipHeaderLabelValue.tsx b/packages/grafana-ui/src/components/VizTooltip/VizTooltipHeaderLabelValue.tsx index 13d8db31a8c..909b60ef7a3 100644 --- a/packages/grafana-ui/src/components/VizTooltip/VizTooltipHeaderLabelValue.tsx +++ b/packages/grafana-ui/src/components/VizTooltip/VizTooltipHeaderLabelValue.tsx @@ -1,4 +1,4 @@ -import { css, cx } from '@emotion/css'; +import { css } from '@emotion/css'; import React from 'react'; import { GrafanaTheme2 } from '@grafana/data'; @@ -6,15 +6,13 @@ import { GrafanaTheme2 } from '@grafana/data'; import { HorizontalGroup } from '..'; import { useStyles2 } from '../../themes'; +import { VizTooltipColorIndicator } from './VizTooltipColorIndicator'; import { LabelValue } from './types'; -import { getColorIndicatorClass } from './utils'; interface Props { keyValuePairs?: LabelValue[]; } -export type HeaderLabelValueStyles = ReturnType; - export const VizTooltipHeaderLabelValue = ({ keyValuePairs }: Props) => { const styles = useStyles2(getStyles); @@ -25,10 +23,9 @@ export const VizTooltipHeaderLabelValue = ({ keyValuePairs }: Props) => {
{keyValuePair.label}
<> - + {keyValuePair.color && ( + + )} {keyValuePair.value}
@@ -38,46 +35,12 @@ export const VizTooltipHeaderLabelValue = ({ keyValuePairs }: Props) => { ); }; -// @TODO Update classes/add svgs? const getStyles = (theme: GrafanaTheme2) => ({ hgContainer: css({ flexGrow: 1, }), - colorIndicator: css({ - marginRight: theme.spacing(0.5), - }), label: css({ color: theme.colors.text.secondary, fontWeight: 400, }), - series: css({ - width: '14px', - height: '4px', - borderRadius: theme.shape.radius.pill, - }), - value: css({ - width: '12px', - height: '12px', - borderRadius: theme.shape.radius.default, - fontWeight: 500, - }), - 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/utils.ts b/packages/grafana-ui/src/components/VizTooltip/utils.ts index 44f65d28ffa..6a229a3f8c3 100644 --- a/packages/grafana-ui/src/components/VizTooltip/utils.ts +++ b/packages/grafana-ui/src/components/VizTooltip/utils.ts @@ -1,4 +1,4 @@ -import { HeaderLabelValueStyles } from './VizTooltipHeaderLabelValue'; +import { ColorIndicatorStyles } from './VizTooltipColorIndicator'; import { ColorIndicator } from './types'; export const calculateTooltipPosition = ( @@ -42,7 +42,7 @@ export const calculateTooltipPosition = ( return { x, y }; }; -export const getColorIndicatorClass = (colorIndicator: string, styles: HeaderLabelValueStyles) => { +export const getColorIndicatorClass = (colorIndicator: string, styles: ColorIndicatorStyles) => { switch (colorIndicator) { case ColorIndicator.value: return styles.value;