-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
prepareForInline.ts
35 lines (31 loc) · 973 Bytes
/
prepareForInline.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
34
35
import React from 'react';
import pLimit from 'p-limit';
import { nanoid } from 'nanoid';
import { AngularFramework, StoryContext } from '@storybook/angular';
import { rendererFactory } from '@storybook/angular/renderer';
import { PartialStoryFn } from '@storybook/csf';
const limit = pLimit(1);
/**
* Uses the angular renderer to generate a story. Uses p-limit to run synchronously
*/
export const prepareForInline = (
storyFn: PartialStoryFn<AngularFramework>,
{ id, parameters }: StoryContext
) => {
return React.createElement('div', {
ref: async (node?: HTMLDivElement): Promise<void> => {
if (!node) {
return null;
}
return limit(async () => {
const renderer = await rendererFactory.getRendererInstance(`${id}-${nanoid(10)}`, node);
await renderer.render({
forced: false,
parameters,
storyFnAngular: storyFn(),
targetDOMNode: node,
});
});
},
});
};