UNPKG

@prismicio/react

Version:

React components and hooks to fetch and present Prismic content

81 lines (80 loc) 3.28 kB
import { AsLinkAttrsConfig, LinkField, LinkResolverFunction, PrismicDocument } from "@prismicio/client"; import { ComponentProps, ComponentType, ForwardedRef, HTMLAttributeAnchorTarget, ReactNode } from "react"; //#region src/PrismicLink.d.ts /** The default component rendered for internal and external links. */ declare const defaultComponent = "a"; /** Props provided to a component when rendered with `<PrismicLink>`. */ interface LinkProps { /** The URL to link. */ href: string; /** * The `target` attribute for anchor elements. If the Prismic field is configured to open in a new * window, this prop defaults to `_blank`. */ target?: HTMLAttributeAnchorTarget; /** * The `rel` attribute for anchor elements. If the `target` prop is set to `"_blank"`, this prop * defaults to `"noopener noreferrer"`. */ rel?: string; /** Children for the component. */ children?: ReactNode; } type PrismicLinkProps<InternalComponentProps = ComponentProps<typeof defaultComponent>, ExternalComponentProps = ComponentProps<typeof defaultComponent>> = Omit<InternalComponentProps & ExternalComponentProps, "rel" | "href" | "children"> & { /** * The `rel` attribute for the link. By default, `"noreferrer"` is provided if the link's URL is * external. This prop can be provided a function to use the link's metadata to determine the * `rel` value. */ rel?: string | AsLinkAttrsConfig["rel"]; /** * 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; /** * The component rendered for internal URLs. Defaults to `<a>`. * * If your app uses a client-side router that requires a special Link component, provide the Link * component to this prop. */ internalComponent?: ComponentType<InternalComponentProps>; /** The component rendered for external URLs. Defaults to `<a>`. */ externalComponent?: ComponentType<ExternalComponentProps>; /** * The children to render for the link. If no children are provided, the link's `text` property * will be used. */ children?: ReactNode; } & ({ document: PrismicDocument | null | undefined; href?: never; field?: never; } | { field: LinkField | null | undefined; href?: never; document?: never; } | { href: LinkProps["href"]; field?: LinkField | null | undefined; document?: never; }); /** * Renders a link from a Prismic link field or page. * * @example * ```tsx * <PrismicLink field={slice.primary.link}>Click here</PrismicLink>; * ``` * * @see Learn how to display links and use variants for styling: {@link https://prismic.io/docs/fields/link} */ declare const PrismicLink: <InternalComponentProps = ComponentProps<typeof defaultComponent>, ExternalComponentProps = ComponentProps<typeof defaultComponent>>(props: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & { ref?: ForwardedRef<Element>; }) => ReactNode; //#endregion export { LinkProps, PrismicLink, PrismicLinkProps }; //# sourceMappingURL=PrismicLink.d.ts.map