1
0
Fork 1
mirror of https://github.com/SomboChea/ui synced 2024-05-21 02:41:36 +07:00
verdaccio-ui/src/components/Link/Link.tsx

34 lines
953 B
TypeScript

import React, { MouseEvent } from 'react';
import { Link as RouterLink } from 'react-router-dom';
import Text, { TextProps } from '../../muiComponents/Text';
interface Props extends Pick<TextProps, 'variant'> {
external?: boolean;
className?: string;
to: string;
children?: React.ReactNode;
onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
}
type LinkRef = HTMLAnchorElement;
/* eslint-disable verdaccio/jsx-spread */
const Link = React.forwardRef<LinkRef, Props>(function Link(
{ external, to, children, variant, className, ...props },
ref
) {
const LinkTextContent = <Text variant={variant}>{children}</Text>;
return external ? (
<a className={className} href={to} ref={ref} rel="noopener noreferrer" target="_blank" {...props}>
{LinkTextContent}
</a>
) : (
<RouterLink className={className} innerRef={ref} to={to} {...props}>
{LinkTextContent}
</RouterLink>
);
});
export default Link;