mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-07-01 15:50:13 +00:00
[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:
committed by
Ryan Cavanaugh
parent
5502326a0a
commit
eeb2e724bc
9
types/storybook__addon-knobs/index.d.ts
vendored
9
types/storybook__addon-knobs/index.d.ts
vendored
@@ -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;
|
||||
|
||||
@@ -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',
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user