Skip to content

Commit 64bd1eb

Browse files
committed
Show no readme screen when there's no readme
1 parent f1599dd commit 64bd1eb

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

storyhelpers/storybook-readme/register.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,26 @@ const Readme = props => {
2020
useEffect(() => {
2121
const api = props.api;
2222
api.on(STORY_RENDERED, eventData => {
23+
setMarkdown('');
2324
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;
2628

27-
setMarkdown(readme);
29+
setMarkdown(readme);
2830

29-
const syntaxHighlighters = document.querySelectorAll(
30-
'.storybook-readme-syntax-highlighter'
31-
);
31+
const syntaxHighlighters = document.querySelectorAll(
32+
'.storybook-readme-syntax-highlighter'
33+
);
3234

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;
3840

39-
parent.append(...children);
41+
parent.append(...children);
42+
}
4043
}
4144
}
4245
});
@@ -71,9 +74,15 @@ const Readme = props => {
7174
/>
7275
);
7376

77+
const renderNoReadme = () => (
78+
<div>
79+
<h3>There's no readme for this component</h3>
80+
</div>
81+
);
82+
7483
return (
7584
<div className="markdown-body" style={{ padding: '32px' }}>
76-
{renderReadme()}
85+
{markdown ? renderReadme() : renderNoReadme()}
7786
</div>
7887
);
7988
};

0 commit comments

Comments
 (0)