Skip to content

Commit

Permalink
support rendering stories without explicit or implicit templates
Browse files Browse the repository at this point in the history
  • Loading branch information
JReinhold committed May 30, 2024
1 parent 9e91fc1 commit eef9618
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/runtime/Story.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,18 @@
injectIntoPlayFunction(renderer.storyContext, play);
}
});
$inspect(renderer.storyContext).with(console.log)
</script>

{#if isCurrentlyViewed}
{#if children}
{@render children(renderer.args, renderer.storyContext)}
{:else if template}
{@render template(renderer.args, renderer.storyContext)}
{:else if renderer.storyContext.component}
<!-- TODO: there's a risk here that this discards decorators -->
<svelte:component this={renderer.storyContext.component} {...renderer.args} />
{:else}
<p>Warning: no story rendered. improve this message</p>
{/if}
{/if}
19 changes: 15 additions & 4 deletions stories/Controls.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,32 @@
interactions: { disable: true },
},
tags: ['autodocs'],
args: {
sampleRequiredBoolean: true,
sampleRequiredString: 'I agree',
sampleRequiredNumber: 10,
sampleRequiredArray: ['I', 'like', 'Svelte', 'and', 'Storybook'],
sampleRequiredEnum: 'storybook',
sampleRequiredObject: { tool: 'storybook', rating: 10 },
},
});
</script>

<Story name="Default" />

<Story
name="Playground"
args={{
sampleRequiredBoolean: true,
sampleRequiredString: 'I agree',
sampleRequiredBoolean: false,
sampleRequiredString: 'Different',
sampleRequiredNumber: 10,
sampleRequiredArray: ['I', 'like', 'Svelte', 'and', 'Storybook'],
sampleRequiredArray: ['I', 'like', 'Storybook', 'and', 'Svelte'],
sampleRequiredEnum: 'storybook',
sampleRequiredObject: { tool: 'storybook', rating: 10 },
sampleRequiredObject: { tool: 'storybook', rating: 11 },
}}
>
{#snippet children(args)}
<Controls {...args} />
{/snippet}
</Story>

4 changes: 2 additions & 2 deletions stories/RequiredSnippet.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
<!-- <Story name="Case 1" /> -->

{#snippet children()}
<p>This works</p>
<p>This works</p>
{/snippet}

<!-- Works, as expected TODO: does not actually work, renders nothing-->
<!-- Works, as expected -->
<Story name="Case 2" args={{ children }} />

<!-- Works, as expected, but TypeScript is not happy -->
Expand Down

0 comments on commit eef9618

Please sign in to comment.