Storybook 自动生成 React 组件的文档/属性描述的问题
我的是一个较旧的存储库(想想Webpack 3.*)。我在回购中添加了故事书,并为我的.scss
文件修改了一些WebPack规则以正确加载。
我可以让故事书控件正确加载。但是,文档部分中的argstable
不尊重我在proptypes
中给出的评论。
这是我的组件 - newpill.js
import styles from './NewPill.scss';
const NewPill = props => {
const { text, color } = props;
return <span className={`${styles.newPill} ${color}`}> {text} </span>;
};
NewPill.propTypes = {
/**
* Denotes the text of the pill
*/
text: PropTypes.string,
/**
* Denotes the color of the pill
*/
color: PropTypes.string,
};
export default NewPill;
这是我的故事 - newpill.stories.js
import NewPill from './NewPill';
export default {
title: 'Components/NewPill',
component: NewPill,
};
const Template = args => {
console.log(NewPill.__docgenInfo); // Gives me undefined
return <NewPill {...args} />;
};
export const FirstStory = Template.bind({});
FirstStory.args = {
text: 'Pill Text',
color: 'blue',
};
,这是输出,
显然,实际上是为故事本身添加argtypes
。
FirstStory.argTypes = {
text: {
control: { type: 'text' },
description: 'Denotes the text of the pill',
}
color: 'blue',
};
但是,如果故事书系统从原始组件本身获取该信息,那就太好了。有没有办法查看babel-plugin-react-docgen
是否有效?我按照他们的说明在这里
Mine is a older repo (think webpack 3.*). I added storybook to the repo and modified a few of the webpack rules for my .scss
files to load properly.
I can get the Storybook controls to load properly. But the ArgsTable
in the docs section does not respect my comments that I gave in propTypes
.
Here is my component - NewPill.js
import styles from './NewPill.scss';
const NewPill = props => {
const { text, color } = props;
return <span className={`${styles.newPill} ${color}`}> {text} </span>;
};
NewPill.propTypes = {
/**
* Denotes the text of the pill
*/
text: PropTypes.string,
/**
* Denotes the color of the pill
*/
color: PropTypes.string,
};
export default NewPill;
Here is my story - NewPill.stories.js
import NewPill from './NewPill';
export default {
title: 'Components/NewPill',
component: NewPill,
};
const Template = args => {
console.log(NewPill.__docgenInfo); // Gives me undefined
return <NewPill {...args} />;
};
export const FirstStory = Template.bind({});
FirstStory.args = {
text: 'Pill Text',
color: 'blue',
};
And this is the output,
The workaround is obviously to add argTypes
to the story itself.
FirstStory.argTypes = {
text: {
control: { type: 'text' },
description: 'Denotes the text of the pill',
}
color: 'blue',
};
But it'd be nice if the storybook system grabs that info from the original component itself. Is there a way to see if the babel-plugin-react-docgen
worked? I followed their instructions here with no luck
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我有完全相同的问题。问题出在您使用的版本上。
将 Storybook 降级到 v
6.3.0
解决了我的问题。PS:必须逐一降级软件包(像这样
npx [email ;protected] init
无法按预期工作)。I had exact same issue. The problem is in version you use.
Downgrading Storybook to v
6.3.0
solved the issue in my case.PS: It was mandatory to downgrade packages one by one (smth like that
npx [email protected] init
doesn't work as expected).