2019-10-05 15:33:31 +07:00
|
|
|
import React, { FC, useContext } from 'react';
|
2019-06-20 19:37:28 +07:00
|
|
|
import List from '@material-ui/core/List';
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-10-05 15:33:31 +07:00
|
|
|
import { DetailContext } from '../../pages/Version';
|
2019-03-28 05:39:06 +07:00
|
|
|
import fileSizeSI from '../../utils/file-size';
|
2019-07-06 16:50:09 +07:00
|
|
|
import { formatLicense } from '../../utils/package';
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-10-08 03:19:18 +07:00
|
|
|
import { Heading, DistListItem, DistChips } from './styles';
|
|
|
|
|
2019-10-05 15:33:31 +07:00
|
|
|
const DistChip: FC<{ name: string }> = ({ name, children }) =>
|
|
|
|
children ? (
|
|
|
|
<DistChips
|
|
|
|
// lint rule conflicting with prettier
|
|
|
|
/* eslint-disable react/jsx-wrap-multilines */
|
|
|
|
label={
|
2019-07-06 23:43:00 +07:00
|
|
|
<>
|
2019-10-05 15:33:31 +07:00
|
|
|
<b>{name}</b>
|
|
|
|
{': '}
|
|
|
|
{children}
|
2019-07-06 23:43:00 +07:00
|
|
|
</>
|
2019-10-05 15:33:31 +07:00
|
|
|
}
|
|
|
|
/* eslint-enable */
|
|
|
|
/>
|
|
|
|
) : null;
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-10-05 15:33:31 +07:00
|
|
|
const Dist: FC = () => {
|
|
|
|
const { packageMeta } = useContext(DetailContext);
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-10-05 15:33:31 +07:00
|
|
|
if (!packageMeta) {
|
|
|
|
return null;
|
|
|
|
}
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-10-05 15:33:31 +07:00
|
|
|
const { dist, license } = packageMeta && packageMeta.latest;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<List subheader={<Heading variant="subtitle1">{'Latest Distribution'}</Heading>}>
|
|
|
|
<DistListItem button={true}>
|
|
|
|
<DistChip name="file count">{dist.fileCount}</DistChip>
|
|
|
|
<DistChip name="size">{dist.unpackedSize && fileSizeSI(dist.unpackedSize)}</DistChip>
|
|
|
|
<DistChip name="license">{formatLicense(license)}</DistChip>
|
|
|
|
</DistListItem>
|
|
|
|
</List>
|
|
|
|
);
|
|
|
|
};
|
2019-03-28 05:39:06 +07:00
|
|
|
|
|
|
|
export default Dist;
|