11import React from 'react' ;
22import BugReport from '@material-ui/icons/BugReport' ;
3+ import DownloadIcon from '@material-ui/icons/CloudDownload' ;
34import HomeIcon from '@material-ui/icons/Home' ;
45
56import { PackageMetaInterface , Author as PackageAuthor } from '../../../types/packageMeta' ;
@@ -8,6 +9,7 @@ import fileSizeSI from '../../utils/file-size';
89import { formatDate , formatDateDistance } from '../../utils/package' ;
910import Tooltip from '../../muiComponents/Tooltip' ;
1011import { isURL } from '../../utils/url' ;
12+ import { downloadHandler } from '../ActionBar/ActionBar' ;
1113import ListItem from '../../muiComponents/ListItem' ;
1214import Grid from '../../muiComponents/Grid' ;
1315
@@ -34,6 +36,7 @@ interface Bugs {
3436}
3537interface Dist {
3638 unpackedSize : number ;
39+ tarball : string ;
3740}
3841
3942export interface PackageInterface {
@@ -132,6 +135,21 @@ const Package: React.FC<PackageInterface> = ({
132135 </ a >
133136 ) ;
134137
138+ const renderDownloadLink = ( ) : React . ReactNode =>
139+ dist &&
140+ dist . tarball &&
141+ isURL ( dist . tarball ) && (
142+ // eslint-disable-next-line
143+ < a onClick = { ( ) => downloadHandler ( dist . tarball . replace ( `https://registry.npmjs.org/` , window . location . href ) ) } target = { '_blank' } >
144+ < Tooltip aria-label = { 'Download the tar file' } title = { 'Download tarball' } >
145+ < IconButton aria-label = { 'Download' } >
146+ { /* eslint-disable-next-line react/jsx-max-depth */ }
147+ < DownloadIcon />
148+ </ IconButton >
149+ </ Tooltip >
150+ </ a >
151+ ) ;
152+
135153 const renderPrimaryComponent = ( ) : React . ReactNode => {
136154 return (
137155 < Grid container = { true } item = { true } xs = { 12 } >
@@ -144,6 +162,7 @@ const Package: React.FC<PackageInterface> = ({
144162 < GridRightAligned item = { true } xs = { true } >
145163 { renderHomePageLink ( ) }
146164 { renderBugsLink ( ) }
165+ { renderDownloadLink ( ) }
147166 </ GridRightAligned >
148167 </ Grid >
149168 ) ;
0 commit comments