Merge branch 'prannayb-patch-1'

This commit is contained in:
Andy Hanson
2017-10-16 08:21:03 -07:00
2 changed files with 19 additions and 3 deletions

View File

@@ -37,8 +37,10 @@ export function color(name: string, value: string): string;
export function object<T>(name: string, value: T): T;
export function select<T>(name: string, options: { [s: string]: T }, value: string): T;
export function select(name: string, options: string[], value: string): string;
export type SelectValue = string | number;
export function select<T extends string>(name: string, options: { [s: string]: string }, value: T): T;
export function select<T extends number>(name: string, options: { [s: number]: string }, value: T): T;
export function select<T extends SelectValue>(name: string, options: T[], value: T): T;
export function date(name: string, value?: Date): Date;

View File

@@ -14,6 +14,11 @@ import {
knob,
} from '@storybook/addon-knobs';
enum SomeEnum {
Type1 = 1,
Type2
}
const stories = storiesOf('Example of Knobs', module);
stories.addDecorator(withKnobs);
@@ -39,9 +44,18 @@ stories.add('with all knobs', () => {
});
const genericObject: string = object<string>('Some generic object', 'value');
type X = 'a' | 'b';
const genericSelect: X = select<X>('Some generic select', { a: 'a', b: 'b'}, 'b');
const genericSelect: X = select<X>('Some generic select', { a: 'type a', b: 'type b'}, 'b');
const enumSelectOptions: { [s: number]: string } = {};
enumSelectOptions[SomeEnum.Type1] = "Type 1";
enumSelectOptions[SomeEnum.Type2] = "Type 2";
const genericSelect2: SomeEnum = select<SomeEnum>('Some generic select', enumSelectOptions, SomeEnum.Type1);
const genericArray: string[] = array<string>('Some generic array', ['red', 'green', 'blue']);
const genericKnob: X = knob<X>('Some generic knob', { value: 'a', type: 'text' });
const style = {