verdaccio-ui/src/components/Dist/Dist.tsx

44 lines
1.1 KiB
TypeScript
Raw Normal View History

import React, { FC, useContext } from 'react';
2019-03-28 05:39:06 +07:00
import { DetailContext } from '../../pages/Version';
2019-03-28 05:39:06 +07:00
import fileSizeSI from '../../utils/file-size';
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
import { StyledText, DistListItem, DistChips } from './styles';
const DistChip: FC<{ name: string }> = ({ name, children }) =>
children ? (
<DistChips
label={
<>
<b>{name}</b>
{': '}
{children}
</>
}
/>
) : null;
2019-03-28 05:39:06 +07:00
const Dist: FC = () => {
const { packageMeta } = useContext(DetailContext);
2019-03-28 05:39:06 +07:00
if (!packageMeta) {
return null;
}
2019-03-28 05:39:06 +07:00
const { dist, license } = packageMeta && packageMeta.latest;
return (
<List subheader={<StyledText variant="subtitle1">{'Latest Distribution'}</StyledText>}>
<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;