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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue3: Don't assign values to all slots (rollback to v7.0.27) #23697

Merged
merged 6 commits into from
Aug 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 8 additions & 14 deletions code/renderers/vue3/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { App } from 'vue';
import { createApp, h, reactive, isVNode, isReactive } from 'vue';
import type { ArgsStoryFn, RenderContext } from '@storybook/types';
import type { Args, StoryContext } from '@storybook/csf';

import type { StoryFnVueReturnType, StoryID, VueRenderer } from './types';

export const render: ArgsStoryFn<VueRenderer> = (props, context) => {
Expand All @@ -14,7 +13,7 @@ export const render: ArgsStoryFn<VueRenderer> = (props, context) => {
);
}

return () => h(Component, props, generateSlots(context));
return () => h(Component, props, getSlots(props, context));
};

// set of setup functions that will be called when story is created
Expand All @@ -36,7 +35,6 @@ const map = new Map<
{
vueApp: ReturnType<typeof createApp>;
reactiveArgs: Args;
reactiveSlots?: Args;
}
>();

Expand Down Expand Up @@ -93,20 +91,16 @@ export function renderToCanvas(

/**
* generate slots for default story without render function template
* @param context
*/

function generateSlots(context: StoryContext<VueRenderer, Args>) {
function getSlots(props: Args, context: StoryContext<VueRenderer, Args>) {
const { argTypes } = context;
const slots = Object.entries(argTypes)
.filter(([key, value]) => argTypes[key]?.table?.category === 'slots')
.map(([key, value]) => {
const slotValue = context.args[key];
return [key, typeof slotValue === 'function' ? slotValue : () => slotValue];
});

return reactive(Object.fromEntries(slots));
const slots = Object.entries(props)
.filter(([key]) => argTypes[key]?.table?.category === 'slots')
.map(([key, value]) => [key, typeof value === 'function' ? value : () => value]);

return Object.fromEntries(slots);
}

/**
* get the args from the root element props if it is a vnode otherwise from the context
* @param element is the root element of the story
Expand Down