UNPKG

10.1 kBTypeScriptView Raw
1/// <reference types="webpack-env" />
2import { AnyFramework, InputType, StoryContext as StoryContextForFramework, LegacyStoryFn as LegacyStoryFnForFramework, PartialStoryFn as PartialStoryFnForFramework, ArgsStoryFn as ArgsStoryFnForFramework, StoryFn as StoryFnForFramework, DecoratorFunction as DecoratorFunctionForFramework, LoaderFunction as LoaderFunctionForFramework, StoryId, StoryKind, StoryName, Args } from '@storybook/csf';
3import { Addon } from './index';
4export type { StoryId, StoryKind, StoryName, StoryIdentifier, ViewMode, Args, } from '@storybook/csf';
5export interface ArgType<TArg = unknown> extends InputType {
6 defaultValue?: TArg;
7}
8export declare type ArgTypes<TArgs = Args> = {
9 [key in keyof Partial<TArgs>]: ArgType<TArgs[key]>;
10} & {
11 [key in string]: ArgType<unknown>;
12};
13export declare type Comparator<T> = ((a: T, b: T) => boolean) | ((a: T, b: T) => number);
14export declare type StorySortMethod = 'configure' | 'alphabetical';
15export interface StorySortObjectParameter {
16 method?: StorySortMethod;
17 order?: any[];
18 locales?: string;
19 includeNames?: boolean;
20}
21interface StoryIndexEntry {
22 id: StoryId;
23 name: StoryName;
24 title: string;
25 importPath: string;
26}
27export declare type StorySortComparator = Comparator<[StoryId, any, Parameters, Parameters]>;
28export declare type StorySortParameter = StorySortComparator | StorySortObjectParameter;
29export declare type StorySortComparatorV7 = Comparator<StoryIndexEntry>;
30export declare type StorySortParameterV7 = StorySortComparatorV7 | StorySortObjectParameter;
31export interface OptionsParameter extends Object {
32 storySort?: StorySortParameter;
33 theme?: {
34 base: string;
35 brandTitle?: string;
36 };
37 [key: string]: any;
38}
39export interface Parameters {
40 fileName?: string;
41 options?: OptionsParameter;
42 /** The layout property defines basic styles added to the preview body where the story is rendered. If you pass 'none', no styles are applied. */
43 layout?: 'centered' | 'fullscreen' | 'padded' | 'none';
44 docsOnly?: boolean;
45 [key: string]: any;
46}
47export declare type StoryContext = StoryContextForFramework<AnyFramework>;
48export declare type StoryContextUpdate = Partial<StoryContext>;
49declare type ReturnTypeFramework<ReturnType> = {
50 component: any;
51 storyResult: ReturnType;
52};
53export declare type PartialStoryFn<ReturnType = unknown> = PartialStoryFnForFramework<ReturnTypeFramework<ReturnType>>;
54export declare type LegacyStoryFn<ReturnType = unknown> = LegacyStoryFnForFramework<ReturnTypeFramework<ReturnType>>;
55export declare type ArgsStoryFn<ReturnType = unknown> = ArgsStoryFnForFramework<ReturnTypeFramework<ReturnType>>;
56export declare type StoryFn<ReturnType = unknown> = StoryFnForFramework<ReturnTypeFramework<ReturnType>>;
57export declare type DecoratorFunction<StoryFnReturnType = unknown> = DecoratorFunctionForFramework<ReturnTypeFramework<StoryFnReturnType>>;
58export declare type LoaderFunction = LoaderFunctionForFramework<ReturnTypeFramework<unknown>>;
59export declare enum types {
60 TAB = "tab",
61 PANEL = "panel",
62 TOOL = "tool",
63 TOOLEXTRA = "toolextra",
64 PREVIEW = "preview",
65 NOTES_ELEMENT = "notes-element"
66}
67export declare type Types = types | string;
68export declare function isSupportedType(type: Types): boolean;
69export interface WrapperSettings {
70 options: object;
71 parameters: {
72 [key: string]: any;
73 };
74}
75export declare type StoryWrapper = (storyFn: LegacyStoryFn, context: StoryContext, settings: WrapperSettings) => any;
76export declare type MakeDecoratorResult = (...args: any) => any;
77export interface AddStoryArgs<StoryFnReturnType = unknown> {
78 id: StoryId;
79 kind: StoryKind;
80 name: StoryName;
81 storyFn: StoryFn<StoryFnReturnType>;
82 parameters: Parameters;
83}
84export interface ClientApiAddon<StoryFnReturnType = unknown> extends Addon {
85 apply: (a: StoryApi<StoryFnReturnType>, b: any[]) => any;
86}
87export interface ClientApiAddons<StoryFnReturnType> {
88 [key: string]: ClientApiAddon<StoryFnReturnType>;
89}
90export interface IStorybookStory {
91 name: string;
92 render: (context: any) => any;
93}
94export interface IStorybookSection {
95 kind: string;
96 stories: IStorybookStory[];
97}
98export declare type ClientApiReturnFn<StoryFnReturnType = unknown> = (...args: any[]) => StoryApi<StoryFnReturnType>;
99export interface StoryApi<StoryFnReturnType = unknown> {
100 kind: StoryKind;
101 add: (storyName: StoryName, storyFn: StoryFn<StoryFnReturnType>, parameters?: Parameters) => StoryApi<StoryFnReturnType>;
102 addDecorator: (decorator: DecoratorFunction<StoryFnReturnType>) => StoryApi<StoryFnReturnType>;
103 addLoader: (decorator: LoaderFunction) => StoryApi<StoryFnReturnType>;
104 addParameters: (parameters: Parameters) => StoryApi<StoryFnReturnType>;
105 [k: string]: string | ClientApiReturnFn<StoryFnReturnType>;
106}
107export interface ClientStoryApi<StoryFnReturnType = unknown> {
108 storiesOf(kind: StoryKind, module: NodeModule): StoryApi<StoryFnReturnType>;
109 addDecorator(decorator: DecoratorFunction<StoryFnReturnType>): StoryApi<StoryFnReturnType>;
110 addParameters(parameter: Parameters): StoryApi<StoryFnReturnType>;
111}
112declare type LoadFn = () => any;
113declare type RequireContext = any;
114export declare type Loadable = RequireContext | [RequireContext] | LoadFn;
115export declare type BaseDecorators<StoryFnReturnType> = Array<(story: () => StoryFnReturnType, context: StoryContext) => StoryFnReturnType>;
116export interface BaseAnnotations<Args, StoryFnReturnType> {
117 /**
118 * Dynamic data that are provided (and possibly updated by) Storybook and its addons.
119 * @see [Arg story inputs](https://storybook.js.org/docs/react/api/csf#args-story-inputs)
120 */
121 args?: Partial<Args>;
122 /**
123 * ArgTypes encode basic metadata for args, such as `name`, `description`, `defaultValue` for an arg. These get automatically filled in by Storybook Docs.
124 * @see [Control annotations](https://github.com/storybookjs/storybook/blob/91e9dee33faa8eff0b342a366845de7100415367/addons/controls/README.md#control-annotations)
125 */
126 argTypes?: ArgTypes<Args>;
127 /**
128 * Custom metadata for a story.
129 * @see [Parameters](https://storybook.js.org/docs/basics/writing-stories/#parameters)
130 */
131 parameters?: Parameters;
132 /**
133 * Wrapper components or Storybook decorators that wrap a story.
134 *
135 * Decorators defined in Meta will be applied to every story variation.
136 * @see [Decorators](https://storybook.js.org/docs/addons/introduction/#1-decorators)
137 */
138 decorators?: BaseDecorators<StoryFnReturnType>;
139 /**
140 * Define a custom render function for the story(ies). If not passed, a default render function by the framework will be used.
141 */
142 render?: (args: Args, context: StoryContext) => StoryFnReturnType;
143 /**
144 * Function that is executed after the story is rendered.
145 */
146 play?: (context: StoryContext) => Promise<void> | void;
147}
148export interface Annotations<Args, StoryFnReturnType> extends BaseAnnotations<Args, StoryFnReturnType> {
149 /**
150 * Used to only include certain named exports as stories. Useful when you want to have non-story exports such as mock data or ignore a few stories.
151 * @example
152 * includeStories: ['SimpleStory', 'ComplexStory']
153 * includeStories: /.*Story$/
154 *
155 * @see [Non-story exports](https://storybook.js.org/docs/formats/component-story-format/#non-story-exports)
156 */
157 includeStories?: string[] | RegExp;
158 /**
159 * Used to exclude certain named exports. Useful when you want to have non-story exports such as mock data or ignore a few stories.
160 * @example
161 * excludeStories: ['simpleData', 'complexData']
162 * excludeStories: /.*Data$/
163 *
164 * @see [Non-story exports](https://storybook.js.org/docs/formats/component-story-format/#non-story-exports)
165 */
166 excludeStories?: string[] | RegExp;
167}
168export interface BaseMeta<ComponentType> {
169 /**
170 * Title of the story which will be presented in the navigation. **Should be unique.**
171 *
172 * Stories can be organized in a nested structure using "/" as a separator.
173 *
174 * Since CSF 3.0 this property is optional.
175 *
176 * @example
177 * export default {
178 * ...
179 * title: 'Design System/Atoms/Button'
180 * }
181 *
182 * @see [Story Hierarchy](https://storybook.js.org/docs/basics/writing-stories/#story-hierarchy)
183 */
184 title?: string;
185 /**
186 * Manually set the id of a story, which in particular is useful if you want to rename stories without breaking permalinks.
187 *
188 * Storybook will prioritize the id over the title for ID generation, if provided, and will prioritize the story.storyName over the export key for display.
189 *
190 * @see [Sidebar and URLs](https://storybook.js.org/docs/react/configure/sidebar-and-urls#permalinking-to-stories)
191 */
192 id?: string;
193 /**
194 * The primary component for your story.
195 *
196 * Used by addons for automatic prop table generation and display of other component metadata.
197 */
198 component?: ComponentType;
199 /**
200 * Auxiliary subcomponents that are part of the stories.
201 *
202 * Used by addons for automatic prop table generation and display of other component metadata.
203 *
204 * @example
205 * import { Button, ButtonGroup } from './components';
206 *
207 * export default {
208 * ...
209 * subcomponents: { Button, ButtonGroup }
210 * }
211 *
212 * By defining them each component will have its tab in the args table.
213 */
214 subcomponents?: Record<string, ComponentType>;
215}
216export declare type BaseStoryObject<Args, StoryFnReturnType> = {
217 /**
218 * Override the display name in the UI
219 */
220 storyName?: string;
221};
222export declare type BaseStoryFn<Args, StoryFnReturnType> = {
223 (args: Args, context: StoryContext): StoryFnReturnType;
224} & BaseStoryObject<Args, StoryFnReturnType>;
225export declare type BaseStory<Args, StoryFnReturnType> = BaseStoryFn<Args, StoryFnReturnType> | BaseStoryObject<Args, StoryFnReturnType>;