fen*_*ech 5 typescript reactjs create-react-app storybook
我正在尝试使用react-docgen-typescript-loader
TypeScript Props 在 Storybook 中生成道具文档,但它不会将任何内容填充到插件中withInfo
。
我正在使用 create-react-app 的 TypeScript 风格,并且遵循多种不同的配置方法,.storybook/webpack.config.js
但似乎没有任何效果。
这是我当前的配置:
module.exports = ({ config, mode }) => {
config.module.rules.push({
test: /\.(ts|tsx)$/,
use: [
{
loader: require.resolve('babel-loader'),
options: {
presets: [['react-app', { flow: false, typescript: true }]],
}
},
require.resolve("react-docgen-typescript-loader"),
]
});
config.resolve.extensions.push('.ts', '.tsx');
return config;
};
Run Code Online (Sandbox Code Playgroud)
import { configure } from '@storybook/react';
// automatically import all files ending in *.stories.js
const req = require.context('../', true, /.stories.tsx$/);
function loadStories() {
req.keys().forEach(filename => req(filename));
}
configure(loadStories, module);
Run Code Online (Sandbox Code Playgroud)
import * as React from 'react';
import { storiesOf } from '@storybook/react';
import { withInfo } from '@storybook/addon-info';
import Button from '../src/components/Button';
storiesOf('Button', module)
.addDecorator(withInfo)
.add('continue', () => <Button buttonType="submit">Hello Button</Button>, { info: { inline: true } })
.add('back', () => <Button buttonType="reset">Hello Button</Button>, { info: { inline: true } });
Run Code Online (Sandbox Code Playgroud)
import React from 'react';
interface Props {
buttonType: Button.Type;
}
const Button: React.FunctionComponent<Props> = (props) => {
const getStyles = (buttonType: string): {color: string} => {
if (buttonType === 'reset') {
return { color: 'red' };
}
if (buttonType === 'submit') {
return { color: 'green' };
}
return { color: 'green' };
};
const { buttonType, children } = props;
return <button type={buttonType} style={getStyles(buttonType)}>{children}</button>;
};
export default Button;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4730 次 |
最近记录: |