Create a link ui component that abstracts away interval vs. internal links
This commit is contained in:
parent
3504e875cc
commit
a9b4027dc4
42
packages/website/ts/components/ui/link.tsx
Normal file
42
packages/website/ts/components/ui/link.tsx
Normal 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';
|
Loading…
x
Reference in New Issue
Block a user