import React, { ComponentType, MouseEvent, ReactNode } from "react"; import type { UrlObject } from "url"; import url from "url"; type SparkleLinkProps = { href: string | UrlObject; className?: string; children: ReactNode; ariaLabel?: string; ariaCurrent?: | boolean | "time" | "false" | "true" | "page" | "step" | "location" | "date"; onClick?: (event: MouseEvent) => void; replace?: boolean; shallow?: boolean; target?: string; rel?: string; prefetch?: boolean; }; export type SparkleContextLinkType = ComponentType< SparkleLinkProps & React.RefAttributes >; export type SparkleContextType = { components: { link: SparkleContextLinkType; }; }; export const aLink: SparkleContextLinkType = React.forwardRef< HTMLAnchorElement, SparkleLinkProps >( ( { href, className, ariaCurrent, ariaLabel, onClick, children, target, rel }, ref ) => { const hrefAsString = typeof href !== "string" ? url.format(href) : href; return ( {children} ); } ); export const noHrefLink: SparkleContextLinkType = React.forwardRef< HTMLAnchorElement, SparkleLinkProps >(({ className, ariaCurrent, ariaLabel, onClick, children }, ref) => ( {children} )); export const SparkleContext = React.createContext({ components: { link: aLink, }, });