2019-06-20 19:37:28 +07:00
|
|
|
import List from '@material-ui/core/List';
|
|
|
|
import ListItemText from '@material-ui/core/ListItemText';
|
2019-03-28 05:39:06 +07:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
2019-08-25 19:34:27 +07:00
|
|
|
import { DetailContextConsumer, VersionPageConsumerProps } from '../../pages/Version';
|
|
|
|
|
2019-02-03 17:23:33 +07:00
|
|
|
import CopyToClipBoard from '../CopyToClipBoard';
|
|
|
|
|
2019-03-28 05:39:06 +07:00
|
|
|
// logos of package managers
|
|
|
|
import npm from './img/npm.svg';
|
|
|
|
import pnpm from './img/pnpm.svg';
|
|
|
|
import yarn from './img/yarn.svg';
|
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
import { Heading, InstallItem, PackageMangerAvatar } from './styles';
|
|
|
|
|
2019-03-28 05:39:06 +07:00
|
|
|
class Install extends Component {
|
2019-06-24 04:44:53 +07:00
|
|
|
public render(): JSX.Element {
|
2019-02-03 17:23:33 +07:00
|
|
|
return (
|
|
|
|
<DetailContextConsumer>
|
2019-06-24 04:44:53 +07:00
|
|
|
{(context: Partial<VersionPageConsumerProps>) => {
|
2019-06-20 19:37:28 +07:00
|
|
|
return context && context.packageName && this.renderCopyCLI(context);
|
2019-02-03 17:23:33 +07:00
|
|
|
}}
|
|
|
|
</DetailContextConsumer>
|
|
|
|
);
|
2019-03-28 05:39:06 +07:00
|
|
|
}
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-06-24 04:44:53 +07:00
|
|
|
public renderCopyCLI = ({ packageName = '' }: Partial<VersionPageConsumerProps>) => {
|
2019-02-03 17:23:33 +07:00
|
|
|
return (
|
2019-03-28 05:39:06 +07:00
|
|
|
<>
|
|
|
|
<List subheader={<Heading variant={'subheading'}>{'Installation'}</Heading>}>{this.renderListItems(packageName)}</List>
|
|
|
|
</>
|
2019-02-03 17:23:33 +07:00
|
|
|
);
|
2019-03-28 05:39:06 +07:00
|
|
|
};
|
2019-02-03 17:23:33 +07:00
|
|
|
|
2019-06-20 19:37:28 +07:00
|
|
|
public renderListItems = (packageName: string) => {
|
2019-02-03 17:23:33 +07:00
|
|
|
return (
|
2019-03-28 05:39:06 +07:00
|
|
|
<>
|
|
|
|
<InstallItem>
|
|
|
|
<PackageMangerAvatar alt={'npm logo'} src={npm} />
|
|
|
|
<ListItemText primary={<CopyToClipBoard text={`npm install ${packageName}`} />} secondary={'Install using NPM'} />
|
|
|
|
</InstallItem>
|
|
|
|
<InstallItem>
|
|
|
|
<PackageMangerAvatar alt={'yarn logo'} src={yarn} />
|
|
|
|
<ListItemText primary={<CopyToClipBoard text={`yarn add ${packageName}`} />} secondary={'Install using Yarn'} />
|
|
|
|
</InstallItem>
|
|
|
|
<InstallItem>
|
|
|
|
<PackageMangerAvatar alt={'pnpm logo'} src={pnpm} />
|
|
|
|
<ListItemText primary={<CopyToClipBoard text={`pnpm install ${packageName}`} />} secondary={'Install using PNPM'} />
|
|
|
|
</InstallItem>
|
|
|
|
</>
|
2019-02-03 17:23:33 +07:00
|
|
|
);
|
2019-03-28 05:39:06 +07:00
|
|
|
};
|
2019-02-03 17:23:33 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Install;
|