import { Link } from "react-router"; import clsx from "clsx"; import { Fragment, ReactNode, Ref, useEffect, useRef } from "react"; import { Button } from "../button"; interface Props { type?: "button" | "submit"; to: string | undefined; children: ReactNode; className?: string; target?: undefined | "_blank" | string; role?: string; ariaLabel?: string; rel?: string; onClick?: (e: React.MouseEvent) => void; reloadDocument?: boolean; autoFocus?: boolean; prefetch?: "intent" | "render" | "none"; disabled?: boolean; isLoading?: boolean; onMouseEnter?: (e: React.MouseEvent) => void; onMouseLeave?: (e: React.MouseEvent) => void; } export default function LinkOrAhref({ type = "button", to, target, children, className, role, ariaLabel, rel, onClick, reloadDocument, autoFocus, prefetch, disabled, isLoading, onMouseEnter, onMouseLeave, }: Props) { const focusRef = useRef(null); useEffect(() => { if (!autoFocus) { return; } const timeout = window.setTimeout(() => focusRef.current?.focus(), 0); return () => window.clearTimeout(timeout); }, [autoFocus]); return ( {(!to && !onClick) || (to && disabled) ? (
{children}
) : to == undefined ? ( ) : ( } prefetch={prefetch} rel={rel} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} > {children} )}
); }