File tree Expand file tree Collapse file tree 5 files changed +45
-12
lines changed
packages/pretty-proptypes/src Expand file tree Collapse file tree 5 files changed +45
-12
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' pretty-proptypes ' : patch
3
+ ---
4
+
5
+ Permalink generation should also work now when ` extract-react-types ` is used.
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import type { Components } from '../components';
10
10
import getPropTypes from '../getPropTypes' ;
11
11
import renderPropType from '../renderPropType' ;
12
12
import PrettyPropType from '../PrettyConvert' ;
13
+ import { getComponentDisplayName } from '../utils' ;
13
14
14
15
type Obj = {
15
16
kind : 'object' ,
@@ -91,12 +92,11 @@ const LayoutRenderer: FC<LayoutRendererProps> = ({
91
92
}
92
93
93
94
let renderProps = rest ;
94
- // ensure displayName passes through, assuming it has been captured
95
- // $FlowFixMe as mentioned above, the typing for `component` is a bit off here...
96
- if ( component && component . ___displayName ) {
95
+ const componentDisplayName = getComponentDisplayName ( component || ( props || { } ) . component ) ;
96
+ if ( typeof componentDisplayName === 'string' ) {
97
97
renderProps = {
98
98
...rest ,
99
- componentDisplayName : String ( component . ___displayName )
99
+ componentDisplayName
100
100
} ;
101
101
}
102
102
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import type { CommonProps } from '../types';
9
9
import PropsWrapper from './Wrapper' ;
10
10
import getPropTypes from '../getPropTypes' ;
11
11
import renderPropType from '../renderPropType' ;
12
+ import { getComponentDisplayName } from '../utils' ;
12
13
13
14
import Prop from '../Prop' ;
14
15
@@ -69,12 +70,12 @@ export default class Props extends Component<DynamicPropsProps> {
69
70
if ( ! propTypes ) return null ;
70
71
71
72
let renderProps = rest ;
72
- // ensure displayName passes through, assuming it has been captured
73
- // $FlowFixMe as mentioned above, the typing for ` component` is a bit off here...
74
- if ( component && component . ___displayName ) {
73
+ // $FlowFixMe types are not exactly correct here ... sadly :/
74
+ const componentDisplayName = getComponentDisplayName ( component || ( props || { } ) . component ) ;
75
+ if ( typeof componentDisplayName === 'string' ) {
75
76
renderProps = {
76
77
...rest ,
77
- componentDisplayName : String ( component . ___displayName )
78
+ componentDisplayName
78
79
} ;
79
80
}
80
81
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import type { CommonProps } from '../types';
11
11
import PropsWrapper from '../Props/Wrapper' ;
12
12
import getPropTypes from '../getPropTypes' ;
13
13
import renderPropType from '../renderPropType' ;
14
+ import { getComponentDisplayName } from '../utils' ;
14
15
import PropRow from './PropRow' ;
15
16
16
17
type Obj = {
@@ -70,12 +71,12 @@ export default class PropsTable extends Component<DynamicPropsProps> {
70
71
if ( ! propTypes ) return null ;
71
72
72
73
let renderProps = rest ;
73
- // ensure displayName passes through, assuming it has been captured
74
- // $FlowFixMe as mentioned above, the typing for ` component` is a bit off here...
75
- if ( component && component . ___displayName ) {
74
+ // $FlowFixMe types are not exactly correct here ... sadly :/
75
+ const componentDisplayName = getComponentDisplayName ( component || ( props || { } ) . component ) ;
76
+ if ( typeof componentDisplayName === 'string' ) {
76
77
renderProps = {
77
78
...rest ,
78
- componentDisplayName : String ( component . ___displayName )
79
+ componentDisplayName
79
80
} ;
80
81
}
81
82
Original file line number Diff line number Diff line change
1
+ /* eslint-disable no-underscore-dangle */
2
+ // @flow strict-local
3
+
4
+ // eslint-disable-next-line import/prefer-default-export
5
+ export const getComponentDisplayName = (
6
+ data :
7
+ | {
8
+ ___displayName ?: string
9
+ }
10
+ | {
11
+ name ?: {
12
+ name ?: string
13
+ }
14
+ }
15
+ | void
16
+ ) : string | void => {
17
+ // ensure displayName passes through, assuming it has been captured by Babel
18
+ if ( data && data . ___displayName ) {
19
+ return String ( data . ___displayName ) ;
20
+ // or it might be obtainable from the converter logic in `packages/extract-react-types/src/converter`
21
+ } else if ( data && data . name && data . name . name ) {
22
+ return String ( data . name . name ) ;
23
+ }
24
+
25
+ return undefined ;
26
+ } ;
You can’t perform that action at this time.
0 commit comments