Skip to content

Commit

Permalink
feat: add “Copy URL” button to asset metadata actions
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyward committed Apr 27, 2021
1 parent 2c37ce5 commit 4cf25cc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@sanity/icons": "1.0.2",
"@sanity/ui": ">=0.33.11",
"@tanem/react-nprogress": "3.0.52",
"copy-to-clipboard": "^3.3.1",
"date-fns": "2.16.1",
"filesize": "6.1.0",
"framer-motion": "3.6.1",
Expand Down
17 changes: 15 additions & 2 deletions src/components/AssetMetadata/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {DownloadIcon} from '@sanity/icons'
import {DownloadIcon, ClipboardIcon} from '@sanity/icons'
import {Box, Button, Flex, Stack, Text} from '@sanity/ui'
import {Asset, AssetItem} from '@types'
import format from 'date-fns/format'
import filesize from 'filesize'
import React, {FC, ReactNode} from 'react'
import copy from 'copy-to-clipboard'

import getAssetResolution from '../../utils/getAssetResolution'
import {isImageAsset} from '../../utils/typeGuards'
Expand Down Expand Up @@ -50,6 +51,9 @@ const AssetMetadata: FC<Props> = (props: Props) => {
const handleDownload = () => {
window.location.href = `${asset.url}?dl=${asset.originalFilename}`
}
const handleCopy = () => {
copy(asset.url)
}

return (
<Box marginTop={3}>
Expand Down Expand Up @@ -90,7 +94,7 @@ const AssetMetadata: FC<Props> = (props: Props) => {
</>
)}

{/* Download button */}
{/* Asset actions */}
<Box marginTop={5}>
<Button
disabled={!item || item?.updating}
Expand All @@ -100,6 +104,15 @@ const AssetMetadata: FC<Props> = (props: Props) => {
onClick={handleDownload}
text="Download"
/>

<Button
disabled={!item || item?.updating}
fontSize={1}
icon={ClipboardIcon}
mode="ghost"
onClick={handleCopy}
text="Copy URL"
/>
</Box>
</Box>
)
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2102,7 +2102,7 @@ copy-descriptor@^0.1.0:
resolved "https://registry.yarnpkg.com/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d"
integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=

copy-to-clipboard@^3.2.0:
copy-to-clipboard@^3.2.0, copy-to-clipboard@^3.3.1:
version "3.3.1"
resolved "https://registry.yarnpkg.com/copy-to-clipboard/-/copy-to-clipboard-3.3.1.tgz#115aa1a9998ffab6196f93076ad6da3b913662ae"
integrity sha512-i13qo6kIHTTpCm8/Wup+0b1mVWETvu2kIMzKoK8FpkLkFxlt0znUAHcMzox+T8sPlqtZXq3CulEjQHsYiGFJUw==
Expand Down

0 comments on commit 4cf25cc

Please sign in to comment.