Commit 1f66b5c7 by Uchechukwu Obasi Committed by GitHub

Chart/Tooltip: refactored style declaration (#30824)

* Chart/Tooltip: added theme variables and refactored style declaration

* added some changes

* removed useStyle hook since we're not using themes variables

* Added useStyle back since it memoizes the style generation
parent ef589bd4
...@@ -4,6 +4,7 @@ import { Portal } from '../Portal/Portal'; ...@@ -4,6 +4,7 @@ import { Portal } from '../Portal/Portal';
import { Dimensions, TimeZone } from '@grafana/data'; import { Dimensions, TimeZone } from '@grafana/data';
import { FlotPosition } from '../Graph/types'; import { FlotPosition } from '../Graph/types';
import { TooltipContainer } from './TooltipContainer'; import { TooltipContainer } from './TooltipContainer';
import { useStyles } from '../../themes';
export type TooltipMode = 'single' | 'multi' | 'none'; export type TooltipMode = 'single' | 'multi' | 'none';
...@@ -46,18 +47,10 @@ export interface TooltipProps { ...@@ -46,18 +47,10 @@ export interface TooltipProps {
} }
export const Tooltip: React.FC<TooltipProps> = ({ content, position, offset }) => { export const Tooltip: React.FC<TooltipProps> = ({ content, position, offset }) => {
const styles = useStyles(getStyles);
if (position) { if (position) {
return ( return (
<Portal <Portal className={styles.portal}>
className={css`
position: absolute;
top: 0;
left: 0;
pointer-events: none;
width: 100%;
height: 100%;
`}
>
<TooltipContainer position={position} offset={offset || { x: 0, y: 0 }}> <TooltipContainer position={position} offset={offset || { x: 0, y: 0 }}>
{content} {content}
</TooltipContainer> </TooltipContainer>
...@@ -68,3 +61,16 @@ export const Tooltip: React.FC<TooltipProps> = ({ content, position, offset }) = ...@@ -68,3 +61,16 @@ export const Tooltip: React.FC<TooltipProps> = ({ content, position, offset }) =
}; };
Tooltip.displayName = 'ChartTooltip'; Tooltip.displayName = 'ChartTooltip';
const getStyles = () => {
return {
portal: css`
position: absolute;
top: 0;
left: 0;
pointer-events: none;
width: 100%;
height: 100%;
`,
};
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment