mirror of
https://github.com/SomboChea/ui
synced 2024-06-27 21:45:33 +07:00
34 lines
953 B
TypeScript
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;
|