Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Option for adding specific storybook addon for only in specific scenario and/or story #12

Open
DrSensor opened this issue Jan 17, 2018 · 4 comments

Comments

@DrSensor
Copy link
Owner

DrSensor commented Jan 17, 2018

Currently, chaining addon was global by specifying it in src/stories/index.js. This way is too cluttered because index.js consists codes not only for chaining addon. To make it better, I plan to separate it into a different file in src/stories/addon-chain.js. For adding addon only for specific scenario/story we can use object-literal-lookups, so:

in src/stories/addon-chain.js

import Footer from '~/Footer.md'
import Readme from '~/README.md'

export default {
   Story1: {
      Senario1: (story, scenario) => withNotes(scenario.__notes || '')(story)
   },
   Story2: function (story) {
         let docsStory = withReadme(Readme)(story)
         return withFooter(Footer)(docsStory)
   },
   default: (story, scenario) => withDocs(scenario.__docs || '')(story)
}

and in src/stories/index.js

.
.
if (chainAddon[storyName][scenarioName] instanceof Function) {
   var addAddon = chainAddon[storyName][scenarioName]
} else if (chainAddon[storyName] instanceof Function) {
   var addAddon = chainAddon[storyName]
} else addAddon = chainAddon['default']

let storyWithAddons = addAddon(story, Component)

Stories.add(scenarioName, storyWithAddons)
@lozinska
Copy link

Hello there! May I work on this issue?

@DrSensor
Copy link
Owner Author

@lozinska sure

@lozinska
Copy link

Thank you! I will work on it today and will send my PR

@lozinska
Copy link

Hello there! Sorry, I'm new to Open Source development and still trying to figure things out. I fix the code according to the instructions but would you be able to let me know how can I test the code and if there are any special instructions? Thank you

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants