-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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
[Bug]: vue3 story sourcecode does not reflect the preview #21129
Comments
At the moment, the only way to properly display the source code is to store the template in a const, and reapply this const to the parameters.docs...
|
HI @KevinCarnaille2 can you share your |
Sure @chakAs3 ! Here it is ! The types imported are generated union string, based on arrays.
|
Hi @KevinCarnaille2 your repo was not really a reproduction one, cause it is missing project configuration can't see either vite or storybook configuration. i copied the stories folder from your repo and tested it was giving me this which is perfect as the variant prop no need to pass as it is the default value = primary |
here is a fork of your repo with my change to be able to test yourself |
Hello @chakAs3 I have updated the repository with a full vue3/ts/vite/storybook setup. Hope this is enough :) |
I've encountered a similar problem with non-component HTML added to the story. Here is a use case for a design system: Here is the source of the story: const render = args => ({
template: `
<div :role="variant === 'danger' ? 'alert' : 'status'">
<ds-notification v-if="isVisible" v-bind="{ variant, prominent, header, content, hideCloseButton }" />
</div>
`,
components: { DsNotification },
props: {
isVisible: { type: Boolean, required: true }, // controlled by a decorator, no problem there
},
setup: () => args,
}); The generated source ends up being with the role stripped from the div: <template>
<div>
<ds-notification
variant="danger"
header="Title of the notification"
content="Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
v-on:close="() => {}"
/>
</div>
</template> I'd expect the role to be presented as well: <template>
<div role="alert">
<ds-notification
variant="danger"
header="Title of the notification"
content="Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
v-on:close="() => {}"
/>
</div>
</template> |
Hi yes I’m opening a pr to fix this. With extra tests : |
Are you talking about this specific PR ? |
yes @KevinCarnaille2 |
Do we have any news about this ? |
Hi @KevinCarnaille2 We are going soon to merge the PR that fixes that, or maybe i can split the large PR to accommodate only the source code feature. |
Hi. @KevinCarnaille2 can you pull this repo and test the source snippet and let me know if this is fine https://github.com/storybookjs/vue3-vuetify-examples |
Thans for this !
|
Hello! Storybook version: 7.0.4 It's better ! But I still struggle with named slots. Here is my story code, I've followed what you've done and I used the h renderer function :
The rendering is fine, but the generated code snippet looks like so :
And I have this warning :
I don't really get what's going on because when I try with your repository, I don't have the issue. |
hi @KevinCarnaille2 i see what are doing, seems ok, i know why the component code is rendered as VNode i have to check back with your test, for here i can see it not big deal i will get back to you . and this fixed in the patch i put on the repo i shared with you. you can contribute there with you case an open a PR, it will be helpful 😃 |
I've also experienced some issues with template rendering but the case is slightly different. import OhIconTeaser, { Props } from "./OhIconTeaser.vue";
import type { Meta, StoryObj, VueRenderer } from "@storybook/vue3";
import { OhIconAlertCircle } from "../../icons";
import { reactive } from 'vue'
import * as icons from '../../icons'
const meta: Meta<Props & {icon: string}> = {
// ...
render: args => ({
components: { OhIconTeaser },
setup() {
const iconsArr = reactive<Record<string, any>>(icons)
return { args, iconsArr };
},
template: `
<OhIconTeaser v-bind="args">
<template #icon>
<component :is="(iconsArr[args.icon])" />
</template>
</OhIconTeaser>
`,
}),
argTypes: {
// ...
icon: {
options: Object.keys(icons),
control: {
type: "select",
}
},
},
args: {
// ...
icon: "OhIconAlertCircle",
},
};
export default meta;
type Story = StoryObj<typeof meta>;
export const Default: Story = {
args: {},
}; Originally the component looks like this: <template>
<a :href="link ?? '#'" :target="target">
<div class="oh-icon-teaser">
<slot name="icon" />
<h2 class="oh-icon-teaser__title">{{ title }}</h2>
<p class="oh-icon-teaser__content">{{ content }}</p>
</div>
</a>
</template> Rendered sourcecode looks like this: <template>
<OhIconTeaser
title="Sit back and relax"
content="Let companies do the applying. You stay in control and decide which opportunities to pursue further."
link="#"
>
"OhIconAlertCircle"
</OhIconTeaser>
</template> and should like this instead: <template>
<OhIconTeaser
title="Sit back and relax"
content="Let companies do the applying. You stay in control and decide which opportunities to pursue further."
link="#"
>
<OhIconAlertCircle />
</OhIconTeaser>
</template> Unnamed slots are even worse: Component: <template>
<a class="oh-btn-icon" :class="[sizeClasses]">
<slot />
<!-- <slot name="default"/> makes the same -->
</a>
</template> Story: render: args => ({
components: { OhButtonIcon },
setup() {
const icons = reactive<Record<keyof typeof iconsModule, any>>(iconsModule)
return { args, icons };
},
template: `
<OhButtonIcon v-bind="{size: args.size}">
<template #default>
<component :is="(icons[args.icon])" />
</template>
</OhButtonIcon>
`,
}), Preview: <template>
<OhButtonIcon size="md" icon="OhIconAlertCircle" />
</template> |
@chakAs3 I see the issue is closed. Which SB version includes the fix :) ? |
hi @KevinCarnaille2 how are doing. long time 😄. it is already on latest version |
Hello hello :D |
yes |
Describe the bug
In vue3 + Storybook 7.0.0-beta.48 context (edit : same issue with beta 51)
When we declare a story with static properties, and without any args, the sourcecode is not rendering correctly (preview is fine though) :
Simple example with a Button component, having multiple variants that I need to display in one story :
Generated sourcecode :
I have a different behavior when I declare the slot like so :
Generated sourcecode :
This time the variant property is correctly displayed, but still not for the slot.
To Reproduce
https://github.com/KevinCarnaille2/sb-vue3-sourcecode-issue
No response
System
Additional context
No response
The text was updated successfully, but these errors were encountered: