diff --git a/packages/grafana-ui/.storybook/preview.ts b/packages/grafana-ui/.storybook/preview.ts index 2154daf4682..b6afd8eda56 100644 --- a/packages/grafana-ui/.storybook/preview.ts +++ b/packages/grafana-ui/.storybook/preview.ts @@ -9,7 +9,6 @@ import '../../../public/vendor/flot/jquery.flot.crosshair'; import '../../../public/vendor/flot/jquery.flot.dashes'; import '../../../public/vendor/flot/jquery.flot.gauge'; import { withTheme } from '../src/utils/storybook/withTheme'; -import { withPaddedStory } from '../src/utils/storybook/withPaddedStory'; // @ts-ignore import lightTheme from '../../../public/sass/grafana.light.scss'; // @ts-ignore @@ -33,7 +32,7 @@ addons.setConfig({ theme: GrafanaDark, }); -export const decorators = [withTheme(handleThemeChange), withPaddedStory]; +export const decorators = [withTheme(handleThemeChange)]; export const parameters = { docs: { diff --git a/packages/grafana-ui/src/components/CallToActionCard/CallToActionCard.story.internal.tsx b/packages/grafana-ui/src/components/CallToActionCard/CallToActionCard.story.internal.tsx index fbda207d29b..edeeebc0f07 100644 --- a/packages/grafana-ui/src/components/CallToActionCard/CallToActionCard.story.internal.tsx +++ b/packages/grafana-ui/src/components/CallToActionCard/CallToActionCard.story.internal.tsx @@ -1,5 +1,4 @@ import React from 'react'; -import { renderComponentWithTheme } from '../../utils/storybook/withTheme'; import { CallToActionCard, CallToActionCardProps } from './CallToActionCard'; import { Story, Meta } from '@storybook/react'; import { Button } from '../Button/Button'; @@ -37,11 +36,9 @@ export const Basic: Story = (args) => { ), }; - return renderComponentWithTheme(CallToActionCard, { - message: args.message, - callToActionElement: ctaElements[args.Element], - footer: args.footer, - }); + return ( + + ); }; Basic.args = { diff --git a/packages/grafana-ui/src/components/CallToActionCard/CallToActionCard.test.tsx b/packages/grafana-ui/src/components/CallToActionCard/CallToActionCard.test.tsx index afd3d6c87e5..633902d32df 100644 --- a/packages/grafana-ui/src/components/CallToActionCard/CallToActionCard.test.tsx +++ b/packages/grafana-ui/src/components/CallToActionCard/CallToActionCard.test.tsx @@ -1,32 +1,27 @@ -import React, { useContext } from 'react'; +import React from 'react'; import { render } from 'enzyme'; -import { CallToActionCard, CallToActionCardProps } from './CallToActionCard'; -import { ThemeContext } from '../../themes'; - -type Omit = Pick>; - -const TestRenderer = (props: Omit) => { - const theme = useContext(ThemeContext); - return ; -}; +import { CallToActionCard } from './CallToActionCard'; describe('CallToActionCard', () => { describe('rendering', () => { it('when no message and footer provided', () => { - const tree = render(Click me} />); + const tree = render(Click me} />); expect(tree).toMatchSnapshot(); }); it('when message and no footer provided', () => { const tree = render( - Click me} /> + Click me} + /> ); expect(tree).toMatchSnapshot(); }); it('when message and footer provided', () => { const tree = render( - Click me} diff --git a/packages/grafana-ui/src/components/CallToActionCard/CallToActionCard.tsx b/packages/grafana-ui/src/components/CallToActionCard/CallToActionCard.tsx index f377cb0059e..2756499c8b2 100644 --- a/packages/grafana-ui/src/components/CallToActionCard/CallToActionCard.tsx +++ b/packages/grafana-ui/src/components/CallToActionCard/CallToActionCard.tsx @@ -1,17 +1,33 @@ import React from 'react'; -import { Themeable } from '../../types/theme'; import { GrafanaTheme } from '@grafana/data'; import { css, cx } from '@emotion/css'; -import { stylesFactory } from '../../themes'; +import { useStyles } from '../../themes/ThemeContext'; -export interface CallToActionCardProps extends Themeable { +export interface CallToActionCardProps { message?: string | JSX.Element; callToActionElement: JSX.Element; footer?: string | JSX.Element; className?: string; } -const getCallToActionCardStyles = stylesFactory((theme: GrafanaTheme) => ({ +export const CallToActionCard: React.FunctionComponent = ({ + message, + callToActionElement, + footer, + className, +}) => { + const css = useStyles(getStyles); + + return ( +
+ {message &&
{message}
} + {callToActionElement} + {footer &&
{footer}
} +
+ ); +}; + +const getStyles = (theme: GrafanaTheme) => ({ wrapper: css` label: call-to-action-card; padding: ${theme.spacing.lg}; @@ -30,22 +46,4 @@ const getCallToActionCardStyles = stylesFactory((theme: GrafanaTheme) => ({ footer: css` margin-top: ${theme.spacing.lg}; `, -})); - -export const CallToActionCard: React.FunctionComponent = ({ - message, - callToActionElement, - footer, - theme, - className, -}) => { - const css = getCallToActionCardStyles(theme); - - return ( -
- {message &&
{message}
} - {callToActionElement} - {footer &&
{footer}
} -
- ); -}; +}); diff --git a/packages/grafana-ui/src/utils/storybook/withPaddedStory.tsx b/packages/grafana-ui/src/utils/storybook/withPaddedStory.tsx deleted file mode 100644 index 8e6dfc02184..00000000000 --- a/packages/grafana-ui/src/utils/storybook/withPaddedStory.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import React from 'react'; -import { GlobalStyles, useTheme } from '../../themes'; -import { RenderFunction } from '../../types'; - -const PaddedStory: React.FunctionComponent<{}> = ({ children }) => { - const theme = useTheme(); - - return ( -
- - {children} -
- ); -}; - -export const withPaddedStory = (story: RenderFunction) => {story()}; diff --git a/packages/grafana-ui/src/utils/storybook/withTheme.tsx b/packages/grafana-ui/src/utils/storybook/withTheme.tsx index bb706ebe1b6..19413585d8a 100644 --- a/packages/grafana-ui/src/utils/storybook/withTheme.tsx +++ b/packages/grafana-ui/src/utils/storybook/withTheme.tsx @@ -1,20 +1,38 @@ import React from 'react'; import { ThemeContext } from '../../themes/ThemeContext'; -import { getTheme } from '../../themes/index'; +import { getTheme, GlobalStyles } from '../../themes/index'; import { GrafanaThemeType } from '@grafana/data'; import { RenderFunction } from '../../types'; import { useDarkMode } from 'storybook-dark-mode'; type SassThemeChangeHandler = (theme: GrafanaThemeType) => void; + const ThemeableStory: React.FunctionComponent<{ handleSassThemeChange: SassThemeChangeHandler }> = ({ children, handleSassThemeChange, }) => { - const theme = useDarkMode() ? GrafanaThemeType.Dark : GrafanaThemeType.Light; + const themeType = useDarkMode() ? GrafanaThemeType.Dark : GrafanaThemeType.Light; - handleSassThemeChange(theme); + handleSassThemeChange(themeType); - return {children}; + const theme = getTheme(themeType); + + return ( + +
+ + {children} +
+
+ ); }; // Temporary solution. When we update to Storybook V5 we will be able to pass data from decorator to story diff --git a/public/app/core/components/EmptyListCTA/EmptyListCTA.tsx b/public/app/core/components/EmptyListCTA/EmptyListCTA.tsx index e47f617d219..84177721900 100644 --- a/public/app/core/components/EmptyListCTA/EmptyListCTA.tsx +++ b/public/app/core/components/EmptyListCTA/EmptyListCTA.tsx @@ -1,6 +1,6 @@ -import React, { MouseEvent, useContext } from 'react'; +import React, { MouseEvent } from 'react'; import { css } from '@emotion/css'; -import { CallToActionCard, Icon, IconName, LinkButton, ThemeContext } from '@grafana/ui'; +import { CallToActionCard, Icon, IconName, LinkButton } from '@grafana/ui'; import { selectors } from '@grafana/e2e-selectors'; export interface Props { @@ -39,8 +39,6 @@ const EmptyListCTA: React.FunctionComponent = ({ infoBox, infoBoxTitle, }) => { - const theme = useContext(ThemeContext); - const footer = () => { return ( <> @@ -86,15 +84,7 @@ const EmptyListCTA: React.FunctionComponent = ({ ); - return ( - - ); + return ; }; export default EmptyListCTA; diff --git a/public/app/features/explore/NoDataSourceCallToAction.tsx b/public/app/features/explore/NoDataSourceCallToAction.tsx index 5127131fd4f..10ae00371f9 100644 --- a/public/app/features/explore/NoDataSourceCallToAction.tsx +++ b/public/app/features/explore/NoDataSourceCallToAction.tsx @@ -35,12 +35,6 @@ export const NoDataSourceCallToAction = () => { `; return ( - + ); };