Having the generic ability to pass options alongside each story to the storiesOf and add method would open the door to some easier per-story customization in decorators or other add-ons.
I see few possible solutions:
options argumentMake options an argument to storiesOf and add. This would look like this:
storiesOf('kind', kindOptions)
.add('title', render, storyOptions);
storiesOf and add accept a single options hash argChange the api for storiesOf and add so that they accept a single options arg. Something along the lines of:
storiesOf({title: 'kind title'})
.add({
title: 'story title',
render,
myOtherOption
});
_Note: Moved the JSX syntax proposal to #1006_
Thank you @theinterned for opening this discussion
One more great variant (actually something between Options 1 and 2) was offered by @nutgaard in #705
storiesOf('Kind without metadata')
.add('no-metadata', () => (<p>No metadata here</p>))
.add('metadata', { story: () => (<p>No metadata here</p>), additionData: 'metadata' })
the big advantage of this is that we can pass data through addons like addon-info to ensure compatibility with them
Some thoughts:
describe/it terminology too.@tmeasday in answer to your third question, I guess the big advantages that a JSX approach gives are the same familiar advantages that all react development gives:
Story works by just wrapping / decorating it or requiring an alternate Story from a different package.@tmeasday as to your question "doesn't the story part need to be a function: how would that work in JSX?" Can you clarify that a bit? Aren't components functions (and sometimes classes)? or do you mean something else?
On the function part: I mean that the current interface expects to be passed a function that returns a React element (I guess equivalent to a stateless functional component). Your version above passes an element as a child to the Story component. (in the OO sense, it passes an "instance" rather than a "class").
The equivalent thing would be to pass in a prop: <Story render={() => <MyComponent ... />} />.
I'm not sure exactly why the interface is as it is, a guess is so that you get a new element each time you visit the story.
On the general question of a "react" interface, let's unpack this a little more. I suspect you can get a lot of the advantages you've stated with a basic OO class-based interface. I'm not necessarily advocating for that, but I want to use it for comparison. So something like:
new Chapter({
title: 'Chapter',
stories: [
new Story({
title: 'Story',
render() { return <My Component ... />; },
}),
});
To your points:
I'm not necessarily against it but I am trying to tease it out so bear with me. I guess I just wonder if the "rendering" interface is restrictive for little benefit. For instance, it no longer becomes easy to take an instance of a chapter and get its stories (compare the two cases: a class instance with a stories property to an Chapter element with a set of children, some of which are Story elements), or easily change the way a chapter/story is rendered.
Is there a reason why restricting the way we think about stories to "rendering" is a good thing? I'm not sure there is.
@tmeasday I agree that you could absolutely describe any interface that is currently described in JSX in pure JS: that's one of the fundamentaly great things about JSX: it transpiles to just pure JS, but is _so much nicer to look at_ then a deeply nested tree of objects and arrays.
So yes people are familiar with OO style and with, say, the functional style of most other testing packages (which I would sort of prefer to see somehow then the fluent api of storybooks as it stands now). But there's a certain expressiveness to the JSX syntax.
I think the value of composition is well expressed by @UsulPro in slack: it makes it easy to solve problems like this: https://github.com/storybooks/storybook/issues/766 because the add-on could be a component rather than a plugin.
I created a separate issue about the JSX syntax: https://github.com/storybooks/storybook/issues/1006
we can continue the discussion there.
I feel that the JSX syntax may be a distraction from the conversation about a generic way to pass props to storiesOf and add which would be a very useful feature on it's own without a major overhall to the storybook api.
I'm fully on board with this idea!
Very solid proposal for #1209 api-v2
I'm board with Option 1. Any breaking change in the API had better be motivated by enabling something we can't do with the current API, IMHO.
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. We do try to do some housekeeping every once in a while so inactive issues will get closed after 90 days. Thanks!
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 60 days. Thanks!
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 60 days. Thanks!
I am working on this actually #2679!
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 60 days. Thanks!
This is done actually, just waiting to be merged in #2679.
Released as 4.0.0-alpha.0