@@ -20,23 +20,26 @@ const Readme = props => {
20
20
useEffect ( ( ) => {
21
21
const api = props . api ;
22
22
api . on ( STORY_RENDERED , eventData => {
23
+ setMarkdown ( '' ) ;
23
24
const component = api . getCurrentStoryData ( ) . component ;
24
- const readme =
25
- require ( `!raw-loader!../../packages/${ component } /README.md` ) . default ;
25
+ if ( component ) {
26
+ const readme =
27
+ require ( `!raw-loader!../../packages/${ component } /README.md` ) . default ;
26
28
27
- setMarkdown ( readme ) ;
29
+ setMarkdown ( readme ) ;
28
30
29
- const syntaxHighlighters = document . querySelectorAll (
30
- '.storybook-readme-syntax-highlighter'
31
- ) ;
31
+ const syntaxHighlighters = document . querySelectorAll (
32
+ '.storybook-readme-syntax-highlighter'
33
+ ) ;
32
34
33
- if ( syntaxHighlighters . length > 0 ) {
34
- for ( const item of syntaxHighlighters ) {
35
- item . style . display = 'none' ;
36
- const children = item . children ;
37
- const parent = item . parentElement ;
35
+ if ( syntaxHighlighters . length > 0 ) {
36
+ for ( const item of syntaxHighlighters ) {
37
+ item . style . display = 'none' ;
38
+ const children = item . children ;
39
+ const parent = item . parentElement ;
38
40
39
- parent . append ( ...children ) ;
41
+ parent . append ( ...children ) ;
42
+ }
40
43
}
41
44
}
42
45
} ) ;
@@ -71,9 +74,15 @@ const Readme = props => {
71
74
/>
72
75
) ;
73
76
77
+ const renderNoReadme = ( ) => (
78
+ < div >
79
+ < h3 > There's no readme for this component</ h3 >
80
+ </ div >
81
+ ) ;
82
+
74
83
return (
75
84
< div className = "markdown-body" style = { { padding : '32px' } } >
76
- { renderReadme ( ) }
85
+ { markdown ? renderReadme ( ) : renderNoReadme ( ) }
77
86
</ div >
78
87
) ;
79
88
} ;
0 commit comments