mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Storybook improvements (#16239)
- Fixed BarGauge story throwing an error - Added helpers for aligning stories
This commit is contained in:
parent
c9e4fedaa8
commit
58109ec5ac
@ -2,7 +2,7 @@ import { storiesOf } from '@storybook/react';
|
|||||||
import { number, text, boolean } from '@storybook/addon-knobs';
|
import { number, text, boolean } from '@storybook/addon-knobs';
|
||||||
import { BarGauge } from './BarGauge';
|
import { BarGauge } from './BarGauge';
|
||||||
import { VizOrientation } from '../../types';
|
import { VizOrientation } from '../../types';
|
||||||
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
import { withHorizontallyCenteredStory } from '../../utils/storybook/withCenteredStory';
|
||||||
import { renderComponentWithTheme } from '../../utils/storybook/withTheme';
|
import { renderComponentWithTheme } from '../../utils/storybook/withTheme';
|
||||||
|
|
||||||
const getKnobs = () => {
|
const getKnobs = () => {
|
||||||
@ -23,7 +23,7 @@ const getKnobs = () => {
|
|||||||
|
|
||||||
const BarGaugeStories = storiesOf('UI/BarGauge/BarGauge', module);
|
const BarGaugeStories = storiesOf('UI/BarGauge/BarGauge', module);
|
||||||
|
|
||||||
BarGaugeStories.addDecorator(withCenteredStory);
|
BarGaugeStories.addDecorator(withHorizontallyCenteredStory);
|
||||||
|
|
||||||
BarGaugeStories.add('Simple with basic thresholds', () => {
|
BarGaugeStories.add('Simple with basic thresholds', () => {
|
||||||
const {
|
const {
|
||||||
@ -41,9 +41,9 @@ BarGaugeStories.add('Simple with basic thresholds', () => {
|
|||||||
} = getKnobs();
|
} = getKnobs();
|
||||||
|
|
||||||
return renderComponentWithTheme(BarGauge, {
|
return renderComponentWithTheme(BarGauge, {
|
||||||
width: 700,
|
width: 300,
|
||||||
height: 700,
|
height: 300,
|
||||||
value: value,
|
value: { text: value.toString(), numeric: value },
|
||||||
minValue: minValue,
|
minValue: minValue,
|
||||||
maxValue: maxValue,
|
maxValue: maxValue,
|
||||||
unit: unit,
|
unit: unit,
|
||||||
|
@ -1,14 +1,20 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { RenderFunction } from '@storybook/react';
|
import { RenderFunction } from '@storybook/react';
|
||||||
|
|
||||||
const CenteredStory: React.FunctionComponent<{}> = ({ children }) => {
|
interface CenteredStoryProps {
|
||||||
|
children: React.ReactNode;
|
||||||
|
horizontal?: boolean;
|
||||||
|
vertical?: boolean;
|
||||||
|
}
|
||||||
|
const CenteredStory: React.FunctionComponent<CenteredStoryProps> = ({ horizontal, vertical, children }) => {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
height: '100vh ',
|
minHeight: '100%',
|
||||||
|
width: '100%',
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: vertical ? 'center' : 'flex-start',
|
||||||
justifyContent: 'center',
|
justifyContent: horizontal ? 'center' : 'flex-start',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
@ -16,4 +22,13 @@ const CenteredStory: React.FunctionComponent<{}> = ({ children }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const withCenteredStory = (story: RenderFunction) => <CenteredStory>{story()}</CenteredStory>;
|
export const withNotCenteredStory = (story: RenderFunction) => <CenteredStory>{story()}</CenteredStory>;
|
||||||
|
export const withCenteredStory = (story: RenderFunction) => (
|
||||||
|
<CenteredStory horizontal vertical>
|
||||||
|
{story()}
|
||||||
|
</CenteredStory>
|
||||||
|
);
|
||||||
|
export const withHorizontallyCenteredStory = (story: RenderFunction) => (
|
||||||
|
<CenteredStory horizontal>{story()}</CenteredStory>
|
||||||
|
);
|
||||||
|
export const withVerticallyCenteredStory = (story: RenderFunction) => <CenteredStory vertical>{story()}</CenteredStory>;
|
||||||
|
@ -5,7 +5,10 @@ const PaddedStory: React.FunctionComponent<{}> = ({ children }) => {
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
|
minHeight: '100vh',
|
||||||
|
width: '100%',
|
||||||
padding: '20px',
|
padding: '20px',
|
||||||
|
display: 'flex',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
Loading…
Reference in New Issue
Block a user