-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #234 from Saimanjari777/qr-code
QR Code Generator
- Loading branch information
Showing
11 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
React-JS-Projects/Advanced/Qr-Code-Generator/.eslintrc.cjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module.exports = { | ||
root: true, | ||
env: { browser: true, es2020: true }, | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:react/recommended', | ||
'plugin:react/jsx-runtime', | ||
'plugin:react-hooks/recommended', | ||
], | ||
ignorePatterns: ['dist', '.eslintrc.cjs'], | ||
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' }, | ||
settings: { react: { version: '18.2' } }, | ||
plugins: ['react-refresh'], | ||
rules: { | ||
'react/jsx-no-target-blank': 'off', | ||
'react-refresh/only-export-components': [ | ||
'warn', | ||
{ allowConstantExport: true }, | ||
], | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<h1 align='center'><b>💥 QR CODE GENERATOR 💥</b></h1> | ||
|
||
<!-- -------------------------------------------------------------------------------------------------------------- --> | ||
|
||
<h3 align='center'>Tech Stack Used 🎮</h3> | ||
<!-- enlist all the technologies used to create this project from them (Remove comment using 'ctrl+z' or 'command+z') --> | ||
|
||
<div align='center'> | ||
|
||
 | ||
 | ||
 | ||
 | ||
</div> | ||
|
||
|
||
 | ||
|
||
<!-- -------------------------------------------------------------------------------------------------------------- --> | ||
|
||
## :zap: Description 📃 | ||
|
||
<div> | ||
<!-- <p>Add Description of the project</p> --> | ||
<p>This project is a react.js project that generates QR code which can be downloaded when an URL of a website is entered.</p> | ||
</div> | ||
|
||
|
||
<!-- -------------------------------------------------------------------------------------------------------------- --> | ||
|
||
## :zap: How to run it? 🕹️ | ||
|
||
<!-- Add steps how to run this project --> | ||
To run this project locally, follow these steps: | ||
|
||
1. Fork the repository. | ||
|
||
2. Clone the repository to your local computer: | ||
git clone https://github.com/your-username/Qr-Code-Generator-Clone.git | ||
|
||
3. Open the project folder in your preferred code editor, now you can view website in live. | ||
|
||
|
||
|
||
<!-- -------------------------------------------------------------------------------------------------------------- --> | ||
|
||
## :zap: Screenshots 📸 | ||
<!-- add the screenshot of the project (Mandatory) --> | ||
|
||
<img src='./screenshot.webp'> | ||
|
||
|
||
 | ||
|
||
<!-- -------------------------------------------------------------------------------------------------------------- --> | ||
|
||
<h4 align='center'>Developed By <b><i>Sai Manjari</i></b> 👧</h4> | ||
<p align='center'> | ||
<a href='https://www.linkedin.com/in/saimanjari777/'> | ||
<img src='https://img.shields.io/badge/linkedin-%230077B5.svg?style=for-the-badge&logo=linkedin&logoColor=white' /> | ||
</a> | ||
<a href='https://github.com/Saimanjari777'> | ||
<img src='https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white' /> | ||
</a> | ||
</p> | ||
|
||
<h4 align='center'>Happy Coding 🧑💻</h4> | ||
|
||
<h3 align="center">Show some ❤️ by 🌟 this repository!</h3> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + React</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.jsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"name": "qr-code-generator", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.2.66", | ||
"@types/react-dom": "^18.2.22", | ||
"@vitejs/plugin-react": "^4.2.1", | ||
"eslint": "^8.57.0", | ||
"eslint-plugin-react": "^7.34.1", | ||
"eslint-plugin-react-hooks": "^4.6.0", | ||
"eslint-plugin-react-refresh": "^0.4.6", | ||
"vite": "^5.2.0" | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
@import url('http://fonts.cdnfonts.com/css/lilly'); | ||
.App{ | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
gap: 50px; | ||
padding-top: 30px; | ||
|
||
} | ||
h1{ | ||
font-family: 'Lilly', sans-serif; | ||
font-size: 50px; | ||
} | ||
.gen input{ | ||
height: 35px; | ||
width: 350px; | ||
font-size: 20px; | ||
padding-left: 5px; | ||
} | ||
button{ | ||
position: relative; | ||
height: 38px; | ||
width: 100px; | ||
top: -2px; | ||
font-size: 18px; | ||
margin-left: 10px; | ||
border: none; | ||
color: whitesmoke; | ||
background-color: forestgreen; | ||
box-shadow: 2px 2px 5px rgb(74, 182, 74); | ||
cursor: pointer; | ||
} | ||
button:active{ | ||
box-shadow: none; | ||
} | ||
.extra{ | ||
padding-top: 20px; | ||
display: flex; | ||
justify-content: space-around; | ||
gap: 10px; | ||
} | ||
input[type="color"]{ | ||
margin-top: 20px; | ||
} | ||
h5{ | ||
font-size: 1rem; | ||
} | ||
.output-box{ | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
gap: 40px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
|
||
import { useEffect, useState } from 'react'; | ||
import './App.css'; | ||
|
||
function App() { | ||
const [temp, setTemp] = useState(""); | ||
const [url, setUrl] = useState(""); | ||
const [size, setSize] = useState(250); | ||
const [bgColor, setBgColor] = useState("ffffff"); | ||
const [qrCode, setQrCode] = useState(""); | ||
const [showDownloadButton, setShowDownloadButton] = useState(false); | ||
|
||
// Changing the URL only when the user | ||
// changes the input | ||
useEffect(() => { | ||
setQrCode(`http://api.qrserver.com/v1/create-qr-code/?data=${encodeURIComponent(url)}&size=${size}x${size}&bgcolor=${bgColor}`); | ||
}, [url, size, bgColor]); | ||
|
||
// Function to handle input change and validate URL | ||
function handleInputChange(event) { | ||
setTemp(event.target.value); | ||
} | ||
|
||
// Function to handle URL submission | ||
function handleSubmit(event) { | ||
event.preventDefault(); | ||
if (isValidUrl(temp)) { | ||
setUrl(temp); | ||
setShowDownloadButton(true); // Show the download button | ||
} else { | ||
alert("Invalid URL. Please enter a valid URL."); | ||
} | ||
} | ||
|
||
// Function to check if a string is a valid URL | ||
function isValidUrl(string) { | ||
try { | ||
new URL(string); | ||
return true; | ||
} catch (_) { | ||
return false; | ||
} | ||
} | ||
|
||
// Function to handle QR code download | ||
function handleDownload() { | ||
const downloadLink = document.createElement('a'); | ||
downloadLink.href = qrCode; | ||
downloadLink.download = 'qrcode.png'; | ||
document.body.appendChild(downloadLink); | ||
downloadLink.click(); | ||
document.body.removeChild(downloadLink); | ||
} | ||
|
||
return ( | ||
<div className="App"> | ||
<h1>QR Code Generator</h1> | ||
<form onSubmit={handleSubmit}> | ||
<div className="input-box"> | ||
<div className="gen"> | ||
<input | ||
type="text" | ||
value={temp} | ||
onChange={handleInputChange} | ||
placeholder="Enter URL to encode" | ||
/> | ||
<button type="submit" className="button">Generate</button> | ||
</div> | ||
<div className="extra"> | ||
<h5>Background Color:</h5> | ||
<input | ||
type="color" | ||
onChange={(e) => { setBgColor(e.target.value.substring(1)) }} | ||
/> | ||
<h5>Dimension:</h5> | ||
<input | ||
type="range" | ||
min="200" | ||
max="600" | ||
value={size} | ||
onChange={(e) => { setSize(e.target.value) }} | ||
/> | ||
</div> | ||
</div> | ||
</form> | ||
<div className="output-box"> | ||
<img src={qrCode} alt="" /> | ||
{showDownloadButton && qrCode && ( // Conditionally render the download button | ||
<button onClick={handleDownload}>Download</button> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom/client' | ||
import App from './App.jsx' | ||
|
||
ReactDOM.createRoot(document.getElementById('root')).render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode>, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { defineConfig } from 'vite' | ||
import react from '@vitejs/plugin-react' | ||
|
||
// https://vitejs.dev/config/ | ||
export default defineConfig({ | ||
plugins: [react()], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters