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 { BarGauge } from './BarGauge';
|
||||
import { VizOrientation } from '../../types';
|
||||
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
||||
import { withHorizontallyCenteredStory } from '../../utils/storybook/withCenteredStory';
|
||||
import { renderComponentWithTheme } from '../../utils/storybook/withTheme';
|
||||
|
||||
const getKnobs = () => {
|
||||
@ -23,7 +23,7 @@ const getKnobs = () => {
|
||||
|
||||
const BarGaugeStories = storiesOf('UI/BarGauge/BarGauge', module);
|
||||
|
||||
BarGaugeStories.addDecorator(withCenteredStory);
|
||||
BarGaugeStories.addDecorator(withHorizontallyCenteredStory);
|
||||
|
||||
BarGaugeStories.add('Simple with basic thresholds', () => {
|
||||
const {
|
||||
@ -41,9 +41,9 @@ BarGaugeStories.add('Simple with basic thresholds', () => {
|
||||
} = getKnobs();
|
||||
|
||||
return renderComponentWithTheme(BarGauge, {
|
||||
width: 700,
|
||||
height: 700,
|
||||
value: value,
|
||||
width: 300,
|
||||
height: 300,
|
||||
value: { text: value.toString(), numeric: value },
|
||||
minValue: minValue,
|
||||
maxValue: maxValue,
|
||||
unit: unit,
|
||||
|
@ -1,14 +1,20 @@
|
||||
import React from '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 (
|
||||
<div
|
||||
style={{
|
||||
height: '100vh ',
|
||||
minHeight: '100%',
|
||||
width: '100%',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
alignItems: vertical ? 'center' : 'flex-start',
|
||||
justifyContent: horizontal ? 'center' : 'flex-start',
|
||||
}}
|
||||
>
|
||||
{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 (
|
||||
<div
|
||||
style={{
|
||||
minHeight: '100vh',
|
||||
width: '100%',
|
||||
padding: '20px',
|
||||
display: 'flex',
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
|
Loading…
Reference in New Issue
Block a user