Skip to content

Commit

Permalink
Add link variant snippets for svelte
Browse files Browse the repository at this point in the history
  • Loading branch information
dani-mp committed Dec 18, 2024
1 parent 7afef6c commit b0e32d8
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/adapter-sveltekit/src/hooks/snippet-read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,31 @@ export const snippetRead: SnippetReadHook<PluginOptions> = 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`
<PrismicLink field={${dotPath(fieldPath)}}>Link</PrismicLink>
<PrismicLink field={${path}}${variant(path)}>Link</PrismicLink>
`;
} else if (!repeat && allowText) {
codeText = stripIndent`
<PrismicLink field={${dotPath(fieldPath)}} />
<PrismicLink field={${path}}${variant(path)} />
`;
} else if (repeat && !allowText) {
codeText = stripIndent`
{#each ${dotPath(fieldPath)} as link (link.key)}
<PrismicLink field={link}>Link</PrismicLink>
{#each ${path} as link (link.key)}
<PrismicLink field={link}${variant("link")}>Link</PrismicLink>
{/each}
`;
} else if (repeat && allowText) {
codeText = stripIndent`
{#each ${dotPath(fieldPath)} as link (link.key)}
<PrismicLink field={link} />
{#each ${path} as link (link.key)}
<PrismicLink field={link}${variant("link")} />
{/each}
`;
} else {
Expand Down

0 comments on commit b0e32d8

Please sign in to comment.