Skip to content

Instantly share code, notes, and snippets.

@chinhnguyen
Created October 5, 2019 13:07
Show Gist options
  • Save chinhnguyen/a4a985a1b9bbd018118396590e768fb4 to your computer and use it in GitHub Desktop.
Save chinhnguyen/a4a985a1b9bbd018118396590e768fb4 to your computer and use it in GitHub Desktop.
Override storybook add to make it work with material UI
import React from 'react';
import { storiesOf as storybookStoriesOf } from '@storybook/react';
import { StylesProvider } from '@material-ui/styles';
const generateClassName = (rule, styleSheet) => `${styleSheet.options.classNamePrefix}-${rule.key}`;
export default function storiesOf(kind, module) {
let stories = storybookStoriesOf(kind, module)
let _add = stories.add
//add: (storyName: string, storyFn: StoryFn<StoryFnReturnType>, parameters?: Parameters) => StoryApi<StoryFnReturnType>;
stories.add = (storyName, storyFn, parameters) =>
_add(storyName, () => (
<StylesProvider generateClassName={generateClassName}>
{storyFn()}
</StylesProvider>
), parameters)
return stories
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment