Create a link ui component that abstracts away interval vs. internal links

This commit is contained in:
Fabio Berger 2018-09-26 13:37:25 +01:00
parent 3504e875cc
commit a9b4027dc4

View File

@ -0,0 +1,42 @@
import * as React from 'react';
import { Link as ReactRounterLink } from 'react-router-dom';
export interface LinkProps {
to: string;
isExternal?: boolean;
shouldOpenInNewTab?: boolean;
style?: React.CSSProperties;
className?: string;
}
export const Link: React.StatelessComponent<LinkProps> = ({
style,
className,
isExternal,
to,
shouldOpenInNewTab,
children,
}) => {
if (isExternal) {
return (
<a target={shouldOpenInNewTab && '_blank'} className={className} style={style} href={to}>
{children}
</a>
);
} else {
return (
<ReactRounterLink to={to} className={className} style={style}>
{children}
</ReactRounterLink>
);
}
};
Link.defaultProps = {
isExternal: false,
shouldOpenInNewTab: false,
style: {},
className: '',
};
Link.displayName = 'Link';