Skip to content

Commit 2cd2075

Browse files
committed
PropTypes.arrayOf support (#20).
1 parent df41f19 commit 2cd2075

File tree

5 files changed

+35
-19
lines changed

5 files changed

+35
-19
lines changed

.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"stage": 0
3+
}

.eslintrc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@
205205
},
206206
"globals": {
207207
"describe": false,
208-
"it": false
208+
"it": false,
209+
"expect": false,
210+
"expectReactShallow": false
209211
}
210212
}

mochasetup.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react';
2+
import { expect } from 'chai';
3+
import expectReactShallow from 'expect-react-shallow';
4+
import 'css-modules-require-hook';
5+
6+
global.React = React;
7+
global.expect = expect;
8+
global.expectReactShallow = expectReactShallow;

package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"dependencies": {
3131
"babel-core": "5.8.30",
3232
"babel-loader": "5.3.2",
33-
"babel-plugin-react-display-name": "~2.0.0",
33+
"babel-plugin-react-display-name": "2.0.0",
3434
"babel-plugin-react-transform": "1.1.1",
3535
"chalk": "1.1.1",
3636
"codemirror": "5.8.0",
@@ -62,15 +62,20 @@
6262
"react": ">=0.14.0"
6363
},
6464
"devDependencies": {
65+
"babel-core": "~5.8.30",
6566
"babel-eslint": "4.1.3",
6667
"chai": "~3.4.1",
68+
"css-modules-require-hook": "~2.0.2",
6769
"eslint": "1.7.3",
6870
"eslint-plugin-react": "3.6.3",
71+
"expect-react-shallow": "~1.0.0",
6972
"gulp": "3.9.0",
7073
"gulp-gh-pages": "0.5.4",
7174
"mocha": "~2.3.3",
72-
"react": "0.14.0",
73-
"react-dom": "0.14.0"
75+
"postcss-modules-extract-imports": "~1.0.0",
76+
"postcss-modules-scope": "~1.0.0",
77+
"react": "~0.14.2",
78+
"react-dom": "~0.14.2"
7479
},
7580
"scripts": {
7681
"test": "npm run lint && npm run mocha && npm run build",

src/components/Props/Props.js

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default class Props extends Component {
1919
rows.push(
2020
<tr key={name}>
2121
<td className={s.cell}><code>{name}</code></td>
22-
<td className={s.cell}><code>{prop.type.name}</code></td>
22+
<td className={s.cell}><code>{this.renderType(prop.type)}</code></td>
2323
<td className={s.cell}>{this.renderDefault(prop)}</td>
2424
<td className={s.cell + ' ' + s.cellDesc}>{this.renderDescription(prop)}</td>
2525
</tr>
@@ -28,6 +28,17 @@ export default class Props extends Component {
2828
return rows;
2929
}
3030

31+
renderType(type) {
32+
let { name } = type;
33+
switch (name) {
34+
case 'arrayOf':
35+
return `${type.value.name}[]`;
36+
case 'instanceOf':
37+
return type.value;
38+
}
39+
return name;
40+
}
41+
3142
renderDefault(prop) {
3243
if (prop.required) {
3344
return '';
@@ -77,20 +88,7 @@ export default class Props extends Component {
7788
}
7889
let values = prop.type.value.map((value) => (
7990
<li className={s.listItem} key={value.name}>
80-
<code>
81-
{(() => {
82-
switch (value.name) {
83-
case 'arrayOf':
84-
return `arrayOf ${value.value.name}`;
85-
86-
case 'instanceOf':
87-
return `instanceOf ${value.value}`;
88-
89-
default:
90-
return value.name;
91-
}
92-
})()}
93-
</code>
91+
<code>{this.renderType(value)}</code>
9492
</li>
9593
));
9694

0 commit comments

Comments
 (0)