renatomoor / storybook-tailwind-dark-mode

MIT License
20 stars 16 forks source link

Set defaults per stories #8

Open wladpaiva opened 2 years ago

wladpaiva commented 2 years ago

I wonder if there is any way we could set up default for specific stories. It would make a lot faster to test impact of changes using chromatic

iamfreund commented 1 year ago
import { useEffect, useGlobals } from '@storybook/client-api';

// ....

export const ButtonStory: Story<PropsWithChildren<ButtonProps>> = (args) => {
    const [_, updateGlobals] = useGlobals();

    useEffect(() => {
        // enable dark mode when component mounts
        updateGlobals({ darkMode: true });

        // disable dark mode when component unmounts
        return () => updateGlobals({ darkMode: false });
    }, []);

    return (
        <Button {...args}>{args.children}</Button>
    );
};

ButtonStory.args = {
    variant: ButtonVariant.PRIMARY,
    children: 'Button',
};