-
-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add copy link to clipboard button
* feat: Add copy link to clipboard button(#362) * change the icon and color * added cursor-pointer
- Loading branch information
1 parent
d316739
commit 1bec243
Showing
7 changed files
with
697 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import useCopyToClipboard from 'hooks/useCopyToClipboard' | ||
import React from 'react' | ||
import { FaRegCopy } from 'react-icons/fa' | ||
|
||
type CopyToClipboardProps = { | ||
url: string | ||
} | ||
|
||
export const CopyToClipboard = ({ url }: CopyToClipboardProps): JSX.Element => { | ||
const [copyToClipboard, { success }] = useCopyToClipboard() | ||
|
||
function handleCopy(e: React.MouseEvent<SVGElement, MouseEvent>) { | ||
e.stopPropagation() | ||
copyToClipboard(url) | ||
} | ||
|
||
return ( | ||
<div className="dropdown dropdown-left dropdown-hover"> | ||
<FaRegCopy | ||
size={'1.3rem'} | ||
className="text-violet-500 cursor-pointer" | ||
onClick={(e) => handleCopy(e)} | ||
/> | ||
<p className="dropdown-content bg-violet-500 text-white text-sm rounded-lg p-1.5 cursor-default"> | ||
{success ? 'Copied!' : 'Copy'} | ||
</p> | ||
</div> | ||
) | ||
} | ||
|
||
export default CopyToClipboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { CopyToClipboard } from './CopyToClipboard' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import copy from 'copy-to-clipboard' | ||
import { useState } from 'react' | ||
|
||
interface CopyToClipboardReturnValue { | ||
value: string | ||
success: boolean | ||
} | ||
|
||
type CopyToClipboardFunction = (text: string, options?: object) => void | ||
|
||
export default function useCopyToClipboard(): [ | ||
CopyToClipboardFunction, | ||
CopyToClipboardReturnValue | ||
] { | ||
const [value, setValue] = useState('') | ||
const [success, setSuccess] = useState(false) | ||
|
||
const copyToClipboard: CopyToClipboardFunction = (text, options) => { | ||
const result = copy(text, options) | ||
if (result) setValue(text) | ||
setSuccess(result) | ||
|
||
setTimeout(() => setSuccess(false), 1500) | ||
} | ||
|
||
return [copyToClipboard, { value, success }] | ||
} |
Oops, something went wrong.
1bec243
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
linkshub – ./
linkshub-rupali-codes.vercel.app
linkshub.vercel.app
linkshub-git-main-rupali-codes.vercel.app