From 36aeb9b9a19cac411ecaffd70deeb069a92c94a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 22 Apr 2021 12:24:48 +0200 Subject: [PATCH] PanelChrome: Restore previous panel chrome story (#33258) * PanelChrome: Restore previous panel chrome story * Update story name --- .../PanelChrome/PanelChrome.story.tsx | 164 ++++++++++-------- 1 file changed, 87 insertions(+), 77 deletions(-) diff --git a/packages/grafana-ui/src/components/PanelChrome/PanelChrome.story.tsx b/packages/grafana-ui/src/components/PanelChrome/PanelChrome.story.tsx index 71341560718..dab30b5d7c6 100644 --- a/packages/grafana-ui/src/components/PanelChrome/PanelChrome.story.tsx +++ b/packages/grafana-ui/src/components/PanelChrome/PanelChrome.story.tsx @@ -1,93 +1,103 @@ -import React, { useState } from 'react'; -import { withCenteredStory, withHorizontallyCenteredStory } from '../../utils/storybook/withCenteredStory'; +import React, { CSSProperties, useState } from 'react'; +import { withCenteredStory } from '../../utils/storybook/withCenteredStory'; +import { PanelChrome, useTheme, PanelChromeProps } from '@grafana/ui'; +import { HorizontalGroup, VerticalGroup } from '../Layout/Layout'; +import { merge } from 'lodash'; +import { GrafanaTheme } from '@grafana/data'; import { useInterval } from 'react-use'; -import { PanelChrome, PanelPadding } from './PanelChrome'; -import { LoadingIndicator } from './LoadingIndicator'; -import { ErrorIndicator } from './ErrorIndicator'; -import { useTheme } from '../../themes/ThemeContext'; export default { title: 'Visualizations/PanelChrome', component: PanelChrome, - decorators: [withCenteredStory, withHorizontallyCenteredStory], + decorators: [withCenteredStory], parameters: { docs: {}, }, - argTypes: { - leftItems: { - control: { - type: 'multi-select', - options: ['none', 'loading', 'error'], - }, - }, - width: { - table: { - disable: true, - }, - }, - height: { - table: { - disable: true, - }, - }, - }, }; -type PanelChromeStoryProps = { - leftItems: string[]; - title: string | undefined; - padding: PanelPadding; -}; +function renderPanel(name: string, overrides: Partial, theme: GrafanaTheme) { + const props: PanelChromeProps = { + width: 400, + height: 130, + title: 'Default title', + children: () => undefined, + }; -export const StandardPanel = (props: PanelChromeStoryProps) => { - const theme = useTheme(); - const leftItems = mapToItems(props.leftItems); + merge(props, overrides); + + const contentStyle: CSSProperties = { + background: theme.colors.bg2, + display: 'flex', + alignItems: 'center', + justifyContent: 'center', + }; return ( -
- - {(innerWidth, innerHeight) => { - return ( -
- ); - }} -
+ + {(innerWidth, innerHeight) => { + return
{name}
; + }} +
+ ); +} + +export const Examples = () => { + const theme = useTheme(); + const [loading, setLoading] = useState(true); + + useInterval(() => setLoading(true), 5000); + + return ( +
+ + + {renderPanel('Default panel', {}, theme)} + {renderPanel('No padding', { padding: 'none' }, theme)} + + + {renderPanel('No title', { title: '' }, theme)} + {renderPanel( + 'Very long title', + { title: 'Very long title that should get ellipsis when there is no more space' }, + theme + )} + + +
+ + + {renderPanel( + 'No title and loading indicator', + { + title: '', + leftItems: [ + setLoading(false)} + key="loading-indicator" + />, + ], + }, + theme + )} + + + {renderPanel( + 'Very long title', + { + title: 'Very long title that should get ellipsis when there is no more space', + leftItems: [ + setLoading(false)} + key="loading-indicator" + />, + ], + }, + theme + )} + +
); }; - -StandardPanel.args = { - leftItems: ['none'], - title: 'Very long title that should get ellipsis when there is no more space', -}; - -const LoadingItem = () => { - const [loading, setLoading] = useState(true); - useInterval(() => setLoading(true), 5000); - - return setLoading(false)} />; -}; - -const mapToItems = (selected: string[]): React.ReactNode[] => { - return selected.map((s) => { - switch (s) { - case 'loading': - return ; - case 'error': - return {}} />; - default: - return null; - } - }); -};