ant-design/components/qr-code/demo/download.tsx
kiner-tang ff12f47d18
feat: use rc-qrcode instead of qrcode.react (#49454)
* feat: use rc-qrcode instead of qrcode.react

* feat: optimize code

* feat: update test case

---------

Signed-off-by: kiner-tang <1127031143@qq.com>
2024-06-21 11:42:21 +08:00

32 lines
788 B
TypeScript

import React from 'react';
import { Button, QRCode } from 'antd';
const downloadQRCode = () => {
const canvas = document.getElementById('myqrcode')?.querySelector<HTMLCanvasElement>('canvas');
if (canvas) {
const url = canvas.toDataURL();
const a = document.createElement('a');
a.download = 'QRCode.png';
a.href = url;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
};
const App: React.FC = () => (
<div id="myqrcode">
<QRCode
value="https://ant.design/"
bgColor="#fff"
style={{ marginBottom: 16 }}
icon="https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg"
/>
<Button type="primary" onClick={downloadQRCode}>
Download
</Button>
</div>
);
export default App;