Merge pull request #27822 from amacleay/storybook-knobs-allow-readonly

Allow readonly parameters to @storybook/addon-knobs
This commit is contained in:
Ron Buckton
2018-08-08 13:26:11 -07:00
committed by GitHub
2 changed files with 11 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
// Project: https://github.com/storybooks/storybook
// Definitions by: Joscha Feth <https://github.com/joscha>
// Martynas Kadisa <https://github.com/martynaskadisa>
// A.MacLeay <https://github.com/amacleay>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
@@ -49,14 +50,14 @@ export function object<T>(name: string, value: T, groupId?: string): T;
export type SelectValue = string | number;
export function select<T extends string>(name: string, options: { [s: string]: string }, value: T, groupId?: string): T;
export function select<T extends number>(name: string, options: { [s: number]: string }, value: T, groupId?: string): T;
export function select<T extends SelectValue>(name: string, options: T[], value: T, groupId?: string): T;
export function select<T extends SelectValue>(name: string, options: ReadonlyArray<T>, value: T, groupId?: string): T;
export function selectV2<T extends string | number>(name: string, options: { [s: string]: T | T[] }, value: T | T[], groupId?: string): T;
export function selectV2<T extends SelectValue>(name: string, options: T[], value: T, groupId?: string): T;
export function date(name: string, value?: Date, groupId?: string): Date;
export function array<T>(name: string, value: T[], separator?: string, groupId?: string): T[];
export function array<T>(name: string, value: ReadonlyArray<T>, separator?: string, groupId?: string): T[];
export function button(name: string, handler: () => any, groupId?: string): void;

View File

@@ -94,6 +94,14 @@ stories.add('dynamic knobs', () => {
);
});
const readonlyOptionsArray: ReadonlyArray<string> = ['hi'];
select('With readonly array', readonlyOptionsArray, readonlyOptionsArray[0]);
const genericArray = array('With regular array', ['hi', 'there']);
const userInputArray = array('With readonly array', readonlyOptionsArray);
userInputArray.push('Make sure that the output is still mutable although the input need not be!');
// groups
const groupId = 'GROUP-ID1';