Skip to content

Commit

Permalink
fix(web): fix copy error
Browse files Browse the repository at this point in the history
  • Loading branch information
xinyao27 committed Aug 29, 2022
1 parent 77982e0 commit c5d1340
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"clsx": "^1.2.1",
"common": "workspace:*",
"config": "workspace:*",
"copy-to-clipboard": "^3.3.2",
"downshift": "^6.1.9",
"framer-motion": "^7.2.1",
"highcharts": "^10.2.0",
Expand Down
15 changes: 6 additions & 9 deletions packages/web/src/components/copy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Box, IconButton, useToast } from '@chakra-ui/react'
import type { FC } from 'react'
import { useCallback } from 'react'
import { RiClipboardLine } from 'react-icons/ri'
import copy from 'copy-to-clipboard'
import ThemeBox from './themeBox'

interface Props {
Expand All @@ -11,16 +12,12 @@ interface Props {
const Copy: FC<Props> = ({ children }) => {
const toast = useToast()
const handleClick = useCallback(() => {
navigator.clipboard.writeText(children)
.then(() => {
copy(children, {
format: 'text/plain',
onCopy() {
toast({ title: 'Copied to clipboard!' })
})
.catch(() => {
toast({
title: 'Copy to clipboard error!',
status: 'error',
})
})
},
})
}, [])

return (
Expand Down
12 changes: 10 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c5d1340

Please sign in to comment.