-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathContentbox.jsx
More file actions
155 lines (135 loc) · 5.31 KB
/
Copy pathContentbox.jsx
File metadata and controls
155 lines (135 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import React,{useState,useEffect} from "react";
import "./Contentbox.css";
const Contentbox = () => {
const [textval,setTeextValue]=useState(null);
const [qrData,setQrData]=useState(``);
const [qrSize,setQrSize]=useState(`200`);
const [margin,setMargin]=useState(null);
const [qzone,setQzone]=useState(null);
const [qrColor,setQrColor]=useState('#000000');
const [qrBgColor,setQrBgColor]=useState('#ffffff');
const [formatType,setFormatType]=useState('png');
const handleDownload = (format) => {
if(formatType=="png")
setFormatType("png")
else if(formatType=="jpeg")
setFormatType("jpeg")
const downloadLink = document.createElement("a");
downloadLink.href = qrData;
downloadLink.download = `qrcode.${format}`;
downloadLink.style.display = "none";
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
};
useEffect(()=>{
if(textval==null || textval=="")
setQrData(`https://api.qrserver.com/v1/create-qr-code/?size=${qrSize}x${qrSize}&margin=${margin}&color=${qrColor.slice(1)}&bgcolor=${qrBgColor.slice(1)}&format=${formatType}&data=Welcome To QRBuilder`)
else
setQrData(`https://api.qrserver.com/v1/create-qr-code/?size=${qrSize}&margin=${margin}&color=${qrColor.slice(1)}&bgcolor=${qrBgColor.slice(1)}&format=${formatType}&data=${textval}`)
},[textval,qrSize,margin,qrColor,qrBgColor])
return (
<>
<section className="contentbox">
<div className="mainbox bg-[#ecf7ff] dark:bg-neutral-950 from-neutral-950 to-[#0F172A]">
<div className="sliderbox">
<img
width="48"
height="48"
src="https://img.icons8.com/fluency/48/link.png"
alt="link"
/>
<img
width="48"
height="48"
src="https://img.icons8.com/fluency/48/text.png"
alt="text"
/>
<img
width="48"
height="48"
src="https://img.icons8.com/fluency/48/new-post.png"
alt="new-post"
/>
<img
width="64"
height="64"
src="https://img.icons8.com/arcade/64/bitcoin.png"
alt="bitcoin"
/>
<img
width="48"
height="48"
src="https://img.icons8.com/color/48/speech-bubble-with-dots.png"
alt="speech-bubble-with-dots"
/>
<img
width="94"
height="94"
src="https://img.icons8.com/3d-fluency/94/document.png"
alt="document"
/>
<img width="94" height="94" src="https://img.icons8.com/3d-fluency/94/contacts.png" alt="contacts"/>
<img
width="48"
height="48"
src="https://img.icons8.com/color/48/ellipsis.png"
alt="ellipsis"
/>
</div>
<div className="textbox">
<textarea id='userInput' type="text" placeholder="Enter Text Here" onChange={(e)=>{setTeextValue(e.target.value)}} value={textval} />
<h1 className="dark:text-white">Your QR Code will be generated automatically </h1>
</div>
<div className="displaybox">
<div className="qrbox">
<img src={qrData} className="qrimg" alt="QR" />
</div>
<div className="qrsettings ">
<div className="dimension">
<h1> Height X width</h1>
<input type="number" name="size" id="size" placeholder="Enter dimension" value={qrSize} onChange={(e)=>{setQrSize(e.target.value)}}/>
<p>Your Dimension : {qrSize}x{qrSize}</p>
</div>
<h1>Color</h1>
<input type="color" name="color" id="color" placeholder="Enter QR Color" value={qrColor} onChange={(e)=>{setQrColor(e.target.value)}} />
<h1>Backgroung Color</h1>
<input type="color" name="bgcolor" id="bgcolor" placeholder="Enter Background color" value={qrBgColor} onChange={(e)=>{setQrBgColor(e.target.value)}}/>
<h1>Margin</h1>
<input type="number" name="margin" id="marginval" placeholder="Enter Margin Value" value={margin} onChange={(e)=>{ setMargin(e.target.value)}} />
<h1>QZone</h1>
<input type="number" name="qrzone" id="qrzone" placeholder="Enter qrzone value" value={qzone} onChange={(e)=>{ setQzone(e.target.value)}}/>
</div>
<div className="qrbuttons">
<button
className="qrbutton"
onClick={() => handleDownload("png")}
>
<img
width="48"
height="48"
src="https://img.icons8.com/fluency/48/download.png"
alt="download"
/>
PNG
</button>
<button
className="qrbutton"
onClick={() => handleDownload("jpeg")}
>
<img
width="48"
height="48"
src="https://img.icons8.com/fluency/48/download.png"
alt="download"
/>
JPEG
</button>
</div>
</div>
</div>
</section>
</>
);
};
export default Contentbox;