Support for documenting component props in the component docBlock
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 30/100
- Issue 类型
- 功能
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- javascript, react
调研方向
首先检查当前如何解析组件 docBlock、JSDoc 标签和 propTypes 属性注释。比较建议的 @prop 和 @react.prop 形式,包括 foobar.foo 等嵌套名称,并在实现和测试该功能之前定义受支持的语法和生成的文档。
由索引模型根据 Issue 内容生成。
描述
As of now, the docblock describing a property must be directly above where the property field is defined. As such
class MyComponent {
static propTypes = {
/**
* Does things that only a foo can
*/
foo: PropTypes.string,
/**
* Does things that only a bar can
*/
bar: PropTypes.string,
}
}
Which is a fine solution, but can get very bloated when you start having more props.
class MyComponent {
static propTypes = {
/**
* Does things that only a foo can
*/
foo: PropTypes.string,
/**
* Does things that only a bar can
*/
bar: PropTypes.string,
/**
* Does things that only a foobar can
*/
foobar: PropTypes.shape({
/**
* Does things that only a foo can
*/
foo: PropTypes.string,
/**
* Does things that only a bar can
*/
bar: PropTypes.string,
}),
/**
* Does things that only a foobar can
*/
foobar: PropTypes.shape({
/**
* Does things that only a foo can
*/
foo: PropTypes.string,
/**
* Does things that only a bar can
*/
bar: PropTypes.string,
}),
}
}
You can online the comments, but with some descriptions being long enough to require being on two line, it ends up looking messy in my opinion.
class MyComponent {
static propTypes = {
/** Does things that only a foo can*/
foo: PropTypes.string,
/** Does things that only a bar can */
bar: PropTypes.string,
/** Does things that only a foobar can */
foobar: PropTypes.shape({
/**
* Some properties will have a longer description that require them to be
* on multiple lines
*/
foo: PropTypes.string,
/** Does things that only a bar can */
bar: PropTypes.string,
}),
/** Does things that only a foobar can */
foobar: PropTypes.shape({
/** Does things only a foo can */
foo: PropTypes.string,
/** Does things that only a bar can */
bar: PropTypes.string,
}),
}
}
What I'm proposing is a JSDoc like tag that allows you to descibe the props for a component in the docblock for the component itself, somthing like:
/**
* @prop foo - Does things that only a foo can
* @prop bar - Does things that only a bar can
* @prop foobar - Does things that only a foobar can
* @prop foobar.foo - Some properties will have a longer description that require them to be on multiple lines
* @prop foobar.bar - Does things that only a bar can
* @prop foobar - Does things that only a foobar can
* @prop foobar.foo - Does things that only a foo can
* @prop foobar.bar - Does things that only a bar can
*/
class MyComponent {
static propTypes = {
foo: PropTypes.string,
bar: PropTypes.string,
foobar: PropTypes.shape({
foo: PropTypes.string,
bar: PropTypes.string,
}),
foobar: PropTypes.shape({
foo: PropTypes.string,
bar: PropTypes.string,
}),
}
}
Seing as prop is an existing JSDoc tag, it might be an idea to prefix it with something. Perhaps react., so
/**
* @react.prop name - description
*/
Is this something that would be worth looking into?
- 主要语言
- TypeScript
- 星标
- 3.8k
- 派生
- 316
- 平均合并
- 5 小时 7 分钟
- 30 天内合并 PR
- 4
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
reactjs/react-docgen 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
reactjs/react-docgen#1102 ·
-
难度 3/5 1-2 天 新手友好度 58/100
reactjs/react-docgen#1134 ·
-
难度 5/5 一周以上 新手友好度 20/100
reactjs/react-docgen#1005 · 4 个 reaction ·
-
难度 3/5 1-2 天 新手友好度 48/100
reactjs/react-docgen#997 ·
-
难度 3/5 1-2 天 新手友好度 42/100
reactjs/react-docgen#994 · 1 条评论 ·
查看 reactjs/react-docgen 的全部 Issue
相似的 Issue
-
Type/Bug
难度 2/5 1-3 小时 新手友好度 78/100
OpenNSW/nsw-srilanka#497 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
0xMiden/bridge-portal#132 ·
-
react-doctor severity:warning tech-debt
难度 1/5 1 小时以内 新手友好度 88/100
digidem/comapeo-cloud-app#403 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 78/100