-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
render.ts
33 lines (29 loc) · 867 Bytes
/
render.ts
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
import { document } from 'global';
import dedent from 'ts-dedent';
import { render } from 'lit';
import { isTemplateResult } from 'lit/directive-helpers.js';
import { RenderContext } from './types';
const rootElement = document.getElementById('root');
export default function renderMain({
storyFn,
kind,
name,
showError,
targetDOMNode = rootElement,
}: RenderContext) {
const element = storyFn();
if (targetDOMNode === null) {
return;
}
if (isTemplateResult(element) && targetDOMNode) {
render(element, targetDOMNode);
} else {
showError({
title: `Expecting an lit template result from the story: "${name}" of "${kind}".`,
description: dedent`
Did you forget to return the lit template result from the story?
Use "() => html\`<your snippet or node>\`" or when defining the story.
`,
});
}
}