aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/ts/pages/documentation/source_link.tsx
blob: dceb88b7b14da7955c7c7bf0ab7ef3deb9d1d972 (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
import * as _ from 'lodash';
import {colors} from 'ts/utils/colors';
import * as React from 'react';
import {Source} from 'ts/types';

interface SourceLinkProps {
    source: Source;
    baseUrl: string;
    version: string;
    subPackageName: string;
}

const packagesWithNamespace = [
    'connect',
];

export function SourceLink(props: SourceLinkProps) {
    const src = props.source;
    const url = props.baseUrl;
    const pkg = props.subPackageName;
    let tagPrefix = pkg;
    if (_.includes(packagesWithNamespace, pkg)) {
        tagPrefix = `@0xproject/${pkg}`;
    }
    const sourceCodeUrl = `${url}/blob/${tagPrefix}%40${props.version}/packages/${pkg}/${src.fileName}#L${src.line}`;
    return (
        <div className="pt2" style={{fontSize: 14}}>
            <a
                href={sourceCodeUrl}
                target="_blank"
                className="underline"
                style={{color: colors.grey}}
            >
                Source
            </a>
        </div>
    );
}