diff --git a/wally-registry-frontend/src/pages/Package.tsx b/wally-registry-frontend/src/pages/Package.tsx index d7c7d81..a2dde9e 100644 --- a/wally-registry-frontend/src/pages/Package.tsx +++ b/wally-registry-frontend/src/pages/Package.tsx @@ -1,7 +1,6 @@ -import React, { createRef, useEffect, useState } from "react" +import React, { useEffect, useState } from "react" import { useHistory, useLocation, useParams } from "react-router" import styled from "styled-components" -import iconDownload from "../assets/icon-download.svg" import { isMobile, notMobile } from "../breakpoints" import { Button } from "../components/Button" import ContentSection from "../components/ContentSection" @@ -91,6 +90,22 @@ const MetaItemWrapper = styled.div` } ` +const VersionSelect = styled.select` + :hover { + cursor: pointer; + } + + :hover, + :focus { + text-decoration: underline; + color: var(--wally-red); + } + + > option { + color: var(--wally-mauve); + } +` + const AuthorItem = styled.p` white-space: nowrap; overflow: hidden; @@ -141,6 +156,14 @@ const DependencyLinkTooltip = styled.span` } ` +const StyledDownloadLink = styled.a` + display: inline-block; + height: 1rem; + width: auto; + padding-right: 0.3rem; + cursor: pointer; +` + const MetaItem = ({ title, width, @@ -184,16 +207,9 @@ const DownloadLink = ({ filename: string children: React.ReactNode }) => { - const link = createRef() - const handleAction = async () => { - if (link.current === null) { - return - } - if (link.current.href) { - // Already has the download blob - return - } + // Using bare JavaScript mutations over a React ref keeps this link tag keyboard accessible, because you + const link = document.createElement("a") const result = await fetch(url, { headers: { @@ -204,21 +220,45 @@ const DownloadLink = ({ const blob = await result.blob() const href = window.URL.createObjectURL(blob) - link.current.download = filename - link.current.href = href + link.href = href + link.download = filename + + document.body.appendChild(link) - link.current.click() + link.click() + + link.parentNode?.removeChild(link) } return ( <> - + {children} - + ) } +const DownloadIcon = ({ packageName }: { packageName: string }) => ( + + Download a Wally Package + Downloads {packageName} + + + + + +) + type PackageParams = { packageScope: string packageName: string @@ -348,7 +388,7 @@ export default function Package() { - + {packageMetadata.package.license && ( @@ -397,11 +437,7 @@ export default function Package() { ".zip" } > - Download +