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

ThemeProvider decorator not affecting stories in docs page #14477

Closed
hazem3500 opened this issue Apr 5, 2021 · 7 comments
Closed

ThemeProvider decorator not affecting stories in docs page #14477

hazem3500 opened this issue Apr 5, 2021 · 7 comments

Comments

@hazem3500
Copy link

hazem3500 commented Apr 5, 2021

Describe the bug
I have a decorator that toggles between color modes.

// withColorMode.tsx
import { useColorMode } from '@chakra-ui/react';
import React, { useEffect } from 'react';

export default (Story, { globals: { theme = 'light' } }) => {
    const { colorMode, setColorMode } = useColorMode();
    useEffect(() => {
    	if (colorMode !== theme) setColorMode(theme);
    }, [theme, colorMode]);
    return <Story />;
};
// preview.js

import React from 'react';

import { DesignSystemProvider } from '../src/providers';
import withColorMode from './decorators/withColorMode';

export const globalTypes = {
    theme: {
        name: 'Theme',
        description: 'Global theme for components',
        defaultValue: 'light',
        toolbar: {
            icon: 'circlehollow',
            items: ['light', 'dark'],
        },
    },
};

export const decorators = [
    withColorMode,
    (Story) => (
        <DesignSystemProvider>
                <Story />
        </DesignSystemProvider>
    ),
];

it works fine when viewing in canvas mode. but when I switch to the docs page it doesn't work.

Expected behavior
It should switch color mode on the docs page just like it does in canvas.

Screenshots
chrome_2021-04-05_11-44-45
chrome_2021-04-05_11-46-09

System

Environment Info:

  System:
    OS: Windows 10 10.0.18362
    CPU: (4) x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
  Binaries:
    Node: 14.8.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.4 - C:\Program Files\nodejs\yarn.CMD
    npm: 6.14.7 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 89.0.4389.114
    Edge: Spartan (44.18362.449.0)
  npmPackages:
    @storybook/addon-a11y: ^6.1.14 => 6.1.14 
    @storybook/addon-actions: ^6.1.18 => 6.1.21
    @storybook/addon-console: ^1.2.2 => 1.2.2
    @storybook/addon-essentials: ^6.1.21 => 6.1.21
    @storybook/addon-links: ^6.1.21 => 6.1.21
    @storybook/node-logger: ^6.1.11 => 6.2.1
    @storybook/preset-create-react-app: ^3.1.5 => 3.1.5
    @storybook/react: ^6.2.1 => 6.2.1
@shilman
Copy link
Member

shilman commented Apr 5, 2021

Do you have a repro repo you can share?

Also, all of your storybook package versions should match. You can do this automatically (recommended) by:

  • stable: npx sb upgrade
  • prerelease: npx sb upgrade --prerelease

@hazem3500
Copy link
Author

here is a reproduction repo: https://github.com/hazem3500/storybook-14477-repro

@shilman
Copy link
Member

shilman commented Apr 6, 2021

Thanks @hazem3500, I've reproduced with your repo. I'm going to merge some related PRs into 6.3-alpha next week and then see if it still has the problem. Thanks for the repro and for your patience!

@hazem3500
Copy link
Author

You're welcome 😄

@hazem3500
Copy link
Author

I've tested this issue on version 6.3.0-rc.7 but it's still not working, is it supposed to be fixed in 6.3.0-rc.7 or will it be in another version?

@shilman
Copy link
Member

shilman commented Jun 15, 2021

issue's still open so i don't think it's going to happen in this release. we're redoing how we render stories in docs mode in 7.0, so maybe that's the best time to fix it.

in the meantime you can probably set docs: { inlineStories: false } in your global parameters as a workaround.

@shilman
Copy link
Member

shilman commented Jun 7, 2023

We’re cleaning house! Storybook has changed a lot since this issue was created and we don’t know if it’s still valid.

Please open a new issue referencing this one if:

@shilman shilman closed this as not planned Won't fix, can't repro, duplicate, stale Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants