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 4025 - allow setting background via name #4081

Merged
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
2 changes: 2 additions & 0 deletions addons/backgrounds/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ storiesOf('Button', module).add('with text', () => <button>Click me</button>, {
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`.
7 changes: 5 additions & 2 deletions addons/backgrounds/src/BackgroundPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down