Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
18 lines
712 B
TypeScript
18 lines
712 B
TypeScript
import QRCode from 'qrcode';
|
|
import { useEffect, useState } from 'react';
|
|
|
|
/** QR как SVG — чёткий на любом экране, без canvas */
|
|
export function Qr({ value, size = 200, label }: { value: string; size?: number; label: string }) {
|
|
const [svg, setSvg] = useState('');
|
|
useEffect(() => {
|
|
let alive = true;
|
|
void QRCode.toString(value, { type: 'svg', margin: 1, errorCorrectionLevel: 'M', color: { dark: '#4A1028', light: '#ffffff' } }).then((s) => {
|
|
if (alive) setSvg(s);
|
|
});
|
|
return () => {
|
|
alive = false;
|
|
};
|
|
}, [value]);
|
|
return <div role="img" aria-label={label} style={{ width: size, height: size }} dangerouslySetInnerHTML={{ __html: svg }} />;
|
|
}
|