Types for Storybook (React Native version). These shares same interface as the React one so just proxies to storybook__react types

This commit is contained in:
Alec Hill
2018-06-21 16:40:41 +01:00
parent 18fd3f98b4
commit e8008599da
4 changed files with 84 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
// Type definitions for @storybook/react-native 3.0
// Project: https://github.com/storybooks/storybook
// Definitions by: Joscha Feth <https://github.com/joscha>
// Anton Izmailov <https://github.com/wapgear>
// Alec Hill <https://github.com/alechill>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.6
import * as Storybook from '@storybook/react';
export = Storybook;
@@ -0,0 +1,37 @@
import * as React from 'react';
import { storiesOf, setAddon, addDecorator, configure, getStorybook, RenderFunction, Story } from '@storybook/react-native';
const Decorator = (story: RenderFunction) => <div>{story()}</div>;
storiesOf('Welcome', module)
// local addDecorator
.addDecorator(Decorator)
.add('to Storybook', () => <div/>)
.add('to Storybook as Array', () => [<div />, <div />]);
// global addDecorator
addDecorator(Decorator);
// 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/>)
.addWithSideEffect('more', () => <div/>)
.add('another story', () => <div/>)
.add('to Storybook as Array', () => [<div />, <div />])
.addWithSideEffect('even more', () => <div/>);
// configure
configure(() => undefined, module);
// getStorybook
getStorybook().forEach(({ kind, stories }) => stories.forEach(({ name, render }) => render()));
@@ -0,0 +1,33 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"dom",
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"jsx": "react",
"typeRoots": [
"../"
],
"paths": {
"@storybook/react-native": [
"storybook__react-native"
],
"@storybook/react": [
"storybook__react"
]
},
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"storybook__react-native-tests.tsx"
]
}
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}