diff --git a/packages/grafana-ui/src/components/InfoTooltip/InfoTooltip.story.tsx b/packages/grafana-ui/src/components/InfoTooltip/InfoTooltip.story.internal.tsx similarity index 100% rename from packages/grafana-ui/src/components/InfoTooltip/InfoTooltip.story.tsx rename to packages/grafana-ui/src/components/InfoTooltip/InfoTooltip.story.internal.tsx diff --git a/packages/grafana-ui/src/components/Table/JSONViewCell.tsx b/packages/grafana-ui/src/components/Table/JSONViewCell.tsx index 7784f540413..5e685e1f1eb 100644 --- a/packages/grafana-ui/src/components/Table/JSONViewCell.tsx +++ b/packages/grafana-ui/src/components/Table/JSONViewCell.tsx @@ -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 = props => { const { field, cell, tableStyles } = props; @@ -29,7 +31,7 @@ export const JSONViewCell: FC = props => { const content = ; return (
- +
{displayValue}
@@ -41,12 +43,19 @@ interface PopupProps { } const JSONTooltip: FC = props => { - const clazz = css` - padding: 10px; - `; + const styles = useStyles((theme: GrafanaTheme) => { + return { + container: css` + padding: ${theme.spacing.xs}; + `, + }; + }); + return ( -
- +
+
+ +
); }; diff --git a/packages/grafana-ui/src/components/Tooltip/Tooltip.mdx b/packages/grafana-ui/src/components/Tooltip/Tooltip.mdx new file mode 100644 index 00000000000..7619e069be2 --- /dev/null +++ b/packages/grafana-ui/src/components/Tooltip/Tooltip.mdx @@ -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 `` in the tooltip. + + diff --git a/packages/grafana-ui/src/components/Tooltip/Tooltip.story.tsx b/packages/grafana-ui/src/components/Tooltip/Tooltip.story.tsx new file mode 100644 index 00000000000..3266a58f80c --- /dev/null +++ b/packages/grafana-ui/src/components/Tooltip/Tooltip.story.tsx @@ -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 ( + + + + ); +}; diff --git a/packages/grafana-ui/src/components/Tooltip/Tooltip.tsx b/packages/grafana-ui/src/components/Tooltip/Tooltip.tsx index 4e09a55dbeb..f8c8d5bf5ef 100644 --- a/packages/grafana-ui/src/components/Tooltip/Tooltip.tsx +++ b/packages/grafana-ui/src/components/Tooltip/Tooltip.tsx @@ -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 | ((props: PopoverContentProps) => JSX.Element); -export const Tooltip = ({ children, theme, ...controllerProps }: TooltipProps) => { +export const Tooltip: FC = ({ children, theme, ...controllerProps }: TooltipProps) => { const tooltipTriggerRef = createRef(); const popperBackgroundClassName = 'popper__background' + (theme ? ' popper__background--' + theme : ''); diff --git a/packages/grafana-ui/src/components/Tooltip/_Tooltip.scss b/packages/grafana-ui/src/components/Tooltip/_Tooltip.scss index 8baf0719c42..6b081064d2f 100644 --- a/packages/grafana-ui/src/components/Tooltip/_Tooltip.scss +++ b/packages/grafana-ui/src/components/Tooltip/_Tooltip.scss @@ -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 { diff --git a/packages/grafana-ui/src/themes/_variables.dark.scss.tmpl.ts b/packages/grafana-ui/src/themes/_variables.dark.scss.tmpl.ts index 95e6d8f3646..5c041a629d5 100644 --- a/packages/grafana-ui/src/themes/_variables.dark.scss.tmpl.ts +++ b/packages/grafana-ui/src/themes/_variables.dark.scss.tmpl.ts @@ -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'; diff --git a/packages/grafana-ui/src/themes/_variables.light.scss.tmpl.ts b/packages/grafana-ui/src/themes/_variables.light.scss.tmpl.ts index 9ffb24a5289..f9afca40cea 100644 --- a/packages/grafana-ui/src/themes/_variables.light.scss.tmpl.ts +++ b/packages/grafana-ui/src/themes/_variables.light.scss.tmpl.ts @@ -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'; diff --git a/public/sass/_variables.dark.generated.scss b/public/sass/_variables.dark.generated.scss index 6c622e99f8f..2ed58e47604 100644 --- a/public/sass/_variables.dark.generated.scss +++ b/public/sass/_variables.dark.generated.scss @@ -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'; diff --git a/public/sass/_variables.light.generated.scss b/public/sass/_variables.light.generated.scss index cbe0e219b85..220ee7c82ec 100644 --- a/public/sass/_variables.light.generated.scss +++ b/public/sass/_variables.light.generated.scss @@ -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';