I'm trying to use react-docgen-typescript-loader
to generate my props documentation in Storybook with my TypeScript Props, but it's not populating anything into the withInfo
addon.
I'm using the TypeScript flavor of create-react-app and I'm following multiple different methods of configuring the .storybook/webpack.config.js
and nothing seems to work.
Here's what my current config is:
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;
};
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);
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 } });
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;
There are currently no issues with this configuration, but I only see this as the info output in Storybook:
There is some difference in using named imports, this worked for me:
import React, {FC} from 'react'
...
const Button: FC<Props> = (props) => {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With