mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-06 07:21:16 +08:00
Knobs: allow arrays in object knob proptypes
This commit is contained in:
parent
ff23bdf1ab
commit
063ccfd713
@ -157,7 +157,7 @@ const value = color(label, defaultValue);
|
|||||||
|
|
||||||
### object
|
### object
|
||||||
|
|
||||||
Allows you to get a JSON object from the user.
|
Allows you to get a JSON object or array from the user.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { object } from '@storybook/addon-knobs';
|
import { object } from '@storybook/addon-knobs';
|
||||||
@ -174,7 +174,7 @@ const value = object(label, defaultValue);
|
|||||||
|
|
||||||
### array
|
### array
|
||||||
|
|
||||||
Allows you to get an array from the user.
|
Allows you to get an array of strings from the user.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { array } from '@storybook/addon-knobs';
|
import { array } from '@storybook/addon-knobs';
|
||||||
|
@ -88,7 +88,7 @@ ObjectType.defaultProps = {
|
|||||||
ObjectType.propTypes = {
|
ObjectType.propTypes = {
|
||||||
knob: PropTypes.shape({
|
knob: PropTypes.shape({
|
||||||
name: PropTypes.string,
|
name: PropTypes.string,
|
||||||
value: PropTypes.object,
|
value: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
||||||
}),
|
}),
|
||||||
onChange: PropTypes.func,
|
onChange: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
@ -1285,6 +1285,25 @@ exports[`Storyshots Button with knobs 1`] = `
|
|||||||
My birthday is:
|
My birthday is:
|
||||||
January 20, 2017
|
January 20, 2017
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
I have
|
||||||
|
2
|
||||||
|
children:
|
||||||
|
</p>
|
||||||
|
<ol>
|
||||||
|
<li>
|
||||||
|
Jane
|
||||||
|
,
|
||||||
|
13
|
||||||
|
years old
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
John
|
||||||
|
,
|
||||||
|
8
|
||||||
|
years old
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
<p>
|
<p>
|
||||||
My wallet contains: $
|
My wallet contains: $
|
||||||
12.50
|
12.50
|
||||||
|
@ -99,6 +99,16 @@ storiesOf('Button', module)
|
|||||||
padding: '10px',
|
padding: '10px',
|
||||||
});
|
});
|
||||||
const nice = boolean('Nice', true);
|
const nice = boolean('Nice', true);
|
||||||
|
const children = object('Children', [
|
||||||
|
{
|
||||||
|
name: 'Jane',
|
||||||
|
age: 13,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'John',
|
||||||
|
age: 8,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
// NOTE: put this last because it currently breaks everything after it :D
|
// NOTE: put this last because it currently breaks everything after it :D
|
||||||
const birthday = date('Birthday', new Date('Jan 20 2017'));
|
const birthday = date('Birthday', new Date('Jan 20 2017'));
|
||||||
@ -116,6 +126,16 @@ storiesOf('Button', module)
|
|||||||
<p>
|
<p>
|
||||||
My birthday is: {new Date(birthday).toLocaleDateString('en-US', dateOptions)}
|
My birthday is: {new Date(birthday).toLocaleDateString('en-US', dateOptions)}
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
|
I have {children.length} children:
|
||||||
|
</p>
|
||||||
|
<ol>
|
||||||
|
{children.map(child =>
|
||||||
|
<li key={child.name}>
|
||||||
|
{child.name}, {child.age} years old
|
||||||
|
</li>
|
||||||
|
)}
|
||||||
|
</ol>
|
||||||
<p>
|
<p>
|
||||||
My wallet contains: ${dollars.toFixed(2)}
|
My wallet contains: ${dollars.toFixed(2)}
|
||||||
</p>
|
</p>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user