Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit dark mode event via addons channel #1

Closed
pveyes opened this issue Mar 8, 2019 · 3 comments · Fixed by #2
Closed

Emit dark mode event via addons channel #1

pveyes opened this issue Mar 8, 2019 · 3 comments · Fixed by #2

Comments

@pveyes
Copy link
Contributor

pveyes commented Mar 8, 2019

This way we can integrate storybook dark mode with custom theme provider by creating custom decorator. We can do this by adding callback after setState in https://github.com/hipstersmoothie/storybook-dark-mode/blob/master/src/Tool.tsx#L37 by calling channel.emit('DARK_MODE', isDark)

I can create the PR if you want

Example usage

const channel = addons.getChannel();

function ThemeWrapper(props) {
  const [dark, setDark] = useState(false);
  useEffect(() => {
    channel.on('DARK_MODE', setDark)
  });

 return (
    <ThemeProvider value={isDark ? darkTheme : defaultTheme}>
      {props.children}
    </ThemeProvider>
  );
}

addDecorator(renderStory => <ThemeWrapper>{renderStory()}</ThemeWrapper>)
@hipstersmoothie
Copy link
Owner

Make a PR 😄 So this is for rendering your story in dark mode as well? Interesting use case. I like it! Make sure to add some docs to the Readme too

@hipstersmoothie
Copy link
Owner

Would it make sense to also expose the ThemeWrapper decorator too? Or maybe this is too dependent upon what styles framework they use. Docs might be sufficient then

@pveyes
Copy link
Contributor Author

pveyes commented Mar 8, 2019

@hipstersmoothie in our case we have custom ThemeProvider because we don't use emotion. I think it's safer not to include the decorator because usually custom theme is too coupled with the framework that the users use

PR ready. Not sure how to test this in the PR but I already have a fork that works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants