Skip to content

Commit

Permalink
Merge pull request #18209 from storybookjs/fix/vue-default-render-fn
Browse files Browse the repository at this point in the history
Vue: map args correctly in CSF3 implicit render function
  • Loading branch information
yannbf committed May 16, 2022
2 parents 9fc259c + 58f38f2 commit fb4f6dc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/vue/src/client/preview/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { renderToDOM } from './render';
export { render, renderToDOM } from './render';
export { decorateStory } from './decorateStory';

export const parameters = { framework: 'vue' };
4 changes: 2 additions & 2 deletions app/vue/src/client/preview/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const root = new Vue({
});

export const render: ArgsStoryFn<VueFramework> = (props, context) => {
const { id, component: Component } = context;
const { id, component: Component, argTypes } = context;
const component = Component as VueFramework['component'] & {
__docgenInfo?: { displayName: string };
props: Record<string, any>;
Expand All @@ -49,7 +49,7 @@ export const render: ArgsStoryFn<VueFramework> = (props, context) => {
}

return {
props: component.props,
props: Object.keys(argTypes),
components: { [componentName]: component },
template: `<${componentName} v-bind="$props" />`,
};
Expand Down
7 changes: 7 additions & 0 deletions examples/vue-cli/src/button/Button.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ export const ButtonWithProps: Story = (args, { argTypes }) => ({
ButtonWithProps.args = {
size: 'big',
};

export const WithDefaultRender = {
args: {
size: 'small',
label: 'Button with default render',
},
};
9 changes: 8 additions & 1 deletion examples/vue-cli/src/button/Button.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<template>
<div class="button" :class="`size-${size}`">
<!-- @slot Button content, e.g. label text -->
<slot></slot>
<slot>
{{label}}
</slot>
</div>
</template>

Expand All @@ -21,6 +23,11 @@ export default class Button extends Vue {
* @values default,small,big
*/
@Prop({ type: String, default: 'default' }) readonly size!: ButtonSize;
/**
* Label of the button
*/
@Prop({ type: String, default: '' }) readonly label!: string;
}
</script>

Expand Down

0 comments on commit fb4f6dc

Please sign in to comment.