Merge pull request 'Updated link to universal component' (#124) from fix/link-update into develop

Reviewed-on: http://85.143.176.51:3000/free-land/front-end/pulls/124
This commit is contained in:
Denis Gorbunov 2022-09-08 09:14:36 +00:00
commit f5251fd04b

View File

@ -7,8 +7,7 @@ type Props = {
children: React.ReactNode; children: React.ReactNode;
disabled?: boolean; disabled?: boolean;
className?: string; className?: string;
} & NavLinkProps & } & NavLinkProps;
Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "">;
function getURL(to: string): URL { function getURL(to: string): URL {
try { try {
@ -26,12 +25,14 @@ export default function Link({
children, children,
disabled, disabled,
className, className,
style,
...props ...props
}: Props) { }: Props) {
const link = const link =
getURL(to).hostname === window.location.hostname ? ( getURL(to).hostname === window.location.hostname ? (
<NavLink <NavLink
to={getURL(to).pathname} to={getURL(to).pathname}
style={style}
className={classNames({ "pointer-events-none": disabled }, className)} className={classNames({ "pointer-events-none": disabled }, className)}
> >
{children} {children}
@ -39,6 +40,13 @@ export default function Link({
) : ( ) : (
<a <a
href={disabled ? undefined : getURL(to).origin} href={disabled ? undefined : getURL(to).origin}
style={
typeof style === "function"
? style({
isActive: true,
})
: style
}
aria-disabled={disabled} aria-disabled={disabled}
{...props} {...props}
> >