@storybook/react add-on type definitions (#18814)

* @storbook/react add-on type definitions

* use this type
This commit is contained in:
Joscha Feth
2017-08-14 12:38:10 -07:00
committed by Mohamed Hegazy
parent 967578c54c
commit 54c84b9b50
2 changed files with 13 additions and 5 deletions
+3 -2
View File
@@ -14,8 +14,9 @@ export type RenderFunction = () => Renderable;
export type StoryDecorator = (story: RenderFunction, context: { kind: string, story: string }) => Renderable | null;
export interface Story {
add(storyName: string, callback: RenderFunction): Story;
addDecorator(decorator: StoryDecorator): Story;
readonly kind: string;
add(storyName: string, callback: RenderFunction): this;
addDecorator(decorator: StoryDecorator): this;
}
export function addDecorator(decorator: StoryDecorator): void;
@@ -13,13 +13,20 @@ addDecorator(Decorator);
// setAddon
interface AnyAddon {
xyz(): void;
addWithSideEffect<T>(this: Story & T, storyName: string, storyFn: RenderFunction): Story & T;
}
const AnyAddon: AnyAddon = {
xyz() {}
addWithSideEffect<T>(this: Story & T, storyName: string, storyFn: RenderFunction): Story & T {
console.log(this.kind === 'withAnyAddon');
return this.add(storyName, storyFn);
}
};
setAddon(AnyAddon);
storiesOf<AnyAddon>('withAnyAddon', module).xyz();
storiesOf<AnyAddon>('withAnyAddon', module)
.addWithSideEffect('custom story', () => <div/>)
.addWithSideEffect('more', () => <div/>)
.add('another story', () => <div/>)
.addWithSideEffect('even more', () => <div/>);
// configure
configure(() => undefined, module);