Coder Social home page Coder Social logo

Comments (6)

arunoda avatar arunoda commented on April 27, 2024

I like to learn more about this. Is that showing the same stories but with some different profiles (like CSS stuff and so on).

I also want know about what we can do when we select a profile. How the components in the story get to know about this.

from storybook.

jasford avatar jasford commented on April 27, 2024

Say I was building an app that provided a displayDensity setting for the user with options for "Comfortable", "Cozy" or "Compact (like Gmail). This is a global setting, and most/many components would render differently based on the setting. Rather than add duplicate stories in React Storybook for each displayDensity setting, it would be ideal to make that choice once, and have all stories reflect the updated value.

To give a loose proposal for how this could be implemented, in the example above I would add a configuration object to the configure() method call in config.js, like this:

// .storybook/config.js

import { configure } from '@kadira/storybook';

function loadStories() {
  require('../components/stories/button');
  // require as many stories as you need.
}

configure(loadStories, {
  contexts: [
    {label: 'Comfortable', values: {displayDensity: 'comfortable'}},
    {label: 'Cozy', values: {displayDensity: 'cozy'}},
    {label: 'Compact', values: {displayDensity: 'compact'}},
  ],
}, module);

And then in the stories themselves, you would get passed a context object that you can use however you see fit:

// components/stories/button.js

import React from 'react';
import { storiesOf, action } from '@kadira/storybook';

storiesOf('Button', module)
  .add('with text', ({context}) => (
    <button displayDensity={context.displayDensity} onClick={action('clicked')}>
      My First Button
    </button>
  ))
  .add('with no text', ({context}) => (
    <button displayDensity={context.displayDensity}></button>
  ));

Then in the UI there could be a simple drop down to choose your context, with the first one in the list always being the default.

from storybook.

isuvorov avatar isuvorov commented on April 27, 2024

dark layout +1

from storybook.

arunoda avatar arunoda commented on April 27, 2024

@isuvorov Could you submit a new issue about the Dark Layout.
I hope this is something else.

from storybook.

ndelangen avatar ndelangen commented on April 27, 2024

#1209 I'm going to take this idea and give it thought when implementing api-v2

from storybook.

mderazon avatar mderazon commented on April 27, 2024

Is this possible to achieve in any way ?
Could be good for something like theme (light dark)

from storybook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.