Skip to content

Commit

Permalink
copy QR code on click
Browse files Browse the repository at this point in the history
  • Loading branch information
LiranCohen committed Oct 25, 2024
1 parent 92702f6 commit ffdd40c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/components/connect/connect-qr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@ interface ConnectQRProps {
}

const ConnectQR: React.FC<ConnectQRProps> = ({ close, value }) => {

const copyQRValue = (e: React.MouseEvent<HTMLElement>) => {
navigator.clipboard.writeText(value);
const currentTarget = e.currentTarget;

currentTarget.classList.add('tooltip-active');
setTimeout(() => currentTarget.classList.remove('tooltip-active'), 1000);
}

return (<div>
<a href={value}>
<Typography variant="h3">Scan QR Code</Typography>
<Typography variant="h3">Scan QR Code</Typography>
<a href={value} onClick={copyQRValue} className="tooltip-action">
<span className="tooltip bg-background text-primary">Copied</span>
<QRCodeCanvas value={value} size={256} className="mt-4 p-2 bg-primary" bgColor="rgb(250,204, 21)" fgColor="rgb(41,37,36)" />
</a>
<div className="mt-4">
Expand Down
13 changes: 13 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
@tailwind components;
@tailwind utilities;

.tooltip-action {
@apply relative;
}

.tooltip {
@apply text-sm invisible absolute opacity-0 transition-opacity duration-300 ease-in-out transform -translate-x-1/2 rounded shadow-lg px-3 py-1;
}

.tooltip-active .tooltip {
@apply visible z-50 opacity-100;
animation: fadeIn 0.3s ease-in-out forwards;
}

@layer base {
:root {
--background: 0 0% 100%;
Expand Down
5 changes: 4 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { VitePWA } from "vite-plugin-pwa";
import path from "path";

//@ts-expect-error - no types available
import nodePolyfills from "vite-plugin-node-stdlib-browser";

import { VitePWA } from "vite-plugin-pwa";
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

Expand Down

0 comments on commit ffdd40c

Please sign in to comment.