question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

addon question: theming in preview

See original GitHub issue

Hi there,

Is there a way to render components such as Button from import {Button} from l'@storybook/components' inside of the preview? Right now I get errors like this:

Button.js:61 Uncaught TypeError: Cannot read property 'size' of undefined
    at push../node_modules/@storybook/components/dist/Button/Button.js.ButtonWrapper.withComponent.target (Button.js:61)

Minimum use case:

import React from 'react';
import { Button } from '@storybook/components';

export default {
  title: 'Button',
};

export const button = () => <Button>Test</Button>;

The issue is that the theme is not being populated. Is there a component I should be wrapping the Button inside of for the preview to have the theme populated?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
alexreardoncommented, Apr 22, 2020

I ended up with this for anyone who needs it:

import { convert, createGlobal, Global, Theme, ThemeProvider, themes } from '@storybook/theming';
import React from 'react';

export default function WithStorybookTheme({
  children,
  mode = 'normal',
}: {
  children: React.ReactNode;
  mode?: 'normal' | 'dark';
}) {
  const theme: Theme = convert(mode === 'dark' ? themes.dark : themes.normal);

  return (
    <>
      <ThemeProvider theme={theme}>
        <Global styles={createGlobal(theme)} />
        {children}
      </ThemeProvider>
    </>
  );
}
0reactions
stale[bot]commented, Jun 12, 2020

Hey there, it’s me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

Read more comments on GitHub >

github_iconTop Results From Across the Web

configure storybook docs addon to display theme.dark
I've been stuck on the same problem for a while, but the solution was in the doc all along: //.storybook/preview.js import { themes...
Read more >
Topic List Previews Theme Component - Discourse Meta
Topic List Previews Theme Component · 'actions' (bookmarking, linking and liking from Topic List) · Thumbnail Picker in the Topic Meta Editor. ( ......
Read more >
Theme Switcha – WordPress plugin
Preview any theme privately on the front-end. Develop themes privately behind the scenes. Enable your visitors to switch themes.
Read more >
Question mark – Get this Theme for Firefox (en-CA) - Firefox Add-ons
Download Question mark for Firefox. ... Search. Search. Preview of Question mark. Question mark by Nguyễn Tiến Đạt. You'll need Firefox to use...
Read more >
Question regarding themes - PrestaShop Forums
February 11, 2009 in Addons, modules and themes developers. Share ... I have also downloaded a theme that I liked and the preview.jpg...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found