aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/components/ui/link.tsx
blob: 252199457e85af1eca32905ec19fc6b7d99e075b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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';