-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support adding decorators to groups of stories by path prefix #2769
Comments
addDecorator((story, context) => {
const style = getTheamByContext(context);
/* */
}) |
We should add some documentation about this. I think we will start making a lot more use of the context soon (#2679) |
This is exactly what I need, thanks! |
I just took advantage of the context parameter to render different decorator templates based on the
import Foo from './Foo';
export default {
title: 'Organisms/Foo',
component: Foo,
};
const Template = (args, { argTypes }) => ({
...
})
import Bar from './Bar';
export default {
title: 'Pages/Bar',
component: Bar,
};
const Template = (args, { argTypes }) => ({
...
})
export const decorators = [
(story, { kind }) => {
const paths = kind.split('/');
if (paths.includes('Pages')) {
return {
template: `<div id="page"><story/></div>`
}
}
if (paths.includes('Organisms')) {
return {
template: `<div id="organism"><story/></div>`
}
}
},
]; |
Issue details
My team is building out a single storybook to serve as the ui kit across multiple web apps that have different themes. Right now, we're using
require.context
to build every.story
in our monorepo, but we haven't found a simple way to apply decorators to all the stories that fall under a specific app.For example, if we have stories:
We would like to apply theme A to AppA stories and theme B to AppB stories, in one location.
Ideal API
Right now, our work around is to add the theme decorator manually to every story individually
The text was updated successfully, but these errors were encountered: