question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ThemeProvider decorator not affecting stories in docs page

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
shilmancommented, 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.

1reaction
shilmancommented, 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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Decorators - Storybook - JS.ORG
A decorator is a way to wrap a story in extra “rendering” functionality. Many addons define decorators to augment your stories with extra...
Read more >
Use a ThemeProvider component in Storybook
In this post, we explore how we can add a ThemeProvider to ... In my current projects, this decorator lives in the .storybook...
Read more >
Text from Google Docs is not displayed in ArcGIS Story Maps ...
A story map with text copied from Google Docs does not display when viewed in Preview, after refreshing the page, or after publishing...
Read more >
configure storybook docs addon to display theme.dark
// .storybook/preview.js import ; from "react" ; from "../src/Common/theme" ; ThemeProvider } from ; import { makeDecorator } from ...
Read more >
Storybook React with Dark Mode Option - David Yeiser
We will then use Emotion's styled function and ThemeProvider ... see a blank Storybook view with a message about not finding any stories....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found