Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to dynamically generate stories / args #1

Open
tobiasdiez opened this issue Sep 29, 2022 · 3 comments
Open

allow to dynamically generate stories / args #1

tobiasdiez opened this issue Sep 29, 2022 · 3 comments
Labels
type: enhancement Improving upon an existing feature

Comments

@tobiasdiez
Copy link
Owner

tobiasdiez commented Sep 29, 2022

Example of how this may look:

<template>
  <Stories>
    <Story
      v-for="(argument, key) of arguments"
      :title="'Story ' + key"
    >
      <MyComponent :argument="argument" />
    </Story>
  </Stories>
</template>
<script lang="ts" setup>
import MyComponent from './MyComponent.vue'

const arguments = ["hello", "world"]
</script>

This is currently blocked by storybookjs/storybook#9828.

Once this is implemented, add https://storybook.js.org/docs/vue/writing-stories/introduction#using-args as example.

@tobiasdiez tobiasdiez added the type: enhancement Improving upon an existing feature label Sep 29, 2022
@tobiasdiez tobiasdiez changed the title allow to dynamically generate stories allow to dynamically generate stories / args Nov 8, 2022
@floroz
Copy link
Contributor

floroz commented Sep 11, 2023

In Storybook V7 to dynamically generate CSF they have introduced the Indexer API, which is what storybook-vue-addon uses under the hood.

So, we could theoretically already support this feature just by enhancing the parsing of the *.stories.vue file to detect the usage of iterators over the <Story /> token, and transform them into a dynamic CSF as we do for static stories' declarations.

Not saying necessarily is something we can do anytime soon, just want to understand if there are any other constraints I am not aware of?

@tobiasdiez
Copy link
Owner Author

Yes, the new indexer api is nice - at least in principle. One still has to implement the transpiling to csf: https://github.com/storybookjs/storybook/blob/next/docs/api/main-config-indexers.md#transpiling-to-csf
And I'm not sure how to hook into vue's compiling to extract the for-loop. The obvious way via node transformers doesn't seem to work as vue's for-loop transformer is always executed first, by design: vuejs/core#4248.
So maybe we have to first replace the v-for by a different directive, say storybook-for and then reimplement the v-for transformer in our setting.

@floroz
Copy link
Contributor

floroz commented Oct 14, 2023

Yes, the new indexer api is nice - at least in principle. One still has to implement the transpiling to csf: https://github.com/storybookjs/storybook/blob/next/docs/api/main-config-indexers.md#transpiling-to-csf And I'm not sure how to hook into vue's compiling to extract the for-loop. The obvious way via node transformers doesn't seem to work as vue's for-loop transformer is always executed first, by design: vuejs/core#4248. So maybe we have to first replace the v-for by a different directive, say storybook-for and then reimplement the v-for transformer in our setting.

That's a very handy link for the API docs, thank you @tobiasdiez.

I guess my point is whether this type of feature would really be in the scope of this addon.

If you are dynamically generating stories, the developer's experience of writing Vue SFC might not be the first thing you need.

Obviously, if this can be supported without much effort, would be great, but it seems a non-trivial use case for which Storybook already provides a valid alternative.

The risk I see is to manage (and maintain) yet another level of pre-processing of the SFC file which might conflict with the future transform we will put in place to support the most advanced features.

I suppose this is something we can revisit at some point in the future.

tobiasdiez added a commit that referenced this issue Aug 4, 2024
* chore: init

* chore: remove enforce

* chore: npm run

* fix: nuxt options

* chore: update deps

* chore: fix tsup commands (#1)

* fix: path, close #2

* build: use tsup.config.ts

* chore: update dependencies (#5)

* chore: update deps

* fix: `pnpm run dev` error (#7)

* fix: pnpm run dev error

* style: lint fix

* fix: fix dev error (#9)

* chore: update deps

* chore: update

* fix: cjs exports (#10) (#11)

* feat: add esbuild export (#12)

* ci: update release script

* chore: update deps

* feat: add esbuild export (#14)

* feat: add esbuild export (#13)

* chore: lint

* chore: add deps of 'chalk' (#15)

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>

* chore: update deps

* fix: 'UserOptions' set to optional (#18)

* feat: use type=module (#16) (#17)

* fix: pnpm workspace config (#19)

* chore: update deps

* fix: nuxt module hooks (#20)

* chore: update deps

* chore: update deps

* chore: update ci matrix

* chore: update deps

* chore: lint

* feat: update builds

* ci: add permission

* docs: update (#21)

* docs: update playground link (#22)

* feat: template update (#25)

* fix: require(...) is not a function (#28)

* update

* fix linter

* fix astro

* fix tests

* use jiti over esno

* update all eslint

* dedupe

* update node used for linter

* fix prettier

---------

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
Co-authored-by: TropicalRaisel <87331818+TropicalRaisel@users.noreply.github.com>
Co-authored-by: dengqing <dengqing0821@gmail.com>
Co-authored-by: Tedy <1197633750@qq.com>
Co-authored-by: snowingfox <1503401882@qq.com>
Co-authored-by: Rongger <934004841@qq.com>
Co-authored-by: 三咲智子 <sxzz@sxzz.moe>
Co-authored-by: Alex Liu <larch.liu@gmail.com>
Co-authored-by: ntnyq <ntnyq13@gmail.com>
Co-authored-by: Robert Soriano <sorianorobertc@gmail.com>
Co-authored-by: Ray <i@mk1.io>
Co-authored-by: yuyin <38490578+yuyinws@users.noreply.github.com>
Co-authored-by: lrs <104537923+RuSenLi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Improving upon an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants