Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
50b78567
Commit
50b78567
authored
Feb 14, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix copy to clipboard
parent
4787979f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
4 deletions
+13
-4
CopyToClipboard.tsx
ui/shared/CopyToClipboard.tsx
+13
-4
No files found.
ui/shared/CopyToClipboard.tsx
View file @
50b78567
import
{
IconButton
,
Tooltip
,
useClipboard
,
chakra
}
from
'
@chakra-ui/react
'
;
import
{
IconButton
,
Tooltip
,
useClipboard
,
chakra
,
useDisclosure
}
from
'
@chakra-ui/react
'
;
import
React
,
{
useEffect
,
useState
}
from
'
react
'
;
import
React
,
{
useEffect
,
useState
}
from
'
react
'
;
import
CopyIcon
from
'
icons/copy.svg
'
;
import
CopyIcon
from
'
icons/copy.svg
'
;
...
@@ -6,6 +6,8 @@ import CopyIcon from 'icons/copy.svg';
...
@@ -6,6 +6,8 @@ import CopyIcon from 'icons/copy.svg';
const
CopyToClipboard
=
({
text
,
className
}:
{
text
:
string
;
className
?:
string
})
=>
{
const
CopyToClipboard
=
({
text
,
className
}:
{
text
:
string
;
className
?:
string
})
=>
{
const
{
hasCopied
,
onCopy
}
=
useClipboard
(
text
,
3000
);
const
{
hasCopied
,
onCopy
}
=
useClipboard
(
text
,
3000
);
const
[
copied
,
setCopied
]
=
useState
(
false
);
const
[
copied
,
setCopied
]
=
useState
(
false
);
// have to implement controlled tooltip because of the issue - https://github.com/chakra-ui/chakra-ui/issues/7107
const
{
isOpen
,
onOpen
,
onToggle
,
onClose
}
=
useDisclosure
();
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
hasCopied
)
{
if
(
hasCopied
)
{
...
@@ -15,8 +17,13 @@ const CopyToClipboard = ({ text, className }: {text: string; className?: string}
...
@@ -15,8 +17,13 @@ const CopyToClipboard = ({ text, className }: {text: string; className?: string}
}
}
},
[
hasCopied
]);
},
[
hasCopied
]);
const
handleClick
=
React
.
useCallback
(()
=>
{
onToggle
();
onCopy
();
},
[
onCopy
,
onToggle
]);
return
(
return
(
<
Tooltip
label=
{
copied
?
'
Copied
'
:
'
Copy to clipboard
'
}
closeOnClick=
{
false
}
>
<
Tooltip
label=
{
copied
?
'
Copied
'
:
'
Copy to clipboard
'
}
isOpen=
{
isOpen
}
>
<
IconButton
<
IconButton
aria
-
label=
"copy"
aria
-
label=
"copy"
icon=
{
<
CopyIcon
/>
}
icon=
{
<
CopyIcon
/>
}
...
@@ -25,11 +32,13 @@ const CopyToClipboard = ({ text, className }: {text: string; className?: string}
...
@@ -25,11 +32,13 @@ const CopyToClipboard = ({ text, className }: {text: string; className?: string}
variant=
"simple"
variant=
"simple"
display=
"inline-block"
display=
"inline-block"
flexShrink=
{
0
}
flexShrink=
{
0
}
onClick=
{
onCopy
}
onClick=
{
handleClick
}
className=
{
className
}
className=
{
className
}
onMouseEnter=
{
onOpen
}
onMouseLeave=
{
onClose
}
/>
/>
</
Tooltip
>
</
Tooltip
>
);
);
};
};
export
default
chakra
(
CopyToClipboard
);
export
default
React
.
memo
(
chakra
(
CopyToClipboard
)
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment