From b0e32d8f84ed72026cc8aaf7c94141c407a1c666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marti=CC=81n?= Date: Wed, 18 Dec 2024 20:30:08 +0100 Subject: [PATCH] Add link variant snippets for svelte --- .../src/hooks/snippet-read.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/adapter-sveltekit/src/hooks/snippet-read.ts b/packages/adapter-sveltekit/src/hooks/snippet-read.ts index 0de45f568..c2760f4e3 100644 --- a/packages/adapter-sveltekit/src/hooks/snippet-read.ts +++ b/packages/adapter-sveltekit/src/hooks/snippet-read.ts @@ -60,25 +60,31 @@ export const snippetRead: SnippetReadHook = async ( const repeat = data.model.config?.repeat ?? false; const allowText = data.model.config?.allowText ?? false; + const allowVariants = Boolean(data.model.config?.variants); + const variant = (path: string) => + allowVariants ? ` class={${path}.variant}` : ""; + + const path = dotPath(fieldPath); + let codeText; if (!repeat && !allowText) { codeText = stripIndent` - Link + Link `; } else if (!repeat && allowText) { codeText = stripIndent` - + `; } else if (repeat && !allowText) { codeText = stripIndent` - {#each ${dotPath(fieldPath)} as link (link.key)} - Link + {#each ${path} as link (link.key)} + Link {/each} `; } else if (repeat && allowText) { codeText = stripIndent` - {#each ${dotPath(fieldPath)} as link (link.key)} - + {#each ${path} as link (link.key)} + {/each} `; } else {