2019-10-06 21:55:49 +07:00
|
|
|
import React from 'react';
|
|
|
|
import styled from 'react-emotion';
|
|
|
|
import ListItemText from '@material-ui/core/ListItemText';
|
|
|
|
|
|
|
|
import CopyToClipBoard from '../CopyToClipBoard';
|
2019-10-06 23:30:05 +07:00
|
|
|
import Avatar from '../../muiComponents/Avatar';
|
2019-10-13 02:11:23 +07:00
|
|
|
import ListItem from '../../muiComponents/ListItem';
|
2019-10-06 21:55:49 +07:00
|
|
|
|
|
|
|
// logos of package managers
|
|
|
|
import npmLogo from './img/npm.svg';
|
|
|
|
import pnpmLogo from './img/pnpm.svg';
|
|
|
|
import yarnLogo from './img/yarn.svg';
|
|
|
|
|
|
|
|
const InstallItem = styled(ListItem)({
|
|
|
|
padding: 0,
|
|
|
|
':hover': {
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const InstallListItemText = styled(ListItemText)({
|
|
|
|
padding: '0 10px',
|
|
|
|
margin: 0,
|
|
|
|
});
|
|
|
|
|
|
|
|
const PackageMangerAvatar = styled(Avatar)({
|
|
|
|
borderRadius: '0px',
|
|
|
|
padding: '0',
|
|
|
|
});
|
|
|
|
|
|
|
|
export enum DependencyManager {
|
|
|
|
NPM = 'npm',
|
|
|
|
YARN = 'yarn',
|
|
|
|
PNPM = 'pnpm',
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Interface {
|
|
|
|
packageName: string;
|
|
|
|
dependencyManager: DependencyManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
const InstallListItem: React.FC<Interface> = ({ packageName, dependencyManager }) => {
|
|
|
|
switch (dependencyManager) {
|
|
|
|
case DependencyManager.NPM:
|
|
|
|
return (
|
|
|
|
<InstallItem button={true} data-testid={'installListItem-npm'}>
|
|
|
|
<PackageMangerAvatar alt="npm" src={npmLogo} />
|
|
|
|
<InstallListItemText primary={<CopyToClipBoard text={`npm install ${packageName}`} />} secondary={'Install using npm'} />
|
|
|
|
</InstallItem>
|
|
|
|
);
|
|
|
|
case DependencyManager.YARN:
|
|
|
|
return (
|
|
|
|
<InstallItem button={true} data-testid={'installListItem-yarn'}>
|
2019-10-25 04:51:27 +07:00
|
|
|
<PackageMangerAvatar alt="yarn" src={yarnLogo} />
|
2019-10-06 21:55:49 +07:00
|
|
|
<InstallListItemText primary={<CopyToClipBoard text={`yarn add ${packageName}`} />} secondary={'Install using yarn'} />
|
|
|
|
</InstallItem>
|
|
|
|
);
|
|
|
|
case DependencyManager.PNPM:
|
|
|
|
return (
|
|
|
|
<InstallItem button={true} data-testid={'installListItem-pnpm'}>
|
2019-10-25 04:51:27 +07:00
|
|
|
<PackageMangerAvatar alt={'pnpm'} src={pnpmLogo} />
|
2019-10-06 21:55:49 +07:00
|
|
|
<InstallListItemText primary={<CopyToClipBoard text={`pnpm install ${packageName}`} />} secondary={'Install using pnpm'} />
|
|
|
|
</InstallItem>
|
|
|
|
);
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default InstallListItem;
|