Skip to content

Commit

Permalink
Merge pull request #1515 from prismicio/dani/link-variant-9
Browse files Browse the repository at this point in the history
Nuxt link variant snippets
  • Loading branch information
dani-mp authored Dec 19, 2024
2 parents 30c4245 + 7afef6c commit 29688a9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
18 changes: 12 additions & 6 deletions packages/adapter-nuxt/src/hooks/snippet-read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,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`
<template v-for="link in ${dotPath(fieldPath)}" :key="link.key">
<PrismicLink :field="link">Link</PrismicLink>
<template v-for="link in ${path}" :key="link.key">
<PrismicLink :field="link"${variant("link")}>Link</PrismicLink>
</template>
`;
} else if (repeat && allowText) {
codeText = stripIndent`
<template v-for="link in ${dotPath(fieldPath)}" :key="link.key">
<PrismicLink :field="link" />
<template v-for="link in ${path}" :key="link.key">
<PrismicLink :field="link"${variant("link")} />
</template>
`;
} else {
Expand Down
18 changes: 12 additions & 6 deletions packages/adapter-nuxt2/src/hooks/snippet-read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,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`
<template v-for="link in ${dotPath(fieldPath)}" :key="link.key">
<PrismicLink :field="link">Link</PrismicLink>
<template v-for="link in ${path}" :key="link.key">
<PrismicLink :field="link"${variant("link")}>Link</PrismicLink>
</template>
`;
} else if (repeat && allowText) {
codeText = stripIndent`
<template v-for="link in ${dotPath(fieldPath)}" :key="link.key">
<PrismicLink :field="link" />
<template v-for="link in ${path}" :key="link.key">
<PrismicLink :field="link"${variant("link")} />
</template>
`;
} else {
Expand Down

0 comments on commit 29688a9

Please sign in to comment.