-
SummaryHello! In our product, we embed stories without the toolbar and we want to build custom control to switch themes. We can catch theme list by catching message event Example: decorators: [
withThemeByClassName({
themes: {
light: "light-theme",
dark: "dark-theme",
},
defaultTheme: "light",
})
] and catch event, I only get this data: {
"key": "storybook-channel",
"event": {
"type": "storybook/themes/REGISTER_THEMES",
"args": [
{
"defaultTheme": "light",
"themes": [
"light",
"dark"
]
}
],
"from": "ec1bf6b39d5c2"
},
"refId": null
} To switch themes, I should add to the iframe URL I think the event should include data like this: {
"key": "storybook-channel",
"event": {
"type": "storybook/themes/REGISTER_THEMES",
"args": [
{
"defaultTheme": "light",
"themes": [
{value: 'light-theme', key: 'light'},
{value: 'dark-theme', key: 'dark'}
]
}
],
"from": "ec1bf6b39d5c2"
},
"refId": null
} or the event should emit values, not keys. Is there any particular reason why this not is implemented this way? Additional informationStorybook version: 8.2.9 This is a React project, generated by executing My preview configuration: const preview: Preview = {
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
},
decorators: [
withThemeByClassName({
themes: {
light: "light-theme",
dark: "dark-theme",
},
defaultTheme: "light",
}),
],
}; Create a reproductionNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It looks correct, based on the code. storybook/code/addons/themes/src/decorators/helpers.ts Lines 20 to 23 in 373ccbd That event emits generic theme data that should be the same if you are using any of the theme decorators. So it would not make sense to include the CSS class name in that event, because that is unique to that decorator. You mentioned that the event should include the value, but the key is all you should need, because the value is an implementation detail that isn't important for specifying which theme that you want to use. Instead of |
Beta Was this translation helpful? Give feedback.
It looks correct, based on the code.
storybook/code/addons/themes/src/decorators/helpers.ts
Lines 20 to 23 in 373ccbd
That event emits generic theme data that should be the same if you are using any of the theme decorators. So it would not make sense to include the CSS class name in that event, because that is unique to that decorator.
You mentioned that the event should include the value, but the key is all you should need, because the value is an implementation detail that isn't important for specifying which theme that you want to use.
Instead of
&globals=th…