fix: QrCode 패키지 변경

This commit is contained in:
minseonju 2025-05-19 15:47:30 +09:00
commit 62e0d4c079
2 changed files with 12 additions and 34 deletions

View file

@ -2,10 +2,9 @@
import React, { useState } from 'react';
import ToolTextInput from '@components/input/ToolTextInput';
import ToolTextResult from '@components/result/ToolTextResult';
import { ToolComponentProps } from '@tools/defineTool';
import ToolContent from '@components/ToolContent';
import { generateQRCodeSVG } from './service';
import QRCode from 'react-qr-code';
import type { ToolComponentProps } from '@tools/defineTool';
const initialValues = {};
@ -14,39 +13,32 @@ export default function QRGeneratorTool({
longDescription
}: ToolComponentProps) {
const [input, setInput] = useState<string>('');
const [result, setResult] = useState<string>('');
const computeExternal = () => {
setResult(generateQRCodeSVG(input));
};
return (
<ToolContent
title={title}
initialValues={initialValues}
getGroups={() => []} // QR은 옵션 없이 단순 입력 → 변환
compute={computeExternal}
getGroups={() => []}
compute={() => {}} // 실제 계산 X, 바로 반영
input={input}
setInput={setInput}
inputComponent={
<ToolTextInput
title="QR에 넣을 텍스트"
title="QR 코드에 들어갈 텍스트"
value={input}
onChange={setInput}
/>
}
resultComponent={
<ToolTextResult
title="QR 코드 결과 (SVG)"
value={result}
type="html" // 결과가 SVG 문자열이라면 이렇게 설정
/>
<div className="p-4 bg-white rounded shadow inline-block">
<QRCode value={input || 'https://example.com'} size={256} />
</div>
}
toolInfo={{
title: 'QR 코드 생성기란?',
description: longDescription
}}
exampleCards={[]} // 예시 생략 가능
exampleCards={[]}
/>
);
}

View file

@ -1,17 +1,3 @@
import QRCode from 'qrcode';
/**
* QR SVG
*/
export function generateQRCodeSVG(text: string): string {
let svg = '';
QRCode.toString(
text || 'https://example.com',
{ type: 'svg' },
(err, out) => {
if (err) console.error(err);
else svg = out;
}
);
return svg;
}
export const isValidQRCodeInput = (text: string): boolean => {
return typeof text === 'string' && text.trim().length > 0;
};