UNPKG

@prismicio/react

Version:

React components and hooks to fetch and present Prismic content

27 lines (26 loc) 1.25 kB
import { jsx, Fragment } from "react/jsx-runtime"; import { isFilled, asText } from "@prismicio/client"; import { DEV } from "esm-env"; import { devMsg } from "./lib/devMsg.js"; 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 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")}`, props.field); } return null; } if (!isFilled.richText(field)) { return fallback != null ? jsx(Fragment, { children: fallback }) : null; } return jsx(Fragment, { children: asText(field, { separator }) }); }; export { PrismicText }; //# sourceMappingURL=PrismicText.js.map