-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
addon-backgrounds doesn't affect docs-mode #7978
Comments
@Couto Docs can be configured via the theming API: https://storybook.js.org/docs/configurations/theming/ Docs doesn't support currently interface with addons in the same way as the canvas, so I don't expect this to happen. There's an open issue at #6700 |
I might be wrong here, so please correct me if I'm wrong (which is likely) but your solution will change the entire background for docs-mode. I expressed myself wrong on the issue, but I meant a way to only change the Preview block's background, and not the entire page. |
Ok that makes more sense to me. For now, we'll do that via theming as well. Once we have figure out addon support for the Preview in #6700 then we might get backgrounds support "for free". I'll re-open this in the meantime. Thanks! |
I just figured out how to add dark theme a few days ago and then added docs this morning.. not sure if it's related, but I have dark theme everywhere else in my storybook. But docs are just a plain white background |
@TurtleWolf Docs are themed separately from the rest of the app as of 5.3 |
@shilman It isn't working for me. I want to give a background color to I have the following code: import { addParameters } from '@storybook/react';
const themes = {
dark: '#33354C',
};
addParameters({
options: {
theme: themes.dark,
},
backgrounds: [{ name: 'dark', value: themes.dark, default: true }],
}); I even tried directly: import { addParameters } from '@storybook/react';
addParameters({
options: {
theme: '#33354C',
},
backgrounds: [{ name: 'dark', value: '#33354C', default: true }],
}); Am I doing anything wrong? I get the error:
|
Alright, I got it. Gotta create a theme myself as said in https://storybook.js.org/docs/configurations/theming/ :) |
Apparently, it doesn't work for me. Not sure if I'm doing anything wrong. It's the same error:
Here are my files: .storybook/main.jsmodule.exports = {
stories: ['../stories/**/*.stories.(ts|tsx)'],
addons: [
'@storybook/addon-actions',
'@storybook/addon-links',
'@storybook/addon-docs',
'@storybook/addon-backgrounds/register',
],
webpackFinal: async config => {
config.module.rules.push({
test: /\.(ts|tsx)$/,
use: [
{
loader: require.resolve('ts-loader'),
options: {
transpileOnly: true,
},
},
{
loader: require.resolve('react-docgen-typescript-loader'),
},
],
});
config.resolve.extensions.push('.ts', '.tsx');
return config;
},
}; .storybook/manager.jsimport { addons } from '@storybook/addons';
import theme from './theme';
addons.setConfig({
theme,
}); .storybook/preview.jsimport { addParameters } from '@storybook/react';
import { themes } from '@storybook/theming';
addParameters({
options: {
theme: {
base: themes.dark,
},
},
backgrounds: [{ name: 'dark', value: themes.dark, default: true }],
}); .storybook/theme.jsimport { create } from '@storybook/theming/create';
import { typography, color } from '@storybook/theming';
const theme = create({
base: 'dark',
// Storybook-specific color palette
colorPrimary: '#FF4785', // coral
colorSecondary: '#1EA7FD', // ocean
// UI
appBg: '#33354C',
appContentBg: '#33354C',
appBorderColor: '#FBDB47',
appBorderRadius: 10,
// Fonts
fontBase: typography.fonts.base,
fontCode: typography.fonts.mono,
// Text colors
textColor: color.lightest,
textInverseColor: color.darkest,
// Toolbar default and active colors
barTextColor: '#999999',
barSelectedColor: color.secondary,
barBg: color.darkest,
// Form colors
inputBg: '#3f3f3f',
inputBorder: 'rgba(0,0,0,.3)',
inputTextColor: color.lightest,
inputBorderRadius: 4,
});
export default theme; Exactly followed the guide above so Idk what I am doing wrong? 🤔 |
Alright finally got it. I was using .storybook/preview.jsimport { addParameters } from '@storybook/react';
import theme from './theme';
addParameters({
options: {
theme,
},
backgrounds: [{ name: 'dark', value: '#33354C', default: true }],
}); |
@yannbf any chance you can contribute this for 6.1? |
Hey @shilman I can definitely try, just gotta understand exactly what to do. Is it so that every preview in docs uses the background defined via the backgrounds addon + bring the addon button to the docs tab? |
Sounds about right. FYI we changed the name from Preview to Canvas in 6.0! |
Huzzah!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.1.0-alpha.16 containing PR #12368 that references this issue. Upgrade today to try it out! You can find this prerelease on the Closing this issue. Please re-open if you think there's still more to do. |
Hi @shilman , Your PR fixes the problem for DocsPage generated documentation, but not for manually written MDX stories in the style described here. The code in the PR tries to set styles on the CSS selector This works for DocsPage since it generates Anchor components for every story. Would it be possible to make the background selection work on any story regardless of whether they are contained in an anchor? |
Cc @yannbf |
I can confirm that I'm having the exact same problem. Works fine for CSF stories, not for MDX stories... |
Having the same issue here with it not working in MDX. Can (should) this issue be reopened? |
Describe the bug
addon-backgrounds only works in canvas mode, and has no effect whatsoever in docs-mode.
To Reproduce
addParameters({})
on config.js with some default backgrounds (As per the addon-backgrounds instructions)Expected behavior
Preview blocks with toolbars should display a button to switch the background color of that block
Screenshots
N/A
Code snippets
N/A
System:
Environment Info:
Additional context
N/A
The text was updated successfully, but these errors were encountered: