From cbd77410af83311ef13c16d893cea1898a995d21 Mon Sep 17 00:00:00 2001 From: Philipp Zins Date: Mon, 27 Aug 2018 10:59:22 +0200 Subject: [PATCH] fixed 4025 - allow setting background via name --- addons/backgrounds/README.md | 2 ++ addons/backgrounds/src/BackgroundPanel.js | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/addons/backgrounds/README.md b/addons/backgrounds/README.md index 93dbda859c2a..fe7f2dcf46e4 100644 --- a/addons/backgrounds/README.md +++ b/addons/backgrounds/README.md @@ -81,3 +81,5 @@ storiesOf('Button', module).add('with text', () => , { backgrounds: { disable: true }, }); ``` + +You can choose your background in a running storybook instance with the `background` query param and either set the background value or the name as the parameter value. E.g. `?background=twitter` or `?background=#00aced`. diff --git a/addons/backgrounds/src/BackgroundPanel.js b/addons/backgrounds/src/BackgroundPanel.js index ea1e9bcd53a7..cf56703b5e25 100644 --- a/addons/backgrounds/src/BackgroundPanel.js +++ b/addons/backgrounds/src/BackgroundPanel.js @@ -99,8 +99,11 @@ export default class BackgroundPanel extends Component { // debugger; - if (current && backgrounds.find(bg => bg.value === current)) { - this.updateIframe(current); + const foundBackground = + current && backgrounds.find(bg => bg.name === decodeURI(current) || bg.value === current); + + if (foundBackground) { + this.updateIframe(foundBackground.value); } else if (defaultOrFirst) { this.updateIframe(defaultOrFirst.value); api.setQueryParams({ background: defaultOrFirst.value });