@prismicio/react
Version:
React components and hooks to fetch and present Prismic content
31 lines (30 loc) • 1.54 kB
JavaScript
import { devMsg } from "./lib/devMsg.js";
import { asText, isFilled } from "@prismicio/client";
import { DEV } from "esm-env";
import { Fragment, jsx } from "react/jsx-runtime";
//#region src/PrismicText.tsx
/**
* Renders content from a Prismic rich text field as plain text (no HTML).
*
* @example
* ```tsx
* <PrismicText field={slice.primary.text} />;
* ```
*
* @see Learn how to display rich text as plain text or React components: {@link https://prismic.io/docs/fields/rich-text}
*/
const PrismicText = (props) => {
const { field, fallback, separator } = props;
if (DEV) {
if ("className" in props) console.warn(`[PrismicText] className cannot be passed to <PrismicText> since it renders plain text without a wrapping component. For more details, see ${devMsg("classname-is-not-a-valid-prop")}.`, props.field);
}
if (typeof props.field === "string") {
if (DEV) console.error(`[PrismicText] The "field" prop only accepts a rich text 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")}`, props.field);
return null;
}
if (!isFilled.richText(field)) return fallback != null ? /* @__PURE__ */ jsx(Fragment, { children: fallback }) : null;
return /* @__PURE__ */ jsx(Fragment, { children: asText(field, { separator }) });
};
//#endregion
export { PrismicText };
//# sourceMappingURL=PrismicText.js.map