import { faFileDownload as downloadIcon } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { useMemo, useState } from 'react'; import { ExternalLink } from 'react-external-link'; import { Button, FormGroup, Modal, ModalBody, ModalHeader, Row } from 'reactstrap'; import { CopyToClipboardIcon } from '../../utils/components/CopyToClipboardIcon'; import type { QrCodeFormat, QrErrorCorrection } from '../../utils/helpers/qrCodes'; import { buildQrCodeUrl } from '../../utils/helpers/qrCodes'; import type { ImageDownloader } from '../../utils/services/ImageDownloader'; import type { ShortUrlModalProps } from '../data'; import { QrErrorCorrectionDropdown } from './qr-codes/QrErrorCorrectionDropdown'; import { QrFormatDropdown } from './qr-codes/QrFormatDropdown'; import './QrCodeModal.scss'; export const QrCodeModal = (imageDownloader: ImageDownloader) => ( { shortUrl: { shortUrl, shortCode }, toggle, isOpen }: ShortUrlModalProps, ) => { const [size, setSize] = useState(300); const [margin, setMargin] = useState(0); const [format, setFormat] = useState('png'); const [errorCorrection, setErrorCorrection] = useState('L'); const qrCodeUrl = useMemo( () => buildQrCodeUrl(shortUrl, { size, format, margin, errorCorrection }), [shortUrl, size, format, margin, errorCorrection], ); const totalSize = useMemo(() => size + margin, [size, margin]); const modalSize = useMemo(() => { if (totalSize < 500) { return undefined; } return totalSize < 800 ? 'lg' : 'xl'; }, [totalSize]); return ( QR code for {shortUrl} setSize(Number(e.target.value))} /> setMargin(Number(e.target.value))} />
QR code
); };