generated from storybookjs/addon-kit
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example for failing TypeScript case with required snippets
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<script context="module" lang="ts"> | ||
import { defineMeta } from '@storybook/addon-svelte-csf'; | ||
import RequiredSnippet from './RequiredSnippet.svelte'; | ||
const { Story } = defineMeta({ | ||
component: RequiredSnippet, | ||
tags: ['autodocs'], | ||
}); | ||
</script> | ||
|
||
|
||
<!-- Not working, as expected --> | ||
<!-- <Story name="Case 1" /> --> | ||
|
||
{#snippet children()} | ||
<p>This works</p> | ||
{/snippet} | ||
|
||
<!-- Works, as expected --> | ||
<Story name="Case 2" args={{ children }} /> | ||
|
||
<!-- Works, as expected, but TypeScript is not happy --> | ||
<Story name="Case 3"> | ||
<!-- Current workaround: add `args: { children: "" }` to `defineMeta`, but this is invalid, Svelte snippets cannot be literal, they're functions --> | ||
{#snippet children()} | ||
<p>This works</p> | ||
{/snippet} | ||
</Story> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script lang="ts"> | ||
import type { Snippet } from "svelte"; | ||
interface Props { | ||
children: Snippet; | ||
} | ||
let { children }: Props = $props(); | ||
</script> | ||
|
||
<div> | ||
{@render children()} | ||
</div> |