import type { LinkProps as ChakraLinkProps } from '@chakra-ui/react';
import { Link as ChakraLink, LinkBox as ChakraLinkBox, LinkOverlay as ChakraLinkOverlay, Icon } from '@chakra-ui/react';
import NextLink from 'next/link';
import type { LinkProps as NextLinkProps } from 'next/link';
import React from 'react';
import ArrowIcon from 'icons/link_external.svg';
import stripUtmParams from 'lib/utils/stripUtmParams';
import { Skeleton } from './skeleton';
export const LinkExternalIcon = ({ color }: { color?: ChakraLinkProps['color'] }) => (
);
interface LinkPropsChakra extends ChakraLinkProps {
loading?: boolean;
external?: boolean;
iconColor?: ChakraLinkProps['color'];
noIcon?: boolean;
disabled?: boolean;
}
interface LinkPropsNext extends Partial> {}
export interface LinkProps extends LinkPropsChakra, LinkPropsNext {}
const splitProps = (props: LinkProps): { chakra: LinkPropsChakra; next: NextLinkProps } => {
const { scroll = true, shallow = false, prefetch = false, ...rest } = props;
return {
chakra: rest,
next: {
href: rest.href as NextLinkProps['href'],
scroll,
shallow,
prefetch,
},
};
};
export const Link = React.forwardRef(
function Link(props, ref) {
const { chakra, next } = splitProps(props);
const { external, loading, href, children, disabled, noIcon, iconColor, ...rest } = chakra;
if (external) {
// Strip UTM parameters from external links if in private mode
const processedHref = typeof href === 'string' ? stripUtmParams(href) : href;
return (
} asChild>
{ children }
{ !noIcon && }
);
}
return (
} asChild>
{ next.href ? (
{ children }
) :
{ children }
}
);
},
);
export const LinkBox = ChakraLinkBox;
export const LinkOverlay = React.forwardRef(
function LinkOverlay(props, ref) {
const { chakra, next } = splitProps(props);
const { children, external, loading, href, noIcon, iconColor, ...rest } = chakra;
if (external) {
// Strip UTM parameters from external links if in private mode
const processedHref = typeof href === 'string' ? stripUtmParams(href) : href;
return (
{ (children || (!noIcon && href)) && (
{ children }
{ !noIcon && href && }
) }
);
}
const content = children ? (
{ children }
) : null;
return (
{ next.href ? { content } : content }
);
},
);