[storybook__addon-knobs] Add missing type overload for options… (#36328)

It's possible to pass an array of default values to optionsKnob and subsequently have an array of selected options returned. This PR adds an overload type to allow that behaviour.
This commit is contained in:
Chris Hayes
2019-07-01 15:53:47 -04:00
committed by Ryan Cavanaugh
parent 5502326a0a
commit eeb2e724bc
2 changed files with 26 additions and 0 deletions

View File

@@ -85,6 +85,15 @@ export function optionsKnob<T>(
options?: OptionsKnobOptions
): T;
export function optionsKnob<T>(
label: string,
values: {
[key: string]: T;
},
defaultValue?: T[],
options?: OptionsKnobOptions
): T[];
export interface WrapStoryProps {
context?: object;
storyFn?: RenderFunction;

View File

@@ -15,6 +15,7 @@ import {
button,
knob,
radios,
optionsKnob as options,
} from '@storybook/addon-knobs';
enum SomeEnum {
@@ -132,3 +133,19 @@ select<any>('label', { option: 'Option' }, null, groupId);
files('label', 'image/*', []);
date('label', new Date(), groupId);
button('label', () => undefined, groupId);
// optionsKnob
type Tool = 'hammer' | 'saw' | 'drill';
const visibleToolOptions: { [key: string]: Tool } = { hammer: 'hammer', saw: 'saw', drill: 'drill' };
// test selecting one option
const defaultVisibleTool = 'hammer';
const singleSelection: Tool = options<Tool>('visibleTools', visibleToolOptions, defaultVisibleTool, {
display: 'check',
});
// test selecting multiple options
const defaultVisibleTools: Tool[] = ['hammer'];
const multiSelection: Tool[] = options<Tool>('visibleTools', visibleToolOptions, defaultVisibleTools, {
display: 'check',
});