Skip to content

Commit

Permalink
Addon-knobs: select support for enum=like record types
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio-martinez committed Jul 17, 2019
1 parent 0ef6675 commit d3d6548
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion addons/knobs/src/__types__/knob-test-cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ enum SomeEnum {
Type1 = 1,
Type2,
}
enum ButtonVariant {
primary = 'primary',
secondary = 'secondary',
}
const stringLiteralArray: ('Apple' | 'Banana' | 'Grapes')[] = ['Apple', 'Banana', 'Grapes'];

expectKnobOfType<string>(
Expand All @@ -101,13 +105,14 @@ expectKnobOfType<string>(
select('select with string array', ['yes', 'no'], 'yes'),
select('select with string literal array', stringLiteralArray, stringLiteralArray[0]),
select('select with readonly array', ['red', 'blue'] as const, 'red'),
select<ButtonVariant>('select with string enum options', ButtonVariant, ButtonVariant.primary),
select('select with null option', { a: 'Option', b: null }, null, groupId)
);

expectKnobOfType<number>(
select('select with number options', { 'type a': 1, 'type b': 2 }, 1),
select<SomeEnum>(
'select with enum options',
'select with numeric enum options',
{ 'type a': SomeEnum.Type1, 'type b': SomeEnum.Type2 },
SomeEnum.Type2
),
Expand Down
1 change: 1 addition & 0 deletions addons/knobs/src/components/types/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type SelectTypeKnobValue = string | number | null | undefined;

export type SelectTypeOptionsProp<T extends SelectTypeKnobValue = SelectTypeKnobValue> =
| Record<string, T>
| Record<T, T[keyof T]>
| T[]
| readonly T[];

Expand Down

0 comments on commit d3d6548

Please sign in to comment.