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

Default theme always resets to configured value #179

Closed
thany opened this issue Feb 25, 2022 · 2 comments
Closed

Default theme always resets to configured value #179

thany opened this issue Feb 25, 2022 · 2 comments

Comments

@thany
Copy link

thany commented Feb 25, 2022

I added a default theme:

export const parameters = {
  darkMode: {
    // ...
    current: 'light',
  },
};

This causes the theme to reset to light every time when selecting another story.

This is incorrect when considering the documention:

Order of precedence for the initial color scheme:

  1. If the user has previously set a color theme it's used
  2. The value you have configured for current parameter in your storybook
  3. The OS color scheme preference

So, a previously set theme by the user should take precedence. And it'd make perfect sense if it did that.

@Develonaut
Copy link
Contributor

Develonaut commented Jul 13, 2022

I think this issue is in this hook: https://github.com/hipstersmoothie/storybook-dark-mode/blob/master/src/Tool.tsx#L181

The current value set in the store is being overwritten with the default that was defined in the parameters. I think it needs to be updated to prefer the store's current and fallback to the params current.

updateStore({
  ...currentStore,
  ...darkModeParams,
  current: currentStore.current || darkModeParams.current,
});

I went ahead and made a PR for the change after testing it locally and having the theme persist between refreshing and story changes: #185

@hipstersmoothie
Copy link
Owner

Gonna close this since a pr was submitted to fix. if it persists feel free to create another PR

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

No branches or pull requests

3 participants