-
Notifications
You must be signed in to change notification settings - Fork 32
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
Export typed Story and Template components #155
Conversation
@JReinhold what do you think of this PR ? I have doubts about the syntax/name of the export.. |
Hmm, I see what you're trying to do. Is there a type-only way to achieve this, without the helper function? That would be closer to regular CSF. <script context="module">
import type { Meta, StoryObj } from '@storybook/svelte';
import * as SvelteCsf from "@storybook/addon-svelte-csf";
import Button from "./Button.svelte";
export const meta = {
component: Button,
} satisfies Meta<Button>;
const { Template, Story } = SvelteCsf as {
Template: SvelteCsf.Template<typeof meta>;
Story: SvelteCsf.Story<typeof meta>
}
</script>
<Template let:args>
<!- args is typed here -->
<Button {...args}/>
</Template>
<!-- args is type checked here -->
<Story args={{rounded: false}}/> For reference, here's the regular CSF version that works today:import type { Meta, StoryObj } from '@storybook/svelte';
import { Button } from './Button';
const meta = {
component: Button,
} satisfies Meta<Button>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Basic: Story = {}; I also see your helper function makes it less verbose though, which is nice.
<script context="module">
import { typed } from "@storybook/addon-svelte-csf";
import Button from "./Button.svelte";
export const meta = {
component: Button,
argTypes: {...}
}
const { Template, Story } = typed(meta);
</script>
<Template let:args>
<!- args is typed here -->
<Button {...args}/>
</Template>
<!-- args is type checked here -->
<Story args={{rounded: false}}/> |
I implemented your advice: it's spelled "typed" now, and accepts a meta export as the argument (as well as a Component). with:
it works with a meta without argTypes, or a component though. |
I don't want this PR to go stale, so I'd like to bump. For the backwards compatibility of this addon (for svelte Discussion on Discord for reference: https://discord.com/channels/486522875931656193/1237378119678300190/1239432547184676945 |
I still think this is a blocker here.
Personally I like the second option best because it's more direct, but no string opinion. |
This is superseded by the new |
Should implements #152
I`m not sure about the syntax however, but it works in vscode (invalid args or use of args are flagged as errors)