mirror of
https://github.com/zhigang1992/react.git
synced 2026-03-26 22:42:51 +08:00
chore: replace clipboard hooks with use-clipboard-copy
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import React, { MouseEvent, useState } from 'react'
|
||||
import { LivePreview, LiveProvider, LiveEditor, LiveError } from 'react-live'
|
||||
import useClipboard from 'react-use-clipboard'
|
||||
import { useClipboard } from 'use-clipboard-copy'
|
||||
import withDefaults from 'components/utils/with-defaults'
|
||||
import { useTheme, useToasts } from 'components'
|
||||
import makeCodeTheme from './code-theme'
|
||||
@@ -29,7 +29,7 @@ export type PlaygroundProps = Props & typeof defaultProps
|
||||
const editor = (code: string) => {
|
||||
const theme = useTheme()
|
||||
const [visible, setVisible] = useState(false)
|
||||
const [, setCopied] = useClipboard(code)
|
||||
const { copy } = useClipboard()
|
||||
const [, setToast] = useToasts()
|
||||
const clickHandler = (event: MouseEvent<HTMLDetailsElement>) => {
|
||||
event.stopPropagation()
|
||||
@@ -37,10 +37,10 @@ const editor = (code: string) => {
|
||||
setVisible(!visible)
|
||||
}
|
||||
|
||||
const copy = (event: MouseEvent<SVGElement>) => {
|
||||
const copyHandler = (event: MouseEvent<SVGElement>) => {
|
||||
event.stopPropagation()
|
||||
event.preventDefault()
|
||||
setCopied()
|
||||
copy(code)
|
||||
setToast({ text: 'code copied.' })
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ const editor = (code: string) => {
|
||||
<span>Code Editor</span>
|
||||
</div>
|
||||
<div>
|
||||
{visible && <CopyIcon onClick={copy} />}
|
||||
{visible && <CopyIcon onClick={copyHandler} />}
|
||||
</div>
|
||||
</summary>
|
||||
<div className="area">
|
||||
|
||||
@@ -65,12 +65,12 @@
|
||||
"react": "^16.13.0",
|
||||
"react-dom": "^16.13.0",
|
||||
"react-live": "^2.2.2",
|
||||
"react-use-clipboard": "^1.0.0",
|
||||
"styled-jsx": "^3.2.4",
|
||||
"typescript": "^3.8.2",
|
||||
"typescript-transform-paths": "^1.1.14",
|
||||
"use-clipboard-copy": "^0.1.2",
|
||||
"webpack": "^4.41.6",
|
||||
"webpack-cli": "^3.3.11"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
}
|
||||
|
||||
31
yarn.lock
31
yarn.lock
@@ -2204,6 +2204,11 @@ cli-width@^2.0.0:
|
||||
resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.2.0.tgz#ff19ede8a9a5e579324147b0c11f0fbcbabed639"
|
||||
integrity sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=
|
||||
|
||||
clipboard-copy@^3.0.0:
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/clipboard-copy/-/clipboard-copy-3.1.0.tgz#4c59030a43d4988990564a664baeafba99f78ca4"
|
||||
integrity sha512-Xsu1NddBXB89IUauda5BIq3Zq73UWkjkaQlPQbLNvNsd5WBMnTWPNKYR6HGaySOxGYZ+BKxP2E9X4ElnI3yiPA==
|
||||
|
||||
clipboard@^2.0.0:
|
||||
version "2.0.6"
|
||||
resolved "https://registry.yarnpkg.com/clipboard/-/clipboard-2.0.6.tgz#52921296eec0fdf77ead1749421b21c968647376"
|
||||
@@ -2425,13 +2430,6 @@ 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.0.8:
|
||||
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==
|
||||
dependencies:
|
||||
toggle-selection "^1.0.6"
|
||||
|
||||
core-js-compat@^3.1.1:
|
||||
version "3.6.4"
|
||||
resolved "https://registry.yarnpkg.com/core-js-compat/-/core-js-compat-3.6.4.tgz#938476569ebb6cda80d339bcf199fae4f16fff17"
|
||||
@@ -6411,13 +6409,6 @@ react-simple-code-editor@^0.10.0:
|
||||
resolved "https://registry.yarnpkg.com/react-simple-code-editor/-/react-simple-code-editor-0.10.0.tgz#73e7ac550a928069715482aeb33ccba36efe2373"
|
||||
integrity sha512-bL5W5mAxSW6+cLwqqVWY47Silqgy2DKDTR4hDBrLrUqC5BXc29YVx17l2IZk5v36VcDEq1Bszu2oHm1qBwKqBA==
|
||||
|
||||
react-use-clipboard@^1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/react-use-clipboard/-/react-use-clipboard-1.0.0.tgz#dee4447ffbf98516caf0b2a3e95508baeec097b8"
|
||||
integrity sha512-yWZMJW2uhi4zUrSNIjSJn5cytEXO1kuSSvC2sYKiQdPWoBWpee4JckZzcNWoyN2g2+mCWkxrbeVFuYH0bYK+7Q==
|
||||
dependencies:
|
||||
copy-to-clipboard "^3.0.8"
|
||||
|
||||
react@^16.13.0:
|
||||
version "16.13.0"
|
||||
resolved "https://registry.yarnpkg.com/react/-/react-16.13.0.tgz#d046eabcdf64e457bbeed1e792e235e1b9934cf7"
|
||||
@@ -7533,11 +7524,6 @@ to-style@^1.3.3:
|
||||
resolved "https://registry.yarnpkg.com/to-style/-/to-style-1.3.3.tgz#63a2b70a6f4a7d4fdc2ed57a0be4e7235cb6699c"
|
||||
integrity sha1-Y6K3Cm9KfU/cLtV6C+TnI1y2aZw=
|
||||
|
||||
toggle-selection@^1.0.6:
|
||||
version "1.0.6"
|
||||
resolved "https://registry.yarnpkg.com/toggle-selection/-/toggle-selection-1.0.6.tgz#6e45b1263f2017fa0acc7d89d78b15b8bf77da32"
|
||||
integrity sha1-bkWxJj8gF/oKzH2J14sVuL932jI=
|
||||
|
||||
toidentifier@1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.0.tgz#7e1be3470f1e77948bc43d94a3c8f4d7752ba553"
|
||||
@@ -7899,6 +7885,13 @@ url@0.11.0, url@^0.11.0:
|
||||
punycode "1.3.2"
|
||||
querystring "0.2.0"
|
||||
|
||||
use-clipboard-copy@^0.1.2:
|
||||
version "0.1.2"
|
||||
resolved "https://registry.yarnpkg.com/use-clipboard-copy/-/use-clipboard-copy-0.1.2.tgz#83b16292dfa8ea262be714252022a8b4ad1c28c5"
|
||||
integrity sha512-EkauxqyX+us4+Mfif/f61ew89EAOWIArqFpHR0jSG4SwwuDZzDAOeqO7gkK0vi+DQVADeB1RB3xqU3U0oOO3NQ==
|
||||
dependencies:
|
||||
clipboard-copy "^3.0.0"
|
||||
|
||||
use-subscription@1.1.1:
|
||||
version "1.1.1"
|
||||
resolved "https://registry.yarnpkg.com/use-subscription/-/use-subscription-1.1.1.tgz#5509363e9bb152c4fb334151d4dceb943beaa7bb"
|
||||
|
||||
Reference in New Issue
Block a user