Merge pull request #14809 from thomasaull/14788-fix-vue3-components-in-decorators

Vue3: Fix components in decorators
This commit is contained in:
Michael Shilman 2021-05-05 12:39:52 +08:00 committed by GitHub
commit 2d34ae302d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 2 deletions

View File

@ -24,7 +24,9 @@ function normalizeFunctionalComponent(options: ConcreteComponent): ComponentOpti
return typeof options === 'function' ? { render: options, name: options.name } : options;
}
function prepare(story: StoryFnVueReturnType, innerStory?: ConcreteComponent): Component | null {
function prepare(rawStory: StoryFnVueReturnType, innerStory?: ConcreteComponent): Component | null {
const story = rawStory as ComponentOptions;
if (story == null) {
return null;
}
@ -33,7 +35,7 @@ function prepare(story: StoryFnVueReturnType, innerStory?: ConcreteComponent): C
return {
// Normalize so we can always spread an object
...normalizeFunctionalComponent(story),
components: { story: innerStory },
components: { ...(story.components || {}), story: innerStory },
};
}

View File

@ -0,0 +1,33 @@
import MyButton from './Button.vue';
export default {
title: 'Example/ComponentInDecorator',
component: MyButton,
decorators: [
() => ({
components: {
MyButton,
},
template: `
<MyButton label="Button from decorator"/>
<story/>
`,
}),
],
};
const Template = (args) => ({
components: { MyButton },
setup() {
return { args };
},
template: '<my-button v-bind="args" />',
});
export const Primary = Template.bind({});
Primary.args = {
primary: true,
label: 'Button',
};