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

Fixed addon knobs proptypes deserialization #1290

Merged
merged 8 commits into from
Jun 17, 2017
2 changes: 1 addition & 1 deletion addons/knobs/src/components/types/Array.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ ArrayType.defaultProps = {
ArrayType.propTypes = {
knob: PropTypes.shape({
name: PropTypes.string,
value: PropTypes.string,
value: PropTypes.array,
}),
onChange: PropTypes.func,
};
Expand Down
4 changes: 2 additions & 2 deletions addons/knobs/src/components/types/Boolean.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ BooleanType.defaultProps = {
BooleanType.propTypes = {
knob: PropTypes.shape({
name: PropTypes.string,
value: PropTypes.string,
value: PropTypes.bool,
}),
onChange: PropTypes.func,
};

BooleanType.serialize = value => String(value);
BooleanType.deserialize = value => (typeof value === 'string' ? value.match('true') : false);
BooleanType.deserialize = value => value === 'true';

export default BooleanType;
2 changes: 1 addition & 1 deletion addons/knobs/src/components/types/Date/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ DateType.defaultProps = {
DateType.propTypes = {
knob: PropTypes.shape({
name: PropTypes.string,
value: PropTypes.string,
value: PropTypes.number,
}),
onChange: PropTypes.func,
};
Expand Down
2 changes: 1 addition & 1 deletion addons/knobs/src/components/types/Object.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ ObjectType.defaultProps = {
ObjectType.propTypes = {
knob: PropTypes.shape({
name: PropTypes.string,
value: PropTypes.string,
value: PropTypes.object,
}),
onChange: PropTypes.func,
};
Expand Down
53 changes: 48 additions & 5 deletions examples/cra-kitchen-sink/src/stories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ import { action } from '@storybook/addon-actions';
import { linkTo } from '@storybook/addon-links';
import WithEvents from '@storybook/addon-events';
import { WithNotes } from '@storybook/addon-notes';
import { withKnobs, text, number } from '@storybook/addon-knobs';
import {
withKnobs,
text,
number,
boolean,
color,
select,
array,
date,
object,
} from '@storybook/addon-knobs';
import centered from '@storybook/addon-centered';

import Button from '@storybook/components/dist/demo/Button';
Expand Down Expand Up @@ -37,11 +47,44 @@ storiesOf('Button', module)
</WithNotes>
)
.add('with knobs', () => {
const label = text('Label', 'Edit me in knobs panel');
const num = number('Number', 1);
const content = `I am ${label} and I'm ${num} years old.`;
const name = text('Name', 'Storyteller');
const age = number('Age', 70, { range: true, min: 0, max: 90, step: 5 });
const fruits = {
apple: 'Apple',
banana: 'Banana',
cherry: 'Cherry',
};
const fruit = select('Fruit', fruits, 'apple');
const dollars = number('Dollars', 12.5);

return <Button>{content}</Button>;
// NOTE: color picker is currently broken
const backgroundColor = color('background', '#ffff00');
const items = array('Items', ['Laptop', 'Book', 'Whiskey']);
const otherStyles = object('Styles', {
border: '3px solid #ff00ff',
padding: '10px',
});
const nice = boolean('Nice', true);

// NOTE: put this last because it currently breaks everything after it :D
const birthday = date('Birthday', new Date('Jan 20 2017'));

const intro = `My name is ${name}, I'm ${age} years old, and my favorite fruit is ${fruit}.`;
const style = { backgroundColor, ...otherStyles };
const salutation = nice ? 'Nice to meet you!' : 'Leave me alone!';

return (
<div style={style}>
<p>{intro}</p>
<p>My birthday is: {new Date(birthday).toLocaleDateString()}</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>
<p>{salutation}</p>
</div>
);
})
.addWithInfo(
'with some info',
Expand Down