Commit 58109ec5 by Dominik Prokop Committed by GitHub

Chore: Storybook improvements (#16239)

- Fixed BarGauge story throwing an error
- Added helpers for aligning stories
parent c9e4feda
...@@ -2,7 +2,7 @@ import { storiesOf } from '@storybook/react'; ...@@ -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 = () => { ...@@ -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', () => { ...@@ -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,
......
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 }) => { ...@@ -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 }) => { ...@@ -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}
......
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