From 57592de4b18a0ae8e58871d4fd63fe4754882122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 19 Nov 2020 15:53:49 +0100 Subject: [PATCH] BarGauge: Fix story for BarGauge, caused knobs to show for other stories (#29232) --- .../components/BarGauge/BarGauge.story.tsx | 90 ++++++++++--------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/packages/grafana-ui/src/components/BarGauge/BarGauge.story.tsx b/packages/grafana-ui/src/components/BarGauge/BarGauge.story.tsx index 1a2cef1b990..96238b2daec 100644 --- a/packages/grafana-ui/src/components/BarGauge/BarGauge.story.tsx +++ b/packages/grafana-ui/src/components/BarGauge/BarGauge.story.tsx @@ -1,10 +1,11 @@ +import React from 'react'; import { number, text } from '@storybook/addon-knobs'; import { BarGauge, BarGaugeDisplayMode } from '@grafana/ui'; import { VizOrientation, ThresholdsMode, Field, FieldType, getDisplayProcessor } from '@grafana/data'; import { Props } from './BarGauge'; import { withCenteredStory } from '../../utils/storybook/withCenteredStory'; -import { renderComponentWithTheme } from '../../utils/storybook/withTheme'; import mdx from './BarGauge.mdx'; +import { useTheme } from '../../themes'; const getKnobs = () => { return { @@ -31,51 +32,56 @@ export default { }; function addBarGaugeStory(overrides: Partial) { - const { - value, - title, - minValue, - maxValue, - threshold1Color, - threshold2Color, - threshold1Value, - threshold2Value, - } = getKnobs(); + return () => { + const theme = useTheme(); - const field: Partial = { - type: FieldType.number, - config: { - min: minValue, - max: maxValue, - thresholds: { - mode: ThresholdsMode.Absolute, - steps: [ - { value: -Infinity, color: 'green' }, - { value: threshold1Value, color: threshold1Color }, - { value: threshold2Value, color: threshold2Color }, - ], + const { + value, + title, + minValue, + maxValue, + threshold1Color, + threshold2Color, + threshold1Value, + threshold2Value, + } = getKnobs(); + + const field: Partial = { + type: FieldType.number, + config: { + min: minValue, + max: maxValue, + thresholds: { + mode: ThresholdsMode.Absolute, + steps: [ + { value: -Infinity, color: 'green' }, + { value: threshold1Value, color: threshold1Color }, + { value: threshold2Value, color: threshold2Color }, + ], + }, }, - }, - }; - field.display = getDisplayProcessor({ field }); + }; + field.display = getDisplayProcessor({ field }); - const props: Props = { - theme: {} as any, - width: 300, - height: 300, - value: { - text: value.toString(), - title: title, - numeric: value, - }, - orientation: VizOrientation.Vertical, - displayMode: BarGaugeDisplayMode.Basic, - field: field.config!, - display: field.display!, - }; + const props: Props = { + theme, + width: 300, + height: 300, + value: { + text: value.toString(), + title: title, + numeric: value, + }, + orientation: VizOrientation.Vertical, + displayMode: BarGaugeDisplayMode.Basic, + field: field.config!, + display: field.display!, + }; - Object.assign(props, overrides); - return renderComponentWithTheme(BarGauge, props); + Object.assign(props, overrides); + + return ; + }; } export const gradientVertical = addBarGaugeStory({