Skip to content

Commit

Permalink
Don't assign values to all slots (rollback to v7.0.27)
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperpeulen committed Aug 3, 2023
1 parent 708a084 commit 615db42
Showing 1 changed file with 8 additions and 14 deletions.
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

0 comments on commit 615db42

Please sign in to comment.