question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Backgrounds addon] Set a different default background for a specific story

See original GitHub issue

Is your feature request related to a problem? Please describe. I have a component prop that controls whether the component is visible on a dark background or a light background. In the dark-background story, I’d like to default to the dark background by name, rather than overriding all the backgrounds for that component.

Describe the solution you’d like Something like:

storiesOf("Logo", module)
  .add("horizontal", () => <Logo layout="horizontal" />)
  .add("vertical", () => <Logo layout="vertical" />)
  .add("horizontal - inverted", () => <Logo layout="horizontal" inverted/>, {defaultBackground: "primary"})
  .add("vertical - inverted", () => <Logo layout="vertical" inverted/>, {defaultBackground: "primary"});

Describe alternatives you’ve considered I saw on the documentation page that you can override the background for a component, but I don’t see a way to leave the other options and just change which one is the default. It may be possible, but I don’t see how in the documentation.

Are you able to assist bring the feature to reality? Maybe; I’m not sure if I can.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:14 (11 by maintainers)

github_iconTop GitHub Comments

3reactions
shilmancommented, Dec 23, 2019

Turns out that #9219 doesn’t really apply. Here’s what I’m thinking for a better backgrounds API. We can deprecate the old API in 6.0 and remove it in 7.0:

// preview.js
addParameters({
  backgrounds: {
    default: 'white',
    values: [
      { name: 'white', value: '#ffffff' }, 
      { name: 'black', value: '#000000' },
    ]
  }
}

// Foo.stories.js
export const Foo = ...
Foo.story = {
  parameters: {
    backgrounds: { default: 'black' },
  }
}
2reactions
iansan5653commented, Dec 19, 2019

The defaultBackground method looks perfect! It’s exactly what I was thinking of.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Backgrounds - Storybook - JS.ORG
The backgrounds toolbar addon allows you to set the background color in which the story renders in the UI: Configuration. By default, the...
Read more >
Storybook: background change on prop change
With a few lines of code, storybook can automatically change the background color whenever certain props on your component change.
Read more >
@storybook/addon-backgrounds - npm
Storybook Addon Backgrounds. Storybook Addon Backgrounds can be used to change background colors inside the preview in Storybook.
Read more >
problems with storybook with Background parameters
I'm on a project with a storybook and I want my story to be able to change the background or ...
Read more >
How to Change Background Color in Instagram Story?
3. How to change the background color without covering the photo ... If you don't want to cover the photo, then you need...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found