-
Notifications
You must be signed in to change notification settings - Fork 223
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 all commits
1d8afdd
933eb53
0a5b51a
4d0bd8f
224d790
549176e
2335131
9250b9f
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,4 +1,7 @@ | ||
| import { PopiconsCopyLine } from "@popicons/react"; | ||
| import { useTranslation } from "react-i18next"; | ||
| import ReactQRCode from "react-qr-code"; | ||
| import toast from "~/app/components/Toast"; | ||
| import { classNames, useTheme } from "~/app/utils"; | ||
|
|
||
| export type Props = { | ||
|
|
@@ -21,15 +24,29 @@ export default function QRCode({ value, size, level, className }: Props) { | |
| const theme = useTheme(); | ||
| const fgColor = theme === "dark" ? "#FFFFFF" : "#000000"; | ||
| const bgColor = theme === "dark" ? "#000000" : "#FFFFFF"; | ||
| const { t } = useTranslation("common"); | ||
|
|
||
| const handleCopy = () => { | ||
| navigator.clipboard.writeText(value); | ||
| toast.success(t("actions.copied_to_clipboard")); | ||
| }; | ||
|
|
||
| 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 group" onClick={handleCopy}> | ||
| <ReactQRCode | ||
| value={value} | ||
| size={size} | ||
| fgColor={fgColor} | ||
| bgColor={bgColor} | ||
| className={classNames( | ||
| "w-full h-auto rounded-md transition-opacity group-hover:opacity-80", | ||
| className ?? "" | ||
| )} | ||
| level={level} | ||
| /> | ||
| <div className="absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity"> | ||
| <PopiconsCopyLine className="h-8 w-8 text-white drop-shadow-lg" /> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where this is used now? i don't see any apperance of this |
||
| </div> | ||
|
Comment on lines
+47
to
+49
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy icon is invisible on light theme. The copy icon uses Consider using a theme-aware color or adding a semi-transparent background behind the icon. 🎨 Proposed fix - add background to icon container <div className="absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity">
- <PopiconsCopyLine className="h-8 w-8 text-white drop-shadow-lg" />
+ <div className="bg-black/50 dark:bg-white/50 rounded-full p-2">
+ <PopiconsCopyLine className="h-8 w-8 text-white dark:text-black drop-shadow-lg" />
+ </div>
</div>🤖 Prompt for AI Agents |
||
| </div> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,7 +149,7 @@ function ReceiveInvoice() { | |
| <div className="relative flex items-center justify-center"> | ||
| <QRCode | ||
| value={invoice.paymentRequest.toUpperCase()} | ||
| size={512} | ||
| size={192} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert |
||
| /> | ||
| {isAlbyOAuthUser ? ( | ||
| <> | ||
|
|
||
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.
Add error handling for clipboard API.
navigator.clipboard.writeText()returns a Promise that can reject (e.g., clipboard permission denied, insecure context). The current implementation ignores errors, which could result in silent failures with no user feedback.🛡️ Proposed fix
const handleCopy = () => { - navigator.clipboard.writeText(value); - toast.success(t("actions.copied_to_clipboard")); + navigator.clipboard.writeText(value) + .then(() => { + toast.success(t("actions.copied_to_clipboard")); + }) + .catch((err) => { + console.error("Failed to copy:", err); + toast.error(t("actions.copy_failed")); + }); };Alternatively, using async/await:
Note: You may need to add a translation key for the error case (e.g.,
actions.copy_failed).🤖 Prompt for AI Agents