UNPKG

@prismicio/react

Version:

React components and hooks to fetch and present Prismic content

94 lines (93 loc) 3.13 kB
import { LinkProps } from "./PrismicLink.js"; import { LinkResolverFunction, RichTextField } from "@prismicio/client"; import { ComponentType, FC, ReactNode } from "react"; import { RichTextFunctionSerializer, RichTextMapSerializer } from "@prismicio/client/richtext"; //#region src/PrismicRichText.d.ts /** * A function mapping rich text block types to React Components. It is used to render rich text * fields. * * @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text} */ type JSXFunctionSerializer = RichTextFunctionSerializer<ReactNode>; /** * A map of rich text block types to React Components. It is used to render rich text fields. * * @see Templating rich text fields {@link https://prismic.io/docs/fields/rich-text} */ type RichTextComponents = RichTextMapSerializer<ReactNode>; /** @deprecated Use `RichTextComponents` instead. */ type JSXMapSerializer = RichTextComponents; /** Props for `<PrismicRichText>`. */ type PrismicRichTextProps = { /** The Prismic rich text field to render. */field: RichTextField | null | undefined; /** * The link resolver used to resolve links. * * @remarks * If your app uses route resolvers when querying for your Prismic repository's content, a link * resolver does not need to be provided. * @see Learn about link resolvers and route resolvers {@link https://prismic.io/docs/routes} */ linkResolver?: LinkResolverFunction; /** * A map or function that maps a rich text block to a React component. * * @remarks * Prefer using a map serializer over the function serializer when possible. The map serializer * is simpler to maintain. * @example * A map serializer. * * ```jsx * { * heading1: ({children}) => <Heading>{children}</Heading> * } * ``` * * @example * A function serializer. * * ```jsx * (type, node, content, children) => { * switch (type) { * case "heading1": { * return <Heading>{children}</Heading>; * } * } * }; * ``` */ components?: RichTextComponents | JSXFunctionSerializer; /** * The React component rendered for links when the URL is internal. * * @defaultValue `<a>` */ internalLinkComponent?: ComponentType<LinkProps>; /** * The React component rendered for links when the URL is external. * * @defaultValue `<a>` */ externalLinkComponent?: ComponentType<LinkProps>; /** * The value to be rendered when the field is empty. If a fallback is not given, `null` will be * rendered. */ fallback?: ReactNode; }; /** * Renders content from a Prismic rich text field as React components. * * @example * ```tsx * <PrismicRichText field={slice.primary.text} />; * ``` * * @see Learn how to style rich text, use custom components, and use labels for custom formatting: {@link https://prismic.io/docs/fields/rich-text} */ declare const PrismicRichText: FC<PrismicRichTextProps>; //#endregion export { JSXFunctionSerializer, JSXMapSerializer, PrismicRichText, PrismicRichTextProps, RichTextComponents }; //# sourceMappingURL=PrismicRichText.d.ts.map