-
Notifications
You must be signed in to change notification settings - Fork 106
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
Allow setting global args in SB 6.5+ #399
Conversation
We got failures in some of the example builds (strangely, not all of them).
Should we update our browser support? Or, maybe I need to wrap the whole thing in an async IIFE? |
Hmm 86% supported globally seems fine to me. I don't have a strong preference either way |
Would something like this work: import * as clientApi from "@storybook/client-api";
const {
addDecorator,
addParameters,
addLoader,
addArgTypesEnhancer,
addArgsEnhancer,
setGlobalRender,
} = clientApi;
case "args": {
if (typeof clientApi.addArgs !== "undefined") {
return clientApi.addArgs(value);
} else {
return logger.warn(
"Could not add global args. Please open an issue in storybookjs/builder-vite."
);
}
}
case "argTypes": {
if (typeof clientApi.addArgTypes !== "undefined") {
return clientApi.addArgTypes(value);
} else {
return logger.warn(
"Could not add global argTypes. Please open an issue in storybookjs/builder-vite."
);
}
}
|
Brilliant, that works great. I tested with storybook 6.4 and 6.5, and it behaves correctly, although react is yelling about trying to set |
Co-authored-by: Josh Wooding <12938082+joshwooding@users.noreply.github.com>
@joshwooding this is ready for another review whenever you've got some time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes #395.
This is a little bit tricky to do in a way that supports storybook 6.4 and 6.5. I've used a dynamic
import()
and a top-level await, in order to wrap the import of the new methods in a try/catch. This has decent browser support, but is not universal. Curious if anyone else has another idea.I've added example global args in the
react
andreact-ts
examples, to show both story store V6 and V7 support. You can simulate storybook 6.4 by changing the destructured imports toaddArgsZ
andaddArgTypesZ
, building, and starting an example. You shouldn't see the control, and there shouldn't be any console errors.