mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-15 15:24:52 +09:00
The custom component merges the behaviour of antd Typography.Link and the react-router.dom Link after the custom component prop was removed in v6 according to this guide: https://reactrouter.com/en/main/upgrading/v5#remove-link-component-prop
48 lines
893 B
TypeScript
48 lines
893 B
TypeScript
import React from "react";
|
|
import { Typography } from "antd";
|
|
import {
|
|
LinkProps,
|
|
useHref,
|
|
useLinkClickHandler,
|
|
} from "react-router-dom";
|
|
import { BaseType } from "antd/es/typography/Base";
|
|
|
|
const Link = React.forwardRef(
|
|
(
|
|
{
|
|
onClick,
|
|
replace = false,
|
|
state,
|
|
target,
|
|
to,
|
|
type,
|
|
...rest
|
|
}: LinkProps,
|
|
ref
|
|
) => {
|
|
let href = useHref(to);
|
|
let handleClick = useLinkClickHandler(to, {
|
|
replace,
|
|
state,
|
|
target,
|
|
}) as (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
|
|
|
|
return (
|
|
<Typography.Link
|
|
{...rest}
|
|
href={href}
|
|
onClick={(event) => {
|
|
onClick?.(event as React.MouseEvent<HTMLAnchorElement, MouseEvent>);
|
|
if (!event.defaultPrevented) {
|
|
handleClick(event);
|
|
}
|
|
}}
|
|
ref={ref as React.RefObject<HTMLElement> | null}
|
|
target={target}
|
|
type={type as BaseType}
|
|
/>
|
|
);
|
|
}
|
|
);
|
|
export default Link;
|