@@ -19,6 +19,7 @@ export function PropertySignatureTable({
19
19
display = "parent" ,
20
20
customOrder = [ ] ,
21
21
idPrefix = "" ,
22
+ genericNames,
22
23
} ) {
23
24
const MDX = useMDXComponents ( ) ;
24
25
const getItem = useApiDocContext ( ) ;
@@ -36,6 +37,29 @@ export function PropertySignatureTable({
36
37
) ;
37
38
}
38
39
40
+ const replaceGenericNames = React . useMemo ( ( ) => {
41
+ if ( ! genericNames ) return ( str ) => str ;
42
+
43
+ const replacements = { } ;
44
+ item . typeParameters . forEach ( ( p , i ) => {
45
+ if ( genericNames [ i ] === p . name ) return ;
46
+ replacements [ p . name ] = genericNames [ i ] ;
47
+ } ) ;
48
+ if ( ! Object . values ( replacements ) . length ) return ( str ) => str ;
49
+
50
+ const genericReplacementRegex = new RegExp (
51
+ `\\b(${ Object . keys ( replacements ) . join ( "|" ) } )\\b` ,
52
+ "g"
53
+ ) ;
54
+ function replace ( match ) {
55
+ console . log ( { match, replacement : replacements [ match ] } ) ;
56
+ return replacements [ match ] || match ;
57
+ }
58
+ return function replaceGenericNames ( str ) {
59
+ return str . replace ( genericReplacementRegex , replace ) ;
60
+ } ;
61
+ } ) ;
62
+
39
63
return (
40
64
< >
41
65
{ item . childrenIncomplete ?
@@ -55,7 +79,7 @@ export function PropertySignatureTable({
55
79
: null }
56
80
{ Object . entries ( groupedProperties ) . map (
57
81
( [ groupName , sortedProperties ] ) => (
58
- < >
82
+ < React . Fragment key = { groupName } >
59
83
{ groupName ?
60
84
< GridItem className = "row heading" > { groupName } </ GridItem >
61
85
: null }
@@ -79,7 +103,6 @@ export function PropertySignatureTable({
79
103
: null
80
104
}
81
105
suffix = { property . optional ? < em > (optional)</ em > : null }
82
- link = { ! ! idPrefix }
83
106
id = {
84
107
idPrefix ?
85
108
`${ idPrefix } -${ property . displayName . toLowerCase ( ) } `
@@ -94,7 +117,7 @@ export function PropertySignatureTable({
94
117
parameterTypes
95
118
arrow
96
119
/>
97
- : property . type }
120
+ : replaceGenericNames ( property . type ) }
98
121
</ MDX . inlineCode >
99
122
</ GridItem >
100
123
< GridItem className = "cell" fontSize = "md" lineHeight = "base" >
@@ -109,7 +132,7 @@ export function PropertySignatureTable({
109
132
</ GridItem >
110
133
</ React . Fragment >
111
134
) ) }
112
- </ >
135
+ </ React . Fragment >
113
136
)
114
137
) }
115
138
</ Wrapper >
@@ -124,4 +147,5 @@ PropertySignatureTable.propTypes = {
124
147
display : PropTypes . oneOf ( [ "parent" , "child" ] ) ,
125
148
customOrder : PropTypes . arrayOf ( PropTypes . string ) ,
126
149
idPrefix : PropTypes . string ,
150
+ genericNames : PropTypes . arrayOf ( PropTypes . string ) ,
127
151
} ;
0 commit comments