mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-16 15:00:26 +00:00
@storybook/react add-on type definitions (#18814)
* @storbook/react add-on type definitions * use this type
This commit is contained in:
committed by
Mohamed Hegazy
parent
967578c54c
commit
54c84b9b50
Vendored
+3
-2
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user