-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
render.js
35 lines (31 loc) · 878 Bytes
/
render.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { document, Node } from 'global';
import { stripIndents } from 'common-tags';
const rootElement = document.getElementById('root');
export default function renderMain({
storyFn,
selectedKind,
selectedStory,
showMain,
showError,
forceRender,
}) {
const element = storyFn();
showMain();
if (typeof element === 'string') {
rootElement.innerHTML = element;
} else if (element instanceof Node) {
if (forceRender === true) {
return;
}
rootElement.innerHTML = '';
rootElement.appendChild(element);
} else {
showError({
title: `Expecting an HTML snippet or DOM node from the story: "${selectedStory}" of "${selectedKind}".`,
description: stripIndents`
Did you forget to return the HTML snippet from the story?
Use "() => <your snippet or node>" or when defining the story.
`,
});
}
}