-
Notifications
You must be signed in to change notification settings - Fork 208
feat(qrcode): add hover-to-copy functionality #2851 #3345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
1d8afdd
933eb53
0a5b51a
4d0bd8f
224d790
549176e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,8 @@ | ||
| import ReactQRCode from "react-qr-code"; | ||
| import { classNames, useTheme } from "~/app/utils"; | ||
| import { useState } from "react"; | ||
| import { useTranslation } from "react-i18next"; | ||
| import { CopyIcon } from "@bitcoin-design/bitcoin-icons-react/filled"; | ||
|
||
|
|
||
| export type Props = { | ||
| value: string; | ||
|
|
@@ -15,21 +18,56 @@ export type Props = { | |
| // (meaning you have to aim your phone very precisely and have to wait longer for the reader | ||
| // to recognize the QR code) | ||
| level?: "Q" | undefined; | ||
| onCopy?: () => void; | ||
| }; | ||
|
|
||
| export default function QRCode({ value, size, level, className }: Props) { | ||
| export default function QRCode({ | ||
| value, | ||
| size, | ||
| level, | ||
| className, | ||
| onCopy, | ||
| }: Props) { | ||
| const theme = useTheme(); | ||
| const fgColor = theme === "dark" ? "#FFFFFF" : "#000000"; | ||
| const bgColor = theme === "dark" ? "#000000" : "#FFFFFF"; | ||
| const { t } = useTranslation("components"); | ||
| const [isHovering, setIsHovering] = useState(false); | ||
|
|
||
| const handleCopy = () => { | ||
| navigator.clipboard.writeText(value); | ||
| onCopy?.(); | ||
| }; | ||
|
|
||
| return ( | ||
| <ReactQRCode | ||
| value={value} | ||
| size={size} | ||
| fgColor={fgColor} | ||
| bgColor={bgColor} | ||
| className={classNames("w-full h-auto rounded-md", className ?? "")} | ||
| level={level} | ||
| /> | ||
| <div | ||
| className="relative cursor-pointer" | ||
| onClick={handleCopy} | ||
| onMouseEnter={() => setIsHovering(true)} | ||
| onMouseLeave={() => setIsHovering(false)} | ||
| > | ||
| <ReactQRCode | ||
| value={value} | ||
| size={size} | ||
| fgColor={fgColor} | ||
| bgColor={bgColor} | ||
| className={classNames( | ||
| "w-full h-auto rounded-md transition-opacity", | ||
| isHovering ? "opacity-80" : "opacity-100", | ||
|
||
| className ?? "" | ||
| )} | ||
| level={level} | ||
| /> | ||
| {isHovering && ( | ||
| <div className="absolute inset-0 flex items-center justify-center bg-black bg-opacity-50 rounded-md"> | ||
| <div className="flex flex-col items-center"> | ||
| <CopyIcon className="h-8 w-8 text-white" /> | ||
| <span className="text-white font-medium mt-2"> | ||
| {t("allowance_menu.qrcode.click_to_copy")} | ||
| </span> | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,7 @@ function Receive() { | |
| value={lightningAddress} | ||
| size={192} | ||
| level="Q" | ||
| onCopy={() => toast.success("Copied to clipboard")} | ||
|
||
| /> | ||
| </> | ||
| )} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1216,7 +1216,10 @@ | |
| "always_allow": "Always allow", | ||
| "always_reject": "Always reject" | ||
| }, | ||
| "website_permissions": "Website Permissions" | ||
| "website_permissions": "Website Permissions", | ||
| "qrcode": { | ||
|
||
| "click_to_copy": "Click to copy" | ||
| } | ||
| }, | ||
| "qrcode_scanner": { | ||
| "title": "Scan QR Code", | ||
|
|
||
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.
why new library for just one icon. we use popicons by default. and i guess copy icon should be there as well PopiconsCopyLine