Storybook: How to use `constructor` in `.stories.js`?

Created on 13 Sep 2018  路  7Comments  路  Source: storybookjs/storybook

Proposal

I want to use constructor in .stories.js file like riot.tag method.
Like below.

return {
  tags: [{ content: SimpleTestRaw, boundAs: 'mustBeUniquePlease' }],
  template:
    '<SimpleTest test={ "with a parameter" } value={"value is mapped to riotValue"}></SimpleTest>',
  tagConstructor: function(opts) {
    // tag constructor here
  }
}

Who to contact

@libetl

riot question / support

All 7 comments

Hello.

as a workaround what you can do is to use { compileNow } from @storybook/riot, then to mount it with your opts.

for example compileNow('<my-tag><div>etc...</div></my-tag>')

and then return {tagName: 'my-tag', opts: { }}

then you can execute one arg from opts in your <script> tag

I know that opts is really different from constructor, but I did not think about it yet.

I will try to find the good way to do that.

Thank you for the feedback

In the meantime, I have a better workaround for you @SatoshiKawabata
Why don't you use tag & mount ? These are some naive proxies to the riot framework

https://storybooks-riot.netlify.com/?selectedKind=Story%7CHow%20to%20create%20a%20story&selectedStory=built%20with%20tag&full=0&addons=1&stories=1&panelRight=0&addonPanel=storybook%2Fstories%2Fstories-panel

@libetl Thank you for your response.

I want to get this of riot tag in .stories.js. This way is also good so we've tried it already. Can you implement it in riot addon? Or can we create PR?

It will probably not be able to do that before begining of october (away from internet)
If you can wait until then, I can do that for you.
Else, go ahead and raise a PR.

added in 4.0.0-alpha.24 OR in 4.0.0-beta.1 (don't know yet)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

miljan-aleksic picture miljan-aleksic  路  3Comments

sakulstra picture sakulstra  路  3Comments

purplecones picture purplecones  路  3Comments

zvictor picture zvictor  路  3Comments

dnlsandiego picture dnlsandiego  路  3Comments