File tree Expand file tree Collapse file tree 3 files changed +51
-5
lines changed
src/json-crdt-peritext-ui/plugins/toolbar/components Expand file tree Collapse file tree 3 files changed +51
-5
lines changed Original file line number Diff line number Diff line change 106
106
"@types/react" : " ^18.3.11" ,
107
107
"@types/react-dom" : " ^18.3.0" ,
108
108
"benchmark" : " ^2.1.4" ,
109
+ "clipboard-copy" : " ^4.0.1" ,
109
110
"collaborative-editor" : " ^2.8.0" ,
110
111
"collaborative-input" : " ^1.6.1" ,
111
112
"collaborative-ui" : " ^1.6.0" ,
Original file line number Diff line number Diff line change
1
+ import * as React from 'react' ;
2
+ import { useT } from 'use-t' ;
3
+ import { BasicButton , BasicButtonProps } from 'nice-ui/lib/2-inline-block/BasicButton' ;
4
+ import { Iconista } from 'nice-ui/lib/icons/Iconista' ;
5
+ import { BasicTooltip , BasicTooltipProps } from 'nice-ui/lib/4-card/BasicTooltip' ;
6
+ import useMountedState from 'react-use/lib/useMountedState' ;
7
+ const copy = require ( 'clipboard-copy' ) ; // eslint-disable-line
8
+
9
+ const anchor = { horizontal : true , center : true } ;
10
+
11
+ export interface CopyButtonProps extends BasicButtonProps {
12
+ onCopy : ( ) => string ;
13
+ tooltip ?: Partial < BasicTooltipProps > ;
14
+ }
15
+
16
+ export const CopyButton : React . FC < CopyButtonProps > = ( { onCopy, tooltip, ...rest } ) => {
17
+ const [ t ] = useT ( ) ;
18
+ const isMounted = useMountedState ( ) ;
19
+ const [ copied , setCopied ] = React . useState ( false ) ;
20
+
21
+ const handleClick = ( e : React . MouseEvent ) => {
22
+ setCopied ( true ) ;
23
+ copy ( onCopy ( ) ) ;
24
+ setTimeout ( ( ) => {
25
+ if ( isMounted ( ) ) setCopied ( false ) ;
26
+ } , 2000 ) ;
27
+ rest . onClick ?.( e ) ;
28
+ } ;
29
+
30
+ return (
31
+ < BasicTooltip
32
+ anchor = { anchor }
33
+ show = { copied || void 0 }
34
+ renderTooltip = { copied ? ( ) => t ( 'Copied!' ) : ( ) => t ( 'Copy' ) }
35
+ { ...tooltip }
36
+ >
37
+ < BasicButton { ...rest } onClick = { handleClick } >
38
+ < Iconista
39
+ key = { copied ? 'check' : 'copy' }
40
+ set = { copied ? 'atlaskit' : 'lucide' }
41
+ icon = { copied ? 'check' : 'copy' }
42
+ width = { 16 }
43
+ height = { 16 }
44
+ />
45
+ </ BasicButton >
46
+ </ BasicTooltip >
47
+ ) ;
48
+ } ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import {Iconista} from 'nice-ui/lib/icons/Iconista';
9
9
import { Split } from 'nice-ui/lib/3-list-item/Split' ;
10
10
import { BasicTooltip } from 'nice-ui/lib/4-card/BasicTooltip' ;
11
11
import { useT } from 'use-t' ;
12
+ import { CopyButton } from './CopyButton' ;
12
13
13
14
const iconColumn = 40 ;
14
15
@@ -86,11 +87,7 @@ export const UrlDisplayLayout: React.FC<UrlDisplayLayoutProps> = ({url}) => {
86
87
</ div >
87
88
</ div >
88
89
< div className = { buttonGroupClass } >
89
- < BasicTooltip nowrap renderTooltip = { ( ) => t ( 'Copy' ) } >
90
- < BasicButton width = { 48 } height = { 48 } round >
91
- < Iconista width = { 16 } height = { 16 } set = { 'lucide' } icon = 'copy' />
92
- </ BasicButton >
93
- </ BasicTooltip >
90
+ < CopyButton width = { 48 } height = { 48 } round onCopy = { ( ) => url } tooltip = { { anchor : { } } } />
94
91
< BasicTooltip nowrap renderTooltip = { ( ) => t ( 'Open' ) } >
95
92
< BasicButton width = { 48 } height = { 48 } round >
96
93
< Iconista width = { 16 } height = { 16 } set = { 'lucide' } icon = 'external-link' />
You can’t perform that action at this time.
0 commit comments