@prismicio/react
Version:
React components and hooks to fetch and present Prismic content
78 lines (77 loc) • 3.3 kB
TypeScript
import { ComponentProps, ComponentType, ForwardedRef, HTMLAttributeAnchorTarget, ReactNode } from "react";
import { type LinkField, type LinkResolverFunction, type PrismicDocument, type AsLinkAttrsConfig } from "@prismicio/client";
/** The default component rendered for internal and external links. */
declare const defaultComponent = "a";
/** Props provided to a component when rendered with `<PrismicLink>`. */
export 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;
}
export 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/core-concepts/link-resolver-route-resolver}
*/
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;
});
export declare const PrismicLink: <InternalComponentProps = ComponentProps<typeof defaultComponent>, ExternalComponentProps = ComponentProps<typeof defaultComponent>>(props: PrismicLinkProps<InternalComponentProps, ExternalComponentProps> & {
ref?: ForwardedRef<Element>;
}) => ReactNode;
/**
* Determines if a URL is internal or external.
*
* @param url - The URL to check if internal or external.
*
* @returns `true` if `url` is internal, `false` otherwise.
*/
export declare function isInternalURL(url: string): boolean;
export {};