Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,92 @@
|
||||
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<HTMLButtonElement | HTMLAnchorElement>) => void;
|
||||
reloadDocument?: boolean;
|
||||
autoFocus?: boolean;
|
||||
prefetch?: "intent" | "render" | "none";
|
||||
disabled?: boolean;
|
||||
isLoading?: boolean;
|
||||
onMouseEnter?: (e: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement | HTMLDivElement>) => void;
|
||||
onMouseLeave?: (e: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement | HTMLDivElement>) => 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<HTMLButtonElement | HTMLAnchorElement | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!autoFocus) {
|
||||
return;
|
||||
}
|
||||
const timeout = window.setTimeout(() => focusRef.current?.focus(), 0);
|
||||
return () => window.clearTimeout(timeout);
|
||||
}, [autoFocus]);
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
{(!to && !onClick) || (to && disabled) ? (
|
||||
<div className={className} role={role} aria-label={ariaLabel} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
|
||||
{children}
|
||||
</div>
|
||||
) : to == undefined ? (
|
||||
<Button
|
||||
ref={focusRef as Ref<HTMLButtonElement>}
|
||||
type={type}
|
||||
onClick={onClick}
|
||||
className={clsx(className, isLoading && "base-spinner cursor-not-allowed")}
|
||||
role={role}
|
||||
aria-label={ariaLabel}
|
||||
disabled={disabled}
|
||||
onMouseEnter={onMouseEnter}
|
||||
onMouseLeave={onMouseLeave}
|
||||
>
|
||||
{children}
|
||||
</Button>
|
||||
) : (
|
||||
<Link
|
||||
reloadDocument={reloadDocument}
|
||||
onClick={onClick}
|
||||
to={to}
|
||||
target={target}
|
||||
className={className}
|
||||
role={role}
|
||||
aria-label={ariaLabel}
|
||||
ref={focusRef as Ref<HTMLAnchorElement>}
|
||||
prefetch={prefetch}
|
||||
rel={rel}
|
||||
onMouseEnter={onMouseEnter}
|
||||
onMouseLeave={onMouseLeave}
|
||||
>
|
||||
{children}
|
||||
</Link>
|
||||
)}
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user