0.0.6 • Published 5 years ago

storybook-addon-theme-selector v0.0.6

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

Storybook-addon-theme-selector

Storybook addon tools for selecting user-defined themes

Example Usage

On .storybook/config.tsx:

import { configure, addDecorator, addParameters } from '@storybook/react';

addParameters({
    themes: [
        { name: 'default', theme: LIGHT_THEME, default: true },
        { name: 'dark', theme: DARK_THEME },
    ],
});

let currentTheme: ThemeType = LIGHT_THEME;

const ThemeDecorator = (storyFn: any) => {
    class Container extends React.Component {
        state = {
            theme: currentTheme,
        };

        constructor(props: any) {
            super(props);

            addons.getChannel().on('theme-selector/themeChanged', theme => {
                currentTheme = theme;
                this.setState({ theme });
            });
        }

        render() {
            const { theme } = this.state;
            return (
                <div style={{ color: theme.text, backgroundColor: theme.background }}>
                    <ThemeProvider value={{ theme }}>
                        {storyFn()}
                    </ThemeProvider>
                </div>
            );
        }
    }
    return <Container />;
};
addDecorator(ThemeDecorator);
0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago