mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-01 07:40:10 +00:00
Add types for @storybook/addon-viewport
This commit is contained in:
42
types/storybook__addon-viewport/index.d.ts
vendored
Normal file
42
types/storybook__addon-viewport/index.d.ts
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
// Type definitions for @storybook/addon-viewport 4.1
|
||||
// Project: https://github.com/storybooks/storybook/tree/master/addons/viewport
|
||||
// Definitions by: Vincent Tunru <https://github.com/Vinnl>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import { StoryDecorator } from '@storybook/react';
|
||||
|
||||
export type ViewportName = string;
|
||||
|
||||
export interface ViewportProperties {
|
||||
name: ViewportName;
|
||||
styles: {
|
||||
width?: string,
|
||||
height?: string,
|
||||
[styleName: string]: any,
|
||||
};
|
||||
type?: 'desktop' | 'tablet' | 'mobile' | string;
|
||||
}
|
||||
export interface ViewportDecoratorOptions {
|
||||
/**
|
||||
* Default viewport
|
||||
*/
|
||||
name?: ViewportName;
|
||||
/**
|
||||
* Called whenever different viewport is selected from the dropdown
|
||||
*/
|
||||
onViewportChange: (change: { viewport: ViewportProperties }) => void;
|
||||
}
|
||||
export interface ViewportDefinitions {
|
||||
[viewportKey: string]: ViewportProperties;
|
||||
}
|
||||
export type Viewport = ViewportName | ViewportDecoratorOptions;
|
||||
|
||||
export interface ViewportConfiguration {
|
||||
viewports?: ViewportDefinitions;
|
||||
defaultViewport?: ViewportName;
|
||||
}
|
||||
|
||||
export const INITIAL_VIEWPORTS: ViewportDefinitions;
|
||||
export function configureViewport(configuration: ViewportConfiguration): void;
|
||||
export function withViewport(viewport?: Viewport): StoryDecorator;
|
||||
@@ -0,0 +1,33 @@
|
||||
import { configureViewport, INITIAL_VIEWPORTS, withViewport } from '@storybook/addon-viewport';
|
||||
|
||||
import { storiesOf } from '@storybook/react';
|
||||
|
||||
const minimalViewport = {
|
||||
name: 'Viewport with minimal amount of configuration',
|
||||
styles: {
|
||||
width: '450px',
|
||||
height: '150px',
|
||||
},
|
||||
};
|
||||
const maximalViewport = {
|
||||
name: 'Viewport that also sets its type',
|
||||
styles: {
|
||||
width: '230px',
|
||||
height: '300px',
|
||||
},
|
||||
type: 'desktop',
|
||||
};
|
||||
configureViewport({
|
||||
viewports: { ...INITIAL_VIEWPORTS, minimalViewport, maximalViewport },
|
||||
});
|
||||
configureViewport({
|
||||
defaultViewport: 'minimalViewport',
|
||||
});
|
||||
|
||||
const stories = storiesOf('Example of Knobs', module);
|
||||
|
||||
stories.addDecorator(withViewport());
|
||||
stories.addDecorator(withViewport('viewportName'));
|
||||
stories.addDecorator(withViewport({
|
||||
onViewportChange: ({ viewport }) => `Viewport changed: ${viewport.name} (${viewport.type})`,
|
||||
}));
|
||||
31
types/storybook__addon-viewport/tsconfig.json
Normal file
31
types/storybook__addon-viewport/tsconfig.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"paths": {
|
||||
"@storybook/addon-viewport": [
|
||||
"storybook__addon-viewport"
|
||||
],
|
||||
"@storybook/react": [
|
||||
"storybook__react"
|
||||
]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"storybook__addon-viewport-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/storybook__addon-viewport/tslint.json
Normal file
1
types/storybook__addon-viewport/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user