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

Set defaults per stories #8

Open
wladpaiva opened this issue Jun 1, 2022 · 1 comment
Open

Set defaults per stories #8

wladpaiva opened this issue Jun 1, 2022 · 1 comment

Comments

@wladpaiva
Copy link

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
Copy link

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',
};

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

2 participants