-
-
Notifications
You must be signed in to change notification settings - Fork 166
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
Feature Request: Support for storybook #63
Comments
I am also trying to integrate export const decorators = [
(Story, { globals }) => {
return (
<ThemeProvider attribute="class" forcedTheme={globals.theme}>
<Story />
</ThemeProvider>
);
},
];
export const globalTypes = {
theme: {
name: 'Theme',
defaultValue: 'system',
toolbar: {
icon: 'circlehollow',
items: ['light', 'dark', 'system'],
showName: true,
},
},
}; EDIT: It does change the theme, but doesn't apply the class attribute, |
Storybook is not implemented with Next.js. Since the purpose of this library is a clean implementation of theming in Next.js, I doubt storybook support will be a thing. (Considering CRA and Gatsby are out of scope as well) |
In v0.2 we're not using any Next.js specific code anymore, so I'll think about making the library more generic to support Storybook or other frameworks. Definitely low priority though – using next-themes with Next.js will always be the focus. |
I managed to make theme changeable in toolbar in storybook in
and also I added decorator in the same file
And here is
And this is my ColorThemeProvider
Please let me know if it works for you guys Screen.Recording.2022-09-02.at.20.28.25.mov |
This worked for me:
|
I used a combination of the above.
The example from @fede-rodes didn't include a "toolbar switcher" and i grabbed that from @natasha08n example and made some minor changes. Works for me! |
pacocoursey/next-themes#63 に従って追加してみた、こんなに簡単だったとは...
Thanks for the library! It's very well rounded and more polished than what I was doing on my own.
I'm looking to integrate this library with storybook for my application. When I was using my own theme provider example repo here which is heavily based on this blog post which provides the same solution this repo seeks to encapsulate in a library (i.e. inject script into head to run theme logic before first paint), I was able to easily integrate this with storybook globals. I went a step further to allow for stories to declare they want to be rendered with a certain theme by default with the following
preview.js
:I would like to accomplish something similar with this repo. i.e. allow outside code to force the theme and allow a custom version of the set theme function so we can keep the globals in sync.
The context object isn't exported from this repo which would allow me to do all of this (alas, I would have to reimplement the logic to "set" the theme onto the dom unless that logic was also exported).
I tried to get a partial solution by using the
forceTheme
prop on the provider as follows, but that didn't work either. It stayed on light mode even though the global was being reset causing a rerender.Is exporting the context object and dom update logic the best solution or is there a better way to achieve what I'm doing?
Thanks for the help and your time; it's greatly appreciated.
The text was updated successfully, but these errors were encountered: