@@ -5,18 +5,46 @@ import Label from '../../src/Label';
5
5
import Table from '../../src/Table' ;
6
6
7
7
8
- let cleanDocletValue = str => str . replace ( / ^ \{ | \} $ / g, '' ) ;
8
+ let cleanDocletValue = str => str . trim ( ) . replace ( / ^ \{ / , '' ) . replace ( / \} $ / , '' ) ;
9
+
10
+ function getPropsData ( componentData , metadata ) {
11
+
12
+ let props = componentData . props || { } ;
13
+
14
+ if ( componentData . composes ) {
15
+ componentData . composes . forEach ( other => {
16
+ props = merge ( { } , getPropsData ( metadata [ other ] || { } , metadata ) , props ) ;
17
+
18
+ } ) ;
19
+ }
20
+
21
+ if ( componentData . mixins ) {
22
+ componentData . mixins . forEach ( other => {
23
+ if ( componentData . composes . indexOf ( other ) === - 1 ) {
24
+ props = merge ( { } , getPropsData ( metadata [ other ] || { } , metadata ) , props ) ;
25
+ }
26
+ } ) ;
27
+ }
28
+
29
+ return props ;
30
+ }
9
31
10
32
const PropTable = React . createClass ( {
11
33
12
34
contextTypes : {
13
35
metadata : React . PropTypes . object
14
36
} ,
15
37
38
+ componentWillMount ( ) {
39
+ let componentData = this . context . metadata [ this . props . component ] || { } ;
40
+
41
+ this . propsData = getPropsData ( componentData , this . context . metadata ) ;
42
+ } ,
43
+
16
44
render ( ) {
17
- let metadata = this . context . metadata [ this . props . component ] || { } ;
45
+ let propsData = this . propsData ;
18
46
19
- if ( ! Object . keys ( metadata . props || { } ) . length ) {
47
+ if ( ! Object . keys ( propsData ) . length ) {
20
48
return < span /> ;
21
49
}
22
50
@@ -31,46 +59,36 @@ const PropTable = React.createClass({
31
59
</ tr >
32
60
</ thead >
33
61
< tbody >
34
- { this . _renderRows ( ) }
62
+ { this . _renderRows ( propsData ) }
35
63
</ tbody >
36
64
</ Table >
37
65
) ;
38
66
} ,
39
67
40
- _renderRows ( ) {
41
- let metadata = this . context . metadata [ this . props . component ] || { } ;
42
- let props = metadata . props || { } ;
68
+ _renderRows ( propsData ) {
43
69
44
- if ( metadata . composes ) {
45
- metadata . composes . forEach ( other => {
46
- props = merge ( props , ( this . context . metadata [ other ] || { } ) . props ) ;
47
- } ) ;
48
- }
49
-
50
- if ( metadata . mixins ) {
51
- metadata . mixins . forEach ( other => {
52
- if ( metadata . composes . indexOf ( other ) === - 1 ) {
53
- props = merge ( props , ( this . context . metadata [ other ] || { } ) . props ) ;
54
- }
55
- } ) ;
56
- }
57
-
58
- return Object . keys ( props )
70
+ return Object . keys ( propsData )
59
71
. sort ( )
60
- . filter ( propName => props [ propName ] . type && ! props [ propName ] . doclets . private )
72
+ . filter ( propName => propsData [ propName ] . type && ! propsData [ propName ] . doclets . private )
61
73
. map ( propName => {
62
- let prop = props [ propName ] ;
74
+ let propData = propsData [ propName ] ;
63
75
64
76
return (
65
77
< tr key = { propName } className = 'prop-table-row' >
66
78
< td >
67
- { propName } { this . renderRequiredLabel ( prop ) }
79
+ { propName } { this . renderRequiredLabel ( propData ) }
68
80
</ td >
69
81
< td >
70
- < div > { this . getType ( prop ) } </ div >
82
+ < div > { this . getType ( propData ) } </ div >
83
+ </ td >
84
+ < td > { propData . defaultValue } </ td >
85
+
86
+ < td >
87
+ { propData . doclets . deprecated
88
+ && < div > < strong className = 'text-danger' > { 'Deprecated: ' + propData . doclets . deprecated + ' ' } </ strong > </ div >
89
+ }
90
+ < div dangerouslySetInnerHTML = { { __html : propData . descHtml } } />
71
91
</ td >
72
- < td > { prop . defaultValue } </ td >
73
- < td dangerouslySetInnerHTML = { { __html : prop . descHtml } } > </ td >
74
92
</ tr >
75
93
) ;
76
94
} ) ;
@@ -87,17 +105,29 @@ const PropTable = React.createClass({
87
105
} ,
88
106
89
107
getType ( prop ) {
90
- let type = prop . type ;
108
+ let type = prop . type || { } ;
91
109
let name = this . getDisplayTypeName ( type . name ) ;
92
110
let doclets = prop . doclets || { } ;
93
111
94
112
switch ( name ) {
95
113
case 'object' :
96
114
return name ;
97
115
case 'union' :
98
- return type . value . map ( val => this . getType ( { type : val } ) ) . join ( ' | ' ) ;
116
+ return type . value . reduce ( ( current , val , i , list ) => {
117
+ let item = this . getType ( { type : val } ) ;
118
+
119
+ if ( React . isValidElement ( item ) ) {
120
+ item = React . cloneElement ( item , { key : i } ) ;
121
+ }
122
+
123
+ current = current . concat ( item ) ;
124
+
125
+ return i === ( list . length - 1 ) ? current : current . concat ( ' | ' ) ;
126
+ } , [ ] ) ;
99
127
case 'array' :
100
- return `array<${ this . getDisplayTypeName ( type . value . name ) } >` ;
128
+ let child = this . getType ( { type : type . value } ) ;
129
+
130
+ return < span > { 'array<' } { child } { '>' } </ span > ;
101
131
case 'enum' :
102
132
return this . renderEnum ( type ) ;
103
133
case 'custom' :
0 commit comments