Skip to content

Commit d97ceaa

Browse files
added qr code generator project
1 parent ec021c9 commit d97ceaa

File tree

4 files changed

+122
-0
lines changed

4 files changed

+122
-0
lines changed

App.jsx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import React from 'react'
2+
import './index.css'
3+
4+
import { useState } from 'react'
5+
6+
const App = () => {
7+
const[img,setimg]=useState("");
8+
const[loading,setloading]=useState(false)
9+
const[data,setdata]=useState("");
10+
const[size,setsize]=useState(200);
11+
function downlode(){
12+
fetch(img).then((response)=>response.blob()).then((blob)=>{
13+
const link=document.createElement('a');
14+
link.href=URL.createObjectURL(blob);
15+
link.download="qrcode.png";
16+
document.body.appendChild(link);
17+
link.click();
18+
document.body.removeChild(link);
19+
})
20+
}
21+
async function generateQr(){
22+
23+
setloading(true);
24+
try {
25+
setimg(encodeURI(`https://api.qrserver.com/v1/create-qr-code/?size=${size}x${size}&data=${data}`))
26+
} catch (error) {
27+
console.error("Error in generating qr code");
28+
29+
}
30+
finally{
31+
setloading(false)
32+
}
33+
34+
}
35+
return (
36+
<>
37+
<div id="container">
38+
{loading && <h1>Please wait ...</h1>}
39+
{img && <img src={img} alt="Qr code" />}
40+
<h1>Data for the Qr code</h1>
41+
<input type="text" placeholder='Enter your content to generate Qr' autoFocus onChange={(e)=>{setdata(e.target.value)}}/>
42+
<h1>size of the Qr code</h1>
43+
<input type="text" placeholder='Enter the size of the QrCode'autoFocus onChange={(e)=>{setsize(e.target.value);console.log(e.target.value)}}/><br />
44+
<button className='generate' onClick={generateQr} disabled={loading}>GENERATE </button>
45+
<button className='downlode' onClick={downlode}>DOWNLODE</button>
46+
47+
<p>&#9400; Designed by BoobeshKumar</p>
48+
49+
</div>
50+
</>
51+
)
52+
}
53+
54+
export default App

index.css

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
*{
2+
font-family: 'Courier New', Courier, monospace;
3+
}
4+
#container{
5+
width:600px;
6+
height:700px;
7+
max-height: max-content;
8+
margin:auto;
9+
border:auto solid black;
10+
text-align: center;
11+
border-radius: 20px;
12+
}
13+
input{
14+
15+
width:450px;
16+
height:40px;
17+
border-radius: 10px;
18+
border:1px solid black;
19+
font-family: 'Courier New', Courier, monospace;
20+
font-size: large;
21+
text-align: center;
22+
}
23+
24+
img{
25+
26+
margin-top:30px;
27+
border: 3px solid black;
28+
}
29+
button{
30+
margin:60px 0px 0 0;
31+
width:200px;
32+
height:50px;
33+
border-radius: 10px;
34+
letter-spacing: 2px;
35+
36+
}
37+
.generate{
38+
color:white;
39+
background-color: rgba(10, 177, 10, 0.712);
40+
border:2px solid green
41+
}
42+
.downlode{
43+
margin-left: 100px;
44+
color:white;
45+
background-color: rgb(16, 16, 121);
46+
border:2px solid rgb(70, 22, 202);
47+
48+
}
49+
input:focus{
50+
border-color:seagreen;
51+
background-color: aliceblue;
52+
color:black
53+
54+
}
55+
p{
56+
margin-top:70px;
57+
}

main.jsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { StrictMode } from 'react'
2+
import { createRoot } from 'react-dom/client'
3+
import App from './App.jsx'
4+
5+
6+
createRoot(document.getElementById('root')).render(
7+
<StrictMode>
8+
<App />
9+
</StrictMode>,
10+
)

react.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)