mirror of https://github.com/grafana/grafana.git
				
				
				
			Fix: Make the JSON in JSONCell Tooltip more visible (#26048)
* add white background to tooltip component * remove faulty background * new theme for tooltip * correct colors, remove custom box-shadow * rename theme and add documentation * use useStyles for style memo
This commit is contained in:
		
							parent
							
								
									bbe8cc4c84
								
							
						
					
					
						commit
						7cdbae4ae6
					
				| 
						 | 
				
			
			@ -1,9 +1,11 @@
 | 
			
		|||
import React, { FC } from 'react';
 | 
			
		||||
import { css, cx } from 'emotion';
 | 
			
		||||
import { TableCellProps } from './types';
 | 
			
		||||
import { isString } from 'lodash';
 | 
			
		||||
import { Tooltip } from '../Tooltip/Tooltip';
 | 
			
		||||
import { JSONFormatter } from '../JSONFormatter/JSONFormatter';
 | 
			
		||||
import { isString } from 'lodash';
 | 
			
		||||
import { useStyles } from '../../themes';
 | 
			
		||||
import { TableCellProps } from './types';
 | 
			
		||||
import { GrafanaTheme } from '@grafana/data';
 | 
			
		||||
 | 
			
		||||
export const JSONViewCell: FC<TableCellProps> = props => {
 | 
			
		||||
  const { field, cell, tableStyles } = props;
 | 
			
		||||
| 
						 | 
				
			
			@ -29,7 +31,7 @@ export const JSONViewCell: FC<TableCellProps> = props => {
 | 
			
		|||
  const content = <JSONTooltip value={value} />;
 | 
			
		||||
  return (
 | 
			
		||||
    <div className={cx(txt, tableStyles.tableCell)}>
 | 
			
		||||
      <Tooltip placement="auto" content={content} theme={'info'}>
 | 
			
		||||
      <Tooltip placement="auto" content={content} theme="info-alt">
 | 
			
		||||
        <div className={tableStyles.overflow}>{displayValue}</div>
 | 
			
		||||
      </Tooltip>
 | 
			
		||||
    </div>
 | 
			
		||||
| 
						 | 
				
			
			@ -41,12 +43,19 @@ interface PopupProps {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
const JSONTooltip: FC<PopupProps> = props => {
 | 
			
		||||
  const clazz = css`
 | 
			
		||||
    padding: 10px;
 | 
			
		||||
  `;
 | 
			
		||||
  const styles = useStyles((theme: GrafanaTheme) => {
 | 
			
		||||
    return {
 | 
			
		||||
      container: css`
 | 
			
		||||
        padding: ${theme.spacing.xs};
 | 
			
		||||
      `,
 | 
			
		||||
    };
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <div className={clazz}>
 | 
			
		||||
      <JSONFormatter json={props.value} open={4} />
 | 
			
		||||
    <div className={styles.container}>
 | 
			
		||||
      <div>
 | 
			
		||||
        <JSONFormatter json={props.value} open={4} />
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
  );
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,22 @@
 | 
			
		|||
import { Props } from '@storybook/addon-docs/blocks';
 | 
			
		||||
import { Tooltip } from './Tooltip';
 | 
			
		||||
 | 
			
		||||
# Tooltip
 | 
			
		||||
 | 
			
		||||
## Theme
 | 
			
		||||
There are currently themes available for the Tooltip.
 | 
			
		||||
 | 
			
		||||
- Info
 | 
			
		||||
- Error
 | 
			
		||||
- Info-alt (alternative)
 | 
			
		||||
 | 
			
		||||
### Info
 | 
			
		||||
This is the default theme, usually used in forms to show more information.
 | 
			
		||||
 | 
			
		||||
### Error
 | 
			
		||||
Tooltip with a red background.
 | 
			
		||||
 | 
			
		||||
### Info alternative
 | 
			
		||||
We added this to be able to add a `<JSONFormatter />` in the tooltip.
 | 
			
		||||
 | 
			
		||||
<Props of={Tooltip } />
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,28 @@
 | 
			
		|||
import React from 'react';
 | 
			
		||||
import { select } from '@storybook/addon-knobs';
 | 
			
		||||
import { Tooltip } from './Tooltip';
 | 
			
		||||
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
 | 
			
		||||
import { Button } from '../Button';
 | 
			
		||||
import mdx from '../Tooltip/Tooltip.mdx';
 | 
			
		||||
 | 
			
		||||
export default {
 | 
			
		||||
  title: 'Overlays/Tooltip',
 | 
			
		||||
  component: Tooltip,
 | 
			
		||||
  decorators: [withCenteredStory],
 | 
			
		||||
  parameters: {
 | 
			
		||||
    docs: {
 | 
			
		||||
      page: mdx,
 | 
			
		||||
    },
 | 
			
		||||
  },
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const basic = () => {
 | 
			
		||||
  const VISUAL_GROUP = 'Visual options';
 | 
			
		||||
  // ---
 | 
			
		||||
  const theme = select('Theme', ['info', 'error', 'info-alt'], 'info', VISUAL_GROUP);
 | 
			
		||||
  return (
 | 
			
		||||
    <Tooltip content="This is a tooltip" theme={theme}>
 | 
			
		||||
      <Button>Hover me for Tooltip </Button>
 | 
			
		||||
    </Tooltip>
 | 
			
		||||
  );
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -1,10 +1,10 @@
 | 
			
		|||
import React, { createRef } from 'react';
 | 
			
		||||
import React, { createRef, FC } from 'react';
 | 
			
		||||
import * as PopperJS from 'popper.js';
 | 
			
		||||
import { Popover } from './Popover';
 | 
			
		||||
import { PopoverController, UsingPopperProps } from './PopoverController';
 | 
			
		||||
 | 
			
		||||
export interface TooltipProps extends UsingPopperProps {
 | 
			
		||||
  theme?: 'info' | 'error';
 | 
			
		||||
  theme?: 'info' | 'error' | 'info-alt';
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface PopoverContentProps {
 | 
			
		||||
| 
						 | 
				
			
			@ -13,7 +13,7 @@ export interface PopoverContentProps {
 | 
			
		|||
 | 
			
		||||
export type PopoverContent = string | React.ReactElement<any> | ((props: PopoverContentProps) => JSX.Element);
 | 
			
		||||
 | 
			
		||||
export const Tooltip = ({ children, theme, ...controllerProps }: TooltipProps) => {
 | 
			
		||||
export const Tooltip: FC<TooltipProps> = ({ children, theme, ...controllerProps }: TooltipProps) => {
 | 
			
		||||
  const tooltipTriggerRef = createRef<PopperJS.ReferenceObject>();
 | 
			
		||||
  const popperBackgroundClassName = 'popper__background' + (theme ? ' popper__background--' + theme : '');
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -47,6 +47,10 @@ $popper-margin-from-ref: 5px;
 | 
			
		|||
  &.popper__background--info {
 | 
			
		||||
    @include popper-theme($popover-help-bg, $popover-help-color);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  &.popper__background--info-alt {
 | 
			
		||||
    @include popper-theme($popover-code-bg, $text-color);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.popper__arrow {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -300,6 +300,9 @@ $popover-help-bg: $tooltipBackground;
 | 
			
		|||
$popover-help-color: $text-color;
 | 
			
		||||
$popover-error-bg: $btn-danger-bg;
 | 
			
		||||
 | 
			
		||||
$popover-code-bg: $popover-bg;
 | 
			
		||||
$popover-code-boxshadow: $tooltipShadow;
 | 
			
		||||
 | 
			
		||||
// images
 | 
			
		||||
$checkboxImageUrl: '../img/checkbox.png';
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -293,6 +293,9 @@ $popover-error-bg: $btn-danger-bg;
 | 
			
		|||
$popover-help-bg: $tooltipBackground;
 | 
			
		||||
$popover-help-color: $tooltipColor;
 | 
			
		||||
 | 
			
		||||
$popover-code-bg: ${theme.colors.bg1};
 | 
			
		||||
$popover-code-boxshadow: 0 0 5px $gray60;
 | 
			
		||||
 | 
			
		||||
// images
 | 
			
		||||
$checkboxImageUrl: '../img/checkbox_white.png';
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -302,6 +302,9 @@ $popover-help-bg: $tooltipBackground;
 | 
			
		|||
$popover-help-color: $text-color;
 | 
			
		||||
$popover-error-bg: $btn-danger-bg;
 | 
			
		||||
 | 
			
		||||
$popover-code-bg: $popover-bg;
 | 
			
		||||
$popover-code-boxshadow: $tooltipShadow;
 | 
			
		||||
 | 
			
		||||
// images
 | 
			
		||||
$checkboxImageUrl: '../img/checkbox.png';
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -295,6 +295,9 @@ $popover-error-bg: $btn-danger-bg;
 | 
			
		|||
$popover-help-bg: $tooltipBackground;
 | 
			
		||||
$popover-help-color: $tooltipColor;
 | 
			
		||||
 | 
			
		||||
$popover-code-bg: #ffffff;
 | 
			
		||||
$popover-code-boxshadow: 0 0 5px $gray60;
 | 
			
		||||
 | 
			
		||||
// images
 | 
			
		||||
$checkboxImageUrl: '../img/checkbox_white.png';
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue