import React, { Component } from 'react';
import List from '@material-ui/core/List';
import { DetailContextConsumer, VersionPageConsumerProps } from '../../pages/version/Version';
import { Heading, DistListItem, DistChips } from './styles';
import fileSizeSI from '../../utils/file-size';
import { PackageMetaInterface } from 'types/packageMeta';
class Dist extends Component {
public render(): JSX.Element {
return (
{(context: Partial) => {
return context && context.packageMeta && this.renderDist(context.packageMeta);
}}
);
}
private renderChips(dist, license: string): JSX.Element | never[] {
const distDict = {
'file-count': dist.fileCount,
size: dist.unpackedSize && fileSizeSI(dist.unpackedSize),
license,
};
const chipsList = Object.keys(distDict).reduce((componentList, title, key) => {
// @ts-ignore
const value = distDict[title];
if (value) {
const label = (
{/* eslint-disable-next-line */}
{title.split('-').join(' ')}:{value}
);
// @ts-ignore is not assignable to parameter of type 'never'
componentList.push();
}
return componentList;
}, []);
return chipsList;
}
private renderDist = (packageMeta: PackageMetaInterface) => {
const { dist, license } = packageMeta && packageMeta.latest;
return (
{'Latest Distribution'}}>
{this.renderChips(dist, license)}
);
};
}
export default Dist;