Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is changed because TS should complain about block scoping when trying to override color. Updated to use a different name (which lines up with the storybook example).

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