From 063ccfd71326e431c608d8b9712b8d97a76ff3b8 Mon Sep 17 00:00:00 2001
From: hypnos
Date: Mon, 21 Aug 2017 23:28:29 +0300
Subject: [PATCH 1/2] Knobs: allow arrays in object knob proptypes
---
addons/knobs/README.md | 4 ++--
addons/knobs/src/components/types/Object.js | 2 +-
.../src/__snapshots__/storyshots.test.js.snap | 19 ++++++++++++++++++
.../cra-kitchen-sink/src/stories/index.js | 20 +++++++++++++++++++
4 files changed, 42 insertions(+), 3 deletions(-)
diff --git a/addons/knobs/README.md b/addons/knobs/README.md
index 4f2a69ccceef..583411c30ce1 100644
--- a/addons/knobs/README.md
+++ b/addons/knobs/README.md
@@ -157,7 +157,7 @@ const value = color(label, defaultValue);
### object
-Allows you to get a JSON object from the user.
+Allows you to get a JSON object or array from the user.
```js
import { object } from '@storybook/addon-knobs';
@@ -174,7 +174,7 @@ const value = object(label, defaultValue);
### array
-Allows you to get an array from the user.
+Allows you to get an array of strings from the user.
```js
import { array } from '@storybook/addon-knobs';
diff --git a/addons/knobs/src/components/types/Object.js b/addons/knobs/src/components/types/Object.js
index 84084144b492..f97eac2b44b8 100644
--- a/addons/knobs/src/components/types/Object.js
+++ b/addons/knobs/src/components/types/Object.js
@@ -88,7 +88,7 @@ ObjectType.defaultProps = {
ObjectType.propTypes = {
knob: PropTypes.shape({
name: PropTypes.string,
- value: PropTypes.object,
+ value: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
}),
onChange: PropTypes.func,
};
diff --git a/examples/cra-kitchen-sink/src/__snapshots__/storyshots.test.js.snap b/examples/cra-kitchen-sink/src/__snapshots__/storyshots.test.js.snap
index 87b857bfac78..4fa131e6af7e 100644
--- a/examples/cra-kitchen-sink/src/__snapshots__/storyshots.test.js.snap
+++ b/examples/cra-kitchen-sink/src/__snapshots__/storyshots.test.js.snap
@@ -1285,6 +1285,25 @@ exports[`Storyshots Button with knobs 1`] = `
My birthday is:
January 20, 2017
+
+ I have
+ 2
+ children:
+
+
+ -
+ Jane
+ ,
+ 13
+ years old
+
+ -
+ John
+ ,
+ 8
+ years old
+
+
My wallet contains: $
12.50
diff --git a/examples/cra-kitchen-sink/src/stories/index.js b/examples/cra-kitchen-sink/src/stories/index.js
index ada77d629f7c..9c092ec229c2 100644
--- a/examples/cra-kitchen-sink/src/stories/index.js
+++ b/examples/cra-kitchen-sink/src/stories/index.js
@@ -99,6 +99,16 @@ storiesOf('Button', module)
padding: '10px',
});
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
const birthday = date('Birthday', new Date('Jan 20 2017'));
@@ -116,6 +126,16 @@ storiesOf('Button', module)
My birthday is: {new Date(birthday).toLocaleDateString('en-US', dateOptions)}
+
+ I have {children.length} children:
+
+
+ {children.map(child =>
+ -
+ {child.name}, {child.age} years old
+
+ )}
+
My wallet contains: ${dollars.toFixed(2)}
From 64c3a07567b586a9bee498d25e732c3b682c0020 Mon Sep 17 00:00:00 2001
From: hypnos
Date: Thu, 31 Aug 2017 02:00:01 +0300
Subject: [PATCH 2/2] Update yarn.lock
---
yarn.lock | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/yarn.lock b/yarn.lock
index a3103caa08fc..e7e67940eaf5 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4949,6 +4949,13 @@ glob-parent@^2.0.0:
dependencies:
is-glob "^2.0.0"
+glob-parent@^3.1.0:
+ version "3.1.0"
+ resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-3.1.0.tgz#9e6af6299d8d3bd2bd40430832bd113df906c5ae"
+ dependencies:
+ is-glob "^3.1.0"
+ path-dirname "^1.0.0"
+
glob@^4.0.2:
version "4.5.3"
resolved "https://registry.yarnpkg.com/glob/-/glob-4.5.3.tgz#c6cb73d3226c1efef04de3c56d012f03377ee15f"
@@ -6589,9 +6596,9 @@ left-pad@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.1.3.tgz#612f61c033f3a9e08e939f1caebeea41b6f3199a"
-lerna@2.1.0:
- version "2.1.0"
- resolved "https://registry.yarnpkg.com/lerna/-/lerna-2.1.0.tgz#22da4c9cb09f7733a7e87ba8f34779a509c172ea"
+lerna@2.1.2:
+ version "2.1.2"
+ resolved "https://registry.yarnpkg.com/lerna/-/lerna-2.1.2.tgz#b07eb7a4d7dd7d44a105262fef49b2229301c577"
dependencies:
async "^1.5.0"
chalk "^2.1.0"
@@ -6606,6 +6613,7 @@ lerna@2.1.0:
fs-extra "^4.0.1"
get-port "^3.2.0"
glob "^7.1.2"
+ glob-parent "^3.1.0"
globby "^6.1.0"
graceful-fs "^4.1.11"
inquirer "^3.2.2"
@@ -8105,6 +8113,10 @@ path-browserify@0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-0.0.0.tgz#a0b870729aae214005b7d5032ec2cbbb0fb4451a"
+path-dirname@^1.0.0:
+ version "1.0.2"
+ resolved "https://registry.yarnpkg.com/path-dirname/-/path-dirname-1.0.2.tgz#cc33d24d525e099a5388c0336c6e32b9160609e0"
+
path-exists@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-1.0.0.tgz#d5a8998eb71ef37a74c34eb0d9eba6e878eea081"