Skip to content

Commit 2000494

Browse files
committed
fix: fix PropTypes.arrayOf(PropTypes.shape)
1 parent 0a4b98e commit 2000494

3 files changed

Lines changed: 101 additions & 18 deletions

File tree

__tests__/fixture/DownloadList.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* @file DownloadList react component
3+
* @author Xinyi Li
4+
* @date 2018/6/11
5+
* @description
6+
*/
7+
8+
import * as React from 'react'
9+
import PropTypes from 'prop-types'
10+
import './style.less'
11+
import p from 'prefix-classname'
12+
import cn from 'classnames'
13+
import DirBtnLrg from 'dulife-ui/DirBtnLrg'
14+
// import More from 'comps/More'
15+
16+
import GridLayout from 'dulife-ui/GridLayout'
17+
import '../DownloadSource'
18+
19+
import './style.less'
20+
import DownloadSource from 'dulife-ui/DownloadSource';
21+
22+
const c = p('du-page-download-list-')
23+
24+
export default class DownloadList extends React.Component {
25+
static propTypes = {
26+
...GridLayout.propTypes,
27+
renderItem: PropTypes.any,
28+
list: PropTypes.arrayOf(
29+
PropTypes.string
30+
),
31+
list2: PropTypes.arrayOf(
32+
PropTypes.shape({
33+
abc: PropTypes.string
34+
})
35+
),
36+
colNum: PropTypes.number
37+
}
38+
39+
static defaultProps = {
40+
list: [],
41+
colNum: '1'
42+
}
43+
44+
renderItem = ({ content, ...props }, index) => {
45+
return <DownloadSource {...props} className={cn(this.props.className)}>{content}</DownloadSource>
46+
}
47+
48+
render() {
49+
return (
50+
<div className={cn(this.props.className,c('container'))}>
51+
<GridLayout {...this.props} renderItem={this.renderItem} />
52+
</div>
53+
)
54+
}
55+
}
56+
57+
// function NumberList(props) {
58+
// const numbers = props.numbers;
59+
// const listItems = numbers.map((number) =>
60+
// <li key={number.toString()}>
61+
// {number}
62+
// </li>
63+
// );
64+
// return (
65+
// <ul>{listItems}</ul>
66+
// );
67+
// }
68+
69+
// const numbers = [1, 2, 3, 4, 5];
70+
// ReactDOM.render(
71+
// <NumberList numbers={numbers} />,
72+
// document.getElementById('root')
73+
// );

examples/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import TableDoc from '../'
1010
import '../lib/style.css'
1111

1212
const data = require('!../loader!../__tests__/fixture/Button.js')
13-
console.log('data', data)
13+
console.log('data', require('!../loader!../__tests__/fixture/DownloadList'))
1414
render(
1515
<div>
1616
<TableDoc data={data} />
1717
<hr/>
1818
<TableDoc data={require('!../loader!../__tests__/fixture/StatelessBtn')} />
19+
<hr/>
20+
<TableDoc data={require('!../loader!../__tests__/fixture/DownloadList')} />
1921
</div>,
2022
window.root
2123
)

src/index.js

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,27 @@ const cn = p('')
1818
export const i18n = _i18n
1919
export const marked = _marked
2020

21-
function renderPureType(d) {
22-
if (typeof d === 'string') {
23-
return d
24-
}
25-
console.log('renderPureType', d)
26-
switch (d.name) {
27-
case 'custom':
28-
return d.raw
29-
default:
30-
return d.value
31-
}
32-
}
33-
34-
function renderType(type) {
21+
function renderTypeAppend(type) {
3522
if (!type) {
3623
return null
3724
}
25+
if (typeof type === 'string') {
26+
return type
27+
}
28+
3829
const { name, value } = type
3930
let append = null
40-
if (name === 'enum') {
31+
if (name === 'custom') {
32+
append = type.raw
33+
} else if (name === 'enum') {
4134
append = value.map(({ value }, i) => (
4235
<span key={i}>
4336
{i > 0 && <span>|</span>}
44-
{renderPureType(value)}
37+
{renderTypeAppend(value)}
4538
</span>
4639
))
4740
} else if (name === 'arrayOf') {
48-
append = renderPureType(value)
41+
append = renderTypeAppend(value) || (value && value.name)
4942
} else if (name === 'custom') {
5043
append = type.raw
5144
} else if (name === 'shape') {
@@ -61,7 +54,22 @@ function renderType(type) {
6154
</div>
6255
)
6356
}
57+
} else {
58+
append = value
6459
}
60+
return append
61+
}
62+
63+
function renderType(type) {
64+
if (!type) {
65+
return null
66+
}
67+
if (typeof type === 'string') {
68+
return type
69+
}
70+
71+
const { name, value } = type
72+
const append = renderTypeAppend(type)
6573
return (
6674
<span className={c(`prop-type prop-type-${name}`)}>
6775
<code>{name}</code>

0 commit comments

Comments
 (0)