Skip to content

Commit

Permalink
Merge pull request #1001 from marcfallows/number-types
Browse files Browse the repository at this point in the history
Fixes for types for knobs `number`
  • Loading branch information
ndelangen authored May 9, 2017
2 parents 119d634 + 7620861 commit 7910ae6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 6 additions & 2 deletions packages/addon-knobs/example/typescript/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ stories.add('with all knobs', () => {
const dob = date('DOB', new Date('January 20 1887'));

const bold = boolean('Bold', false);
const color = color('Color', 'black');
const selectedColor = color('Color', 'black');
const favoriteNumber = number('Favorite Number', 42);
const comfortTemp = number('Comfort Temp', 72, { range: true, min: 60, max: 90, step: 1 });
const textDecoration = select('Decoration', {
none: 'None',
underline: 'Underline',
Expand All @@ -39,13 +41,15 @@ stories.add('with all knobs', () => {

const style = Object.assign({}, customStyle, {
fontWeight: bold ? 800: 400,
color,
color: selectedColor,
textDecoration
});

return (
<div style={style}>
I'm {name} and I was born on "{moment(dob).format("DD MMM YYYY")}"
<p>My favorite number is {favoriteNumber}.</p>
<p>My most comfortable room temperature is {comfortTemp} degrees Fahrenheit.</p>
</div>
);
});
Expand Down
9 changes: 8 additions & 1 deletion packages/addon-knobs/storybook-addon-knobs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ interface StoryContext {
story: string,
}

interface NumberOptions {
range: boolean,
min: number,
max: number,
step: number,
}

export function knob<T>(name: string, options: KnobOption<T>): T;

export function text(name: string, value: string | null): string;

export function boolean(name: string, value: boolean): boolean;

export function number(name: string, value: number): number;
export function number(name: string, value: number, options?: NumberOptions): number;

export function color(name: string, value: string): string;

Expand Down

0 comments on commit 7910ae6

Please sign in to comment.