Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Storybook 7 - docs-root does not exists to add dark class #14

Closed
adityapant1286 opened this issue Apr 5, 2023 · 5 comments
Closed

Storybook 7 - docs-root does not exists to add dark class #14

adityapant1286 opened this issue Apr 5, 2023 · 5 comments

Comments

@adityapant1286
Copy link

adityapant1286 commented Apr 5, 2023

Hi @renatomoor,

Thank you for your efforts working on this package.

There is an error observed for Storybook 7. The element to add dark class is null as there is no such element exists with the id docs-root. This errors out when adding dark class.
Changing the background of body element is working, but this is a hack. Please advise.

  • Storybook 7
  • React 18
  • storybook-tailwind-dark-mode 1.0.16

const selector = isInDocs ? '#docs-root' : 'html';

Receiving this error for Docs:

image

@JReinhold
Copy link

@renatomoor the element that had the id docs-root in 6.5, now has the id storybook-docs in 7.0. You could try changing the implementation to that and see if it fixes it. However I would expect it to be a breaking change to this addon, since it would make it only compatible with 7.0, but that's not for me to decide.

The change can be seen here storybookjs/storybook#10638

@renatomoor
Copy link
Owner

@JReinhold @adityapant1286.

@freddyamarante has made the fix and has also released the new version

@adityapant1286
Copy link
Author

Hi @freddyamarante , thank you for fixing it. Not sure it is an issue with storybook 7 or this case is failing.

The controls are showing correct colors for dark and light mode. However, the background color remains white.

Button in light-mode

image

Button in dark-mode

image

Perhaps need to update background color of the body element having .sb-show-main class.

image

preview.ts file for a reference

const preview: Preview = {
  globalTypes: {
    darkMode: {
      defaultValue: true, // Enable dark mode by default on all stories
    }
  },
  parameters: {
    actions: { argTypesRegex: "^on[A-Z].*" },
    controls: {
      matchers: {
        color: /(background|color)$/i,
        date: /Date$/,
      },
    },
    darkMode: {
      current: 'light',
      dark: { ...themes.dark, appBg: '#171717' },
      light: { ...themes.normal, appBg: '#ffffff' }
    },
  },
};

@freddyamarante
Copy link
Collaborator

I'll take a look at it! I also think would be convenient to add a way to input what background color you want, I'll pr soon

@adityapant1286
Copy link
Author

Hi @renatomoor and @freddyamarante, this recent request is closed, would you advise moving to a new issue or mark this to 'open'.

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

No branches or pull requests

4 participants