Skip to content
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

[Question] How to load decorators from different addons in preset #13412

Closed
darkowic opened this issue Dec 9, 2020 · 3 comments · Fixed by #17221
Closed

[Question] How to load decorators from different addons in preset #13412

darkowic opened this issue Dec 9, 2020 · 3 comments · Fixed by #17221

Comments

@darkowic
Copy link

darkowic commented Dec 9, 2020

Hello!

I'm creating a preset which is supposed to load a couple of different addons together - something similar to addon essentials. I'm not able to find any example of how to easily load decorators from other addons to be enabled by default. I've come up with something like this:

// my-preset/index.js
function managerEntries(entry = []) {
    return [
        ...entry,
        require.resolve('my-addon-theming/register'),
    ];
}

const config = (entry = [], options) => {
    return [
        ...entry,
        require.resolve('my-addon-theming/addDecorator'),
    ];
};

module.exports = {
managerEntries,
config
}

This my-preset will load more different addons and also allow to configure them. What is the recommended approach for it?

Is it possible to pass configuration to these add-ons through the my-preset addon?

Storybook: v6.1

@shilman
Copy link
Member

shilman commented Dec 9, 2020

If you control the other addons, e.g. my-addons-theming, my suggestion would be to copy what we did in addon-essentials.

export const addons = (options) => [
  { name: 'my-addon-theming', options: { ... } },
  'something-else',
];

This would example that my-addon-theming have its own preset which calls addDecorator, which is the recommended way to write addons now.

If you don't control the other addons, what you're doing should also work and will give you full control to do whatever you want.

cc @jonniebigodes @winkerVSbecks

@darkowic
Copy link
Author

Thank you! Works perfectly ;)

Feel free to change this issue topic to some documentation update or close it.

@jonniebigodes
Copy link
Contributor

Thanks for bringing this to our attention, I've just pushed a pull request to address this issue and hopefully help other addon creators with the necessary information. Hope you don't mind but I'm going to close this issue as the documentation is updated.

Have a great day!

Stay safe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants