-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
167 additions
and
202 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,66 @@ | ||
<script lang="ts" setup> | ||
import type { RichTextField } from "@prismicio/client" | ||
import { asText, isFilled } from "@prismicio/client" | ||
import { watchEffect } from "vue" | ||
import { devMsg } from "../lib/devMsg" | ||
import type { ComponentOrTagName } from "../types" | ||
/** | ||
* Props for `<PrismicText />`. | ||
*/ | ||
export type PrismicTextProps = { | ||
/** | ||
* The Prismic Rich Text field to render. | ||
*/ | ||
field: RichTextField | null | undefined | ||
/** | ||
* The string value to be rendered when the field is empty. If a fallback is | ||
* not given, `""` (nothing) will be rendered. | ||
*/ | ||
fallback?: string | ||
/** | ||
* The separator used between blocks. | ||
* | ||
* @defaultValue `" "` (a whitespace) | ||
*/ | ||
separator?: string | ||
/** | ||
* An HTML tag name, a component, or a functional component used to wrap the | ||
* output. | ||
* | ||
* @defaultValue `"template"` (no wrapper) | ||
*/ | ||
wrapper?: ComponentOrTagName | ||
} | ||
const props = defineProps<PrismicTextProps>() | ||
defineOptions({ name: "PrismicText" }) | ||
if (typeof process !== "undefined" && process.env.NODE_ENV === "development") { | ||
watchEffect(() => { | ||
if (typeof props.field === "string") { | ||
throw new Error( | ||
`[PrismicText] The "field" prop only accepts a Rich Text or Title field's value but was provided a different type of field instead (e.g. a Key Text or Select field). You can resolve this error by rendering the field value inline without <PrismicText>. For more details, see ${devMsg( | ||
"prismictext-works-only-with-rich-text-and-title-fields", | ||
)}`, | ||
) | ||
} | ||
}, {}) | ||
} | ||
</script> | ||
|
||
<template> | ||
<template v-if="isFilled.richText(field) || fallback"> | ||
<Component v-if="wrapper" :is="wrapper"> | ||
{{ asText(field) || fallback }} | ||
</Component> | ||
<template v-else> | ||
{{ asText(field) || fallback }} | ||
</template> | ||
</template> | ||
</template> |
Oops, something went wrong.