-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathprovider.ts
49 lines (43 loc) · 1.17 KB
/
provider.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { ReactNode } from 'react';
import { Channel } from '@storybook/channels';
import { ThemeVars } from '@storybook/theming';
import { API, State, ModuleFn, Root, Group, Story } from '../index';
import { StoryMapper, Refs } from './refs';
import { UIOptions } from './layout';
interface SidebarOptions {
showRoots?: boolean;
collapsedRoots?: string[];
renderLabel?: (item: Root | Group | Story) => ReactNode;
}
type IframeRenderer = (
storyId: string,
viewMode: State['viewMode'],
id: string,
baseUrl: string,
scale: number,
queryParams: Record<string, any>
) => ReactNode;
export interface Provider {
channel?: Channel;
renderPreview?: IframeRenderer;
handleAPI(api: API): void;
getConfig(): {
sidebar?: SidebarOptions;
theme?: ThemeVars;
refs?: Refs;
StoryMapper?: StoryMapper;
[k: string]: any;
} & Partial<UIOptions>;
[key: string]: any;
}
export interface SubAPI {
renderPreview?: Provider['renderPreview'];
}
export const init: ModuleFn = ({ provider, fullAPI }) => {
return {
api: provider.renderPreview ? { renderPreview: provider.renderPreview } : {},
init: () => {
provider.handleAPI(fullAPI);
},
};
};