'use client' import React, { useEffect, useRef, useState } from 'react' import { useTranslation } from 'react-i18next' import QRCode from 'qrcode.react' import QrcodeStyle from './style.module.css' import Tooltip from '@/app/components/base/tooltip' type Props = { content: string selectorId: string className?: string } const prefixEmbedded = 'appOverview.overview.appInfo.qrcode.title' const ShareQRCode = ({ content, selectorId, className }: Props) => { const { t } = useTranslation() const [isShow, setIsShow] = useState(false) const qrCodeRef = useRef(null) const toggleQRCode = (event: React.MouseEvent) => { event.stopPropagation() setIsShow(prev => !prev) } useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if (qrCodeRef.current && !qrCodeRef.current.contains(event.target as Node)) setIsShow(false) } if (isShow) document.addEventListener('click', handleClickOutside) return () => { document.removeEventListener('click', handleClickOutside) } }, [isShow]) const downloadQR = () => { const canvas = document.getElementsByTagName('canvas')[0] const link = document.createElement('a') link.download = 'qrcode.png' link.href = canvas.toDataURL() link.click() } const handlePanelClick = (event: React.MouseEvent) => { event.stopPropagation() } return (
{isShow && (
{t('appOverview.overview.appInfo.qrcode.scan')}
ยท
{t('appOverview.overview.appInfo.qrcode.download')}
)}
) } export default ShareQRCode