配置故事书文档插件以显示 theme.dark
configure storybook docs addon to display theme.dark
我正在尝试配置 storybook 以显示深色主题,到目前为止我还没有找到解决这个问题的方法。
所以我遵循了故事书文档,
我已经像这样设置了 manager.js 文件:
// .storybook/manager.js
import { addons } from '@storybook/addons';
import { themes } from '@storybook/theming';
addons.setConfig({
theme: themes.dark,
});
我还将主题打印到控制台,所以我看到它到了:
值得一提的是,当浏览器重新加载这个文件时,
但是如果我更改源代码并保存热重载不起作用..
这是我在 .storybook/preview.js:
中为文档指定相同主题的方式
// .storybook/preview.js
import React from "react";
import { appTheme } from "../src/Common/theme";
import { ThemeProvider } from "styled-components";
import { makeDecorator } from "@storybook/addons";
import { addParameters, addDecorator } from "@storybook/react";
import defaultNotes from "./general-docs.md";
import { themes } from "@storybook/theming";
export const parameters = {
docs: {
theme: themes.dark
}
};
addParameters({
notes: defaultNotes,
options: {
showRoots: true
}
});
const withStyledTheme = storyFn => {
return <ThemeProvider theme={appTheme}>{storyFn()}</ThemeProvider>;
};
const styledThemed = makeDecorator({
name: "styled-theme",
wrapper: withStyledTheme
});
addDecorator(styledThemed);
addParameters(parameters);
这是 main.js 文件的样子:
module.exports = {
stories: ["../src/**/*.stories.(ts|tsx|js|jsx|mdx)"],
addons: [
"@storybook/preset-create-react-app",
"@storybook/addon-actions",
"@storybook/addon-links",
"@storybook/addon-actions/register",
"@storybook/addon-knobs/register",
"@storybook/addon-notes/register-panel",
"storybook-addon-designs",
"@storybook/addon-docs/preset"
]
};
我在这个项目中使用打字稿,
所以这是 tsconfig.json:
{
"compilerOptions": {
"experimentalDecorators": true,
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"baseUrl": "src"
},
"include": ["src"]
}
我在这里错过了什么?
我一直被同一个问题困住,但解决方案一直是in the doc:
//.storybook/preview.js
import { themes } from '@storybook/theming';
export const parameters = {
docs: {
theme: themes.dark,
},
};
是的,您必须在两个不同的文件中指定主题两次
我正在尝试配置 storybook 以显示深色主题,到目前为止我还没有找到解决这个问题的方法。
所以我遵循了故事书文档, 我已经像这样设置了 manager.js 文件:
// .storybook/manager.js
import { addons } from '@storybook/addons';
import { themes } from '@storybook/theming';
addons.setConfig({
theme: themes.dark,
});
我还将主题打印到控制台,所以我看到它到了:
值得一提的是,当浏览器重新加载这个文件时, 但是如果我更改源代码并保存热重载不起作用..
这是我在 .storybook/preview.js:
中为文档指定相同主题的方式// .storybook/preview.js
import React from "react";
import { appTheme } from "../src/Common/theme";
import { ThemeProvider } from "styled-components";
import { makeDecorator } from "@storybook/addons";
import { addParameters, addDecorator } from "@storybook/react";
import defaultNotes from "./general-docs.md";
import { themes } from "@storybook/theming";
export const parameters = {
docs: {
theme: themes.dark
}
};
addParameters({
notes: defaultNotes,
options: {
showRoots: true
}
});
const withStyledTheme = storyFn => {
return <ThemeProvider theme={appTheme}>{storyFn()}</ThemeProvider>;
};
const styledThemed = makeDecorator({
name: "styled-theme",
wrapper: withStyledTheme
});
addDecorator(styledThemed);
addParameters(parameters);
这是 main.js 文件的样子:
module.exports = {
stories: ["../src/**/*.stories.(ts|tsx|js|jsx|mdx)"],
addons: [
"@storybook/preset-create-react-app",
"@storybook/addon-actions",
"@storybook/addon-links",
"@storybook/addon-actions/register",
"@storybook/addon-knobs/register",
"@storybook/addon-notes/register-panel",
"storybook-addon-designs",
"@storybook/addon-docs/preset"
]
};
我在这个项目中使用打字稿, 所以这是 tsconfig.json:
{
"compilerOptions": {
"experimentalDecorators": true,
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
"baseUrl": "src"
},
"include": ["src"]
}
我在这里错过了什么?
我一直被同一个问题困住,但解决方案一直是in the doc:
//.storybook/preview.js
import { themes } from '@storybook/theming';
export const parameters = {
docs: {
theme: themes.dark,
},
};
是的,您必须在两个不同的文件中指定主题两次