import React, { Component } from 'react'; import List from '@material-ui/core/List'; import { VersionPageConsumerProps, DetailContextConsumer } from '../../pages/Version'; import { Heading, DistListItem, DistChips } from './styles'; import fileSizeSI from '../../utils/file-size'; import { PackageMetaInterface } from 'types/packageMeta'; import { formatLicense } from '../../utils/package'; class Dist extends Component { public render(): JSX.Element { return ( {(context: Partial) => { return context && context.packageMeta && this.renderDist(context.packageMeta); }} ); } private renderChips(dist, license: PackageMetaInterface['latest']['license']): (JSX.Element | undefined)[] { const distDict = { 'file-count': dist.fileCount, size: dist.unpackedSize && fileSizeSI(dist.unpackedSize), license, }; const chipsList = Object.keys(distDict).map((dist, key) => { if (!distDict[dist]) return; const value = dist === 'license' ? formatLicense(distDict[dist]) : distDict[dist]; const label = ( <> {/* eslint-disable-next-line */} {dist.replace('-', ' ')}: {value} ); return ; }); return chipsList; } private renderDist = (packageMeta: PackageMetaInterface) => { const { dist, license } = packageMeta && packageMeta.latest; return ( {'Latest Distribution'}}> {this.renderChips(dist, license)} ); }; } export default Dist;