openpanel/packages/nextjs-router/src/legacy-common/refine-link.tsx
2024-02-05 10:23:04 +01:00

30 lines
738 B
TypeScript

import React from "react";
import Link, { LinkProps } from "next/link";
type MakeOptional<Type, Key extends keyof Type> = Omit<Type, Key> &
Partial<Pick<Type, Key>>;
type RefineLinkProps = (
| (MakeOptional<LinkProps, "href"> & {
to: LinkProps["href"];
})
| LinkProps
) & {
children: React.ReactNode;
ref?: React.Ref<HTMLAnchorElement>;
};
export const RefineLink: React.FC<RefineLinkProps> = React.forwardRef(
({ children, ...props }, ref) => (
<Link
ref={ref}
href={"to" in props ? props.to : props.href}
legacyBehavior={false}
{...props}
>
{children}
</Link>
),
);
RefineLink.displayName = "RefineLink";