Skip to content

Commit

Permalink
Add link variant snippets for nuxt
Browse files Browse the repository at this point in the history
  • Loading branch information
dani-mp committed Dec 18, 2024
1 parent ce28dca commit 7afef6c
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 7afef6c

Please sign in to comment.