mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
add typings for @storybook/html (#35598)
This commit is contained in:
committed by
Ryan Cavanaugh
parent
dccdbbd718
commit
43ddae1d7d
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
// Type definitions for @storybook/html 5.0
|
||||
// Project: https://github.com/storybooks/storybook, https://github.com/storybooks/storybook/tree/master/app/html
|
||||
// Definitions by: Christian Murphy <https://github.com/ChristianMurphy>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
/// <reference types="webpack-env" />
|
||||
|
||||
export type RenderFunction = () => string | string[];
|
||||
|
||||
export interface DecoratorParameters {
|
||||
[key: string]: any;
|
||||
}
|
||||
export type StoryDecorator = (story: RenderFunction, context: { kind: string, story: string }) => string | null;
|
||||
|
||||
export interface Story {
|
||||
readonly kind: string;
|
||||
add(storyName: string, callback: RenderFunction, parameters?: DecoratorParameters): this;
|
||||
addDecorator(decorator: StoryDecorator): this;
|
||||
addParameters(parameters: DecoratorParameters): this;
|
||||
}
|
||||
|
||||
export function addDecorator(decorator: StoryDecorator): void;
|
||||
export function addParameters(parameters: DecoratorParameters): void;
|
||||
export function clearDecorators(): void;
|
||||
export function configure(fn: () => void, module: NodeModule): void;
|
||||
export function setAddon(addon: object): void;
|
||||
export function storiesOf(name: string, module: NodeModule): Story;
|
||||
export function storiesOf<T>(name: string, module: NodeModule): Story & T;
|
||||
export function forceReRender(): void;
|
||||
|
||||
export interface StoryObject {
|
||||
name: string;
|
||||
render: RenderFunction;
|
||||
}
|
||||
|
||||
export interface StoryBucket {
|
||||
kind: string;
|
||||
stories: StoryObject[];
|
||||
}
|
||||
|
||||
export function getStorybook(): StoryBucket[];
|
||||
@@ -0,0 +1,43 @@
|
||||
import { storiesOf, setAddon, addDecorator, addParameters, configure, getStorybook, RenderFunction, Story, forceReRender, DecoratorParameters, clearDecorators } from '@storybook/html';
|
||||
|
||||
const Decorator = (story: RenderFunction) => `<div>${story()}</div>`;
|
||||
const parameters: DecoratorParameters = { parameter: 'foo' };
|
||||
|
||||
forceReRender();
|
||||
|
||||
storiesOf('Welcome', module)
|
||||
// local addDecorator
|
||||
.addDecorator(Decorator)
|
||||
.add('to Storybook', () => "<div></div>")
|
||||
.add('to Storybook as Array', () => ["<div></div>", "<div></div>"])
|
||||
.add('and a story with additional parameters', () => "<div></div>", parameters);
|
||||
|
||||
// global addDecorator
|
||||
addDecorator(Decorator);
|
||||
addParameters(parameters);
|
||||
clearDecorators();
|
||||
|
||||
// setAddon
|
||||
interface AnyAddon {
|
||||
addWithSideEffect<T>(this: Story & T, storyName: string, storyFn: RenderFunction): Story & T;
|
||||
}
|
||||
const AnyAddon: AnyAddon = {
|
||||
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)
|
||||
.addWithSideEffect('custom story', () => "<div></div>")
|
||||
.addWithSideEffect('more', () => "<div></div>")
|
||||
.add('another story', () => "<div></div>")
|
||||
.add('to Storybook as Array', () => ["<div></div>", "<div></div>"])
|
||||
.add('and a story with additional parameters', () => "<div></div>", parameters)
|
||||
.addWithSideEffect('even more', () => "<div></div>");
|
||||
|
||||
// configure
|
||||
configure(() => undefined, module);
|
||||
|
||||
// getStorybook
|
||||
getStorybook().forEach(({ kind, stories }) => stories.forEach(({ name, render }) => render()));
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"dom",
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"jsx": "preserve",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"paths": {
|
||||
"@storybook/html": [
|
||||
"storybook__html"
|
||||
]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"storybook__html-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"no-unnecessary-generics": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user