Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number knob: apply default min/max/step values only in range mode #2437

Merged
merged 3 commits into from
Dec 6, 2017
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
10 changes: 7 additions & 3 deletions addons/knobs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ export function boolean(name, value) {
}

export function number(name, value, options = {}) {
const defaults = {
range: false,
const rangeDefaults = {
min: 0,
max: 10,
step: 1,
};

const mergedOptions = { ...defaults, ...options };
const mergedOptions = options.range
? {
...rangeDefaults,
...options,
}
: options;

const finalOptions = {
...mergedOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5029,6 +5029,11 @@ exports[`Storyshots Addon Knobs.withKnobs tweaks static values 1`] = `
My birthday is:
January 20, 2017
</p>
<p>
I live in NY for
9
years.
</p>
<p>
My wallet contains: $
12.50
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ storiesOf('Addon Knobs.withKnobs', module)
};
const fruit = select('Fruit', fruits, 'apple');
const dollars = number('Dollars', 12.5, { min: 0, max: 100, step: 0.01 });
const years = number('Years in NY', 9);

const backgroundColor = color('background', '#ffff00');
const items = array('Items', ['Laptop', 'Book', 'Whiskey']);
Expand All @@ -79,6 +80,7 @@ storiesOf('Addon Knobs.withKnobs', module)
<div style={style}>
<p>{intro}</p>
<p>My birthday is: {new Date(birthday).toLocaleDateString('en-US', dateOptions)}</p>
<p>I live in NY for {years} years.</p>
<p>My wallet contains: ${dollars.toFixed(2)}</p>
<p>In my backpack, I have:</p>
<ul>{items.map(item => <li key={item}>{item}</li>)}</ul>
Expand Down