-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
/
types.ts
105 lines (88 loc) · 2.79 KB
/
types.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { HooksContext } from './hooks';
import { Addon } from './index';
export enum types {
TAB = 'tab',
PANEL = 'panel',
TOOL = 'tool',
PREVIEW = 'preview',
NOTES_ELEMENT = 'notes-element',
}
export type Types = types | string;
export function isSupportedType(type: Types): boolean {
return !!Object.values(types).find(typeVal => typeVal === type);
}
export interface Parameters {
fileName?: string;
options?: OptionsParameter;
[key: string]: any;
}
export interface StoryContext {
id: string;
name: string;
kind: string;
[key: string]: any;
parameters: Parameters;
hooks?: HooksContext;
}
export interface WrapperSettings {
options: OptionsParameter;
parameters: {
[key: string]: any;
};
}
export interface OptionsParameter extends Object {
storySort?: any;
hierarchyRootSeparator?: string;
hierarchySeparator?: RegExp;
showRoots?: boolean;
theme?: {
base: string;
brandTitle?: string;
};
[key: string]: any;
}
export type StoryGetter = (context: StoryContext) => any;
export type StoryFn<ReturnType = unknown> = (p?: StoryContext) => ReturnType;
export type StoryWrapper = (
getStory: StoryGetter,
context: StoryContext,
settings: WrapperSettings
) => any;
export type MakeDecoratorResult = (...args: any) => any;
export interface AddStoryArgs<StoryFnReturnType = unknown> {
id: string;
kind: string;
name: string;
storyFn: StoryFn<StoryFnReturnType>;
parameters: Parameters;
}
export interface ClientApiAddon<StoryFnReturnType = unknown> extends Addon {
apply: (a: StoryApi<StoryFnReturnType>, b: any[]) => any;
}
export interface ClientApiAddons<StoryFnReturnType> {
[key: string]: ClientApiAddon<StoryFnReturnType>;
}
export type ClientApiReturnFn<StoryFnReturnType> = (...args: any[]) => StoryApi<StoryFnReturnType>;
export interface StoryApi<StoryFnReturnType = unknown> {
kind: string;
add: (
storyName: string,
storyFn: StoryFn<StoryFnReturnType>,
parameters?: Parameters
) => StoryApi<StoryFnReturnType>;
addDecorator: (decorator: DecoratorFunction<StoryFnReturnType>) => StoryApi<StoryFnReturnType>;
addParameters: (parameters: Parameters) => StoryApi<StoryFnReturnType>;
[k: string]: string | ClientApiReturnFn<StoryFnReturnType>;
}
export type DecoratorFunction<StoryFnReturnType = unknown> = (
fn: StoryFn<StoryFnReturnType>,
c: StoryContext
) => ReturnType<StoryFn<StoryFnReturnType>>;
export interface ClientStoryApi<StoryFnReturnType = unknown> {
storiesOf(kind: string, module: NodeModule): StoryApi<StoryFnReturnType>;
addDecorator(decorator: DecoratorFunction<StoryFnReturnType>): StoryApi<StoryFnReturnType>;
addParameters(parameter: Parameters): StoryApi<StoryFnReturnType>;
}
type LoadFn = () => any;
type RequireContext = any; // FIXME
export type Loadable = RequireContext | [RequireContext] | LoadFn;