2019-10-05 15:33:31 +07:00
|
|
|
import React, { FC, useContext } from 'react';
|
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-10-13 03:26:56 +07:00
|
|
|
import List from '../../muiComponents/List';
|
2019-03-28 05:39:06 +07:00
|
|
|
|
2019-10-13 02:41:42 +07:00
|
|
|
import { StyledText, DistListItem, DistChips } from './styles';
|
2019-10-08 03:19:18 +07:00
|
|
|
|
2019-10-05 15:33:31 +07:00
|
|
|
const DistChip: FC<{ name: string }> = ({ name, children }) =>
|
|
|
|
children ? (
|
|
|
|
<DistChips
|
|
|
|
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
|
|
|
}
|
|
|
|
/>
|
|
|
|
) : 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 (
|
2019-10-13 02:41:42 +07:00
|
|
|
<List subheader={<StyledText variant="subtitle1">{'Latest Distribution'}</StyledText>}>
|
2019-10-05 15:33:31 +07:00
|
|
|
<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;
|