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

Express meta as JS #135

Closed
benmccann opened this issue Aug 30, 2023 · 6 comments · Fixed by #134
Closed

Express meta as JS #135

benmccann opened this issue Aug 30, 2023 · 6 comments · Fixed by #134
Labels
enhancement New feature or request

Comments

@benmccann
Copy link
Contributor

This idea courtesy of @JReinhold. It might be more natural to express meta as JS within the .svelte file leaving Svelte syntax for the stories themselves.

<script context="module">
  import Button from './Button.svelte';

  // exactly like default export in plain CSF
  export const meta = {
    title: "Special Buttons",
    component: Button,
    argTypes: {...},
    parameters: {...}
  };
</script>
@benmccann benmccann added the enhancement New feature or request label Aug 30, 2023
@j3rem1e
Copy link
Contributor

j3rem1e commented Aug 30, 2023

The issue here is that "meta" should be statically analyzed to be part of the stories index. It's doable but not easy to do if it's plain JavaScript.

@benmccann
Copy link
Contributor Author

If it's in JavaScript couldn't you just use it directly rather than trying to statically analyze it?

@j3rem1e
Copy link
Contributor

j3rem1e commented Aug 30, 2023

It's not possible afaik. At least the first version of this plugin had been rejected because of that ^^

You have to extract a "stories.json" at compile time.

Storybook uses an AST from Babel to do that - cf https://github.com/storybookjs/storybook/tree/next/code/lib/csf-tools
Here, we should reimplement this logic with the AST from Svelte, or maybe reuse csf-tools, but IMO it's not part of the public api of storybook.

At least 3 properties should be exported at compile time: an id, a title, and the list of tags - https://github.com/storybookjs/addon-svelte-csf/pull/134/files#diff-268ed31ede4f019aa45638117dd2ee766a1f44800c8f9d9a8b7557cce061a9c0L144

Others properties/parameters could be read at runtime.

@j3rem1e
Copy link
Contributor

j3rem1e commented Aug 31, 2023

I have an implementation of this issue in #134

@benmccann
Copy link
Contributor Author

It's not possible afaik.

I have an implementation of this issue in #134

I'm not quite sure how to interpret these two seemingly conflicting statements 😆 It sounds like you originally thought it wasn't possible, but then figured it out, so I wanted to clarify if that's right?

@j3rem1e
Copy link
Contributor

j3rem1e commented Sep 14, 2023

Sorry, I was talking about this:

If it's in JavaScript couldn't you just use it directly rather than trying to statically analyze it?

It's not possible because it has to be parsed at compile time. It's implemented here in the PR: https://github.com/storybookjs/addon-svelte-csf/pull/134/files#diff-268ed31ede4f019aa45638117dd2ee766a1f44800c8f9d9a8b7557cce061a9c0R168

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants