├── .gitignore ├── README.md ├── img ├── barcodegenerator.png ├── barcodescanner.png └── home.png ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.css ├── App.js ├── App.test.js ├── index.css ├── index.js ├── logo.svg ├── pages │ ├── BarcodeGenerator.js │ ├── BarcodeScanner.js │ ├── Home.js │ └── Scanner.js ├── reportWebVitals.js └── setupTests.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![simplinnovation](https://1.bp.blogspot.com/-wStk0VZDfMk/YCC0GIRPrDI/AAAAAAAAAGc/1yj7IOUedvoeO1CuCxq7ETLW0FqXni6mwCLcBGAsYHQ/s320/logotext.png) 2 | 3 | # React Barcode Scanner & Generator 4 | 5 | A simple React application to generate & scan barcode. 6 | 7 | - __Demo__: 8 | 9 | Click the following picture to see the demo video: 10 | 11 | [![Video](https://img.youtube.com/vi/A0tRKgbmbIg/0.jpg)](https://youtu.be/A0tRKgbmbIg) 12 | 13 | - __Clone this repo__: 14 | 15 | ```bash 16 | $ git clone https://github.com/LintangWisesa/React-Barcode-Generator-Scanner.git 17 | $ npm i 18 | $ npm start 19 | ``` 20 | 21 | - __React UI Kit: [Material UI](https://material-ui.com/)__ 22 | 23 | Install Material UI core: 24 | ```bash 25 | $ npm i @material-ui/core @material-ui/icons 26 | ``` 27 | 28 | - __Icons: [Material Design Icons](https://materialdesignicons.com/)__ 29 | 30 | Install Material Design Icons: 31 | ```bash 32 | $ npm i @mdi/react @mdi/js @mdi/font 33 | ``` 34 | 35 | Add these lines on `./public/index.html` head: 36 | ```html 37 | 38 | 39 | 40 | 41 | ``` 42 | 43 | - __Barcode Generator: [react-barcode](https://github.com/kciter/react-barcode)__ 44 | 45 | Install `react-barcode`: 46 | ```bash 47 | $ npm i react-barcode 48 | ``` 49 | 50 | - __Barcode Scanner: [quagga](https://github.com/michaeltrollan/quaggaJS#readme)__ 51 | 52 | Install `quagga`: 53 | ```bash 54 | $ npm i quagga 55 | ``` 56 | 57 | - __Preview__ 58 | 59 | Home Page 60 | 61 | ![./img/Home.png](./img/home.png) 62 | 63 | Barcode Generator Page 64 | 65 | ![./img/QRgenerator.png](./img/barcodegenerator.png) 66 | 67 | Barcode Scanner Page 68 | 69 | ![./img/QRscanner.png](./img/barcodescanner.png) 70 | 71 |
72 | 73 | #### 🍔 Lintang Wisesa 74 | 75 |
76 | 77 | 78 | lintang ymail 79 | 80 | 81 | 82 | lintang facebook 83 | 84 | 85 | 86 | lintang twitter 87 | 88 | 89 | 90 | lintang youtube 91 | 92 | 93 | 94 | lintang linkedin 95 | 96 | 97 | 98 | lintang github 99 | 100 | 101 | 102 | lintang hackster 103 | 104 | 105 | 106 | lintang bio 107 | 108 | -------------------------------------------------------------------------------- /img/barcodegenerator.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LintangWisesa/React-Barcode-Generator-Scanner/a4cb52bdd5e0e5ec874fbde0bfe3bdd019e7a52a/img/barcodegenerator.png -------------------------------------------------------------------------------- /img/barcodescanner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LintangWisesa/React-Barcode-Generator-Scanner/a4cb52bdd5e0e5ec874fbde0bfe3bdd019e7a52a/img/barcodescanner.png -------------------------------------------------------------------------------- /img/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LintangWisesa/React-Barcode-Generator-Scanner/a4cb52bdd5e0e5ec874fbde0bfe3bdd019e7a52a/img/home.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react_barcode", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@createnextapp/react-barcode": "^1.1.1", 7 | "@material-ui/core": "^4.11.3", 8 | "@material-ui/icons": "^4.11.2", 9 | "@mdi/font": "^5.9.55", 10 | "@mdi/js": "^5.9.55", 11 | "@mdi/react": "^1.4.0", 12 | "@testing-library/jest-dom": "^5.11.4", 13 | "@testing-library/react": "^11.1.0", 14 | "@testing-library/user-event": "^12.1.10", 15 | "quagga": "^0.12.1", 16 | "react": "^17.0.1", 17 | "react-barcode": "^1.4.0", 18 | "react-dom": "^17.0.1", 19 | "react-router-dom": "^5.2.0", 20 | "react-scripts": "4.0.3", 21 | "web-vitals": "^1.0.1" 22 | }, 23 | "scripts": { 24 | "start": "react-scripts start", 25 | "build": "react-scripts build", 26 | "test": "react-scripts test", 27 | "eject": "react-scripts eject" 28 | }, 29 | "eslintConfig": { 30 | "extends": [ 31 | "react-app", 32 | "react-app/jest" 33 | ] 34 | }, 35 | "browserslist": { 36 | "production": [ 37 | ">0.2%", 38 | "not dead", 39 | "not op_mini all" 40 | ], 41 | "development": [ 42 | "last 1 chrome version", 43 | "last 1 firefox version", 44 | "last 1 safari version" 45 | ] 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LintangWisesa/React-Barcode-Generator-Scanner/a4cb52bdd5e0e5ec874fbde0bfe3bdd019e7a52a/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | 28 | 29 | React App 30 | 31 | 32 | 33 |
34 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LintangWisesa/React-Barcode-Generator-Scanner/a4cb52bdd5e0e5ec874fbde0bfe3bdd019e7a52a/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LintangWisesa/React-Barcode-Generator-Scanner/a4cb52bdd5e0e5ec874fbde0bfe3bdd019e7a52a/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #ffffff; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: rgb(0, 0, 0); 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import './App.css'; 2 | import { 3 | BrowserRouter as Router, 4 | Switch, 5 | Route, 6 | // Link 7 | } from "react-router-dom"; 8 | 9 | import Home from './pages/Home' 10 | import Bargen from './pages/BarcodeGenerator' 11 | import Barscan from './pages/BarcodeScanner' 12 | 13 | function App() { 14 | return ( 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 | export default App; 42 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root') 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/pages/BarcodeGenerator.js: -------------------------------------------------------------------------------- 1 | import React, {useState} from 'react' 2 | import {Fab, TextField, TextareaAutosize, Grid} from '@material-ui/core' 3 | import {ArrowBack, GetApp} from '@material-ui/icons' 4 | import { Link } from "react-router-dom"; 5 | // var Barcode = require('react-barcode'); 6 | import { useBarcode } from '@createnextapp/react-barcode' 7 | 8 | function BarcodeGenerator() { 9 | const [barcode, setBarcode] = useState('lintangwisesa'); 10 | const handleChange = (event) => { 11 | setBarcode(event.target.value ? event.target.value : ''); 12 | }; 13 | const { inputRef } = useBarcode({ 14 | value: barcode, 15 | options: { 16 | background: '#ffffff', 17 | } 18 | }); 19 | const downloadBarcode = () => { 20 | const canvas = document.getElementById("mybarcode"); 21 | const pngUrl = canvas 22 | .toDataURL("image/png") 23 | .replace("image/png", "image/octet-stream"); 24 | let downloadLink = document.createElement("a"); 25 | downloadLink.href = pngUrl; 26 | downloadLink.download = "mybarcode.png"; 27 | document.body.appendChild(downloadLink); 28 | downloadLink.click(); 29 | document.body.removeChild(downloadLink); 30 | }; 31 | 32 | return ( 33 |
34 | 35 | 36 | 37 | 38 | 39 | Barcode Generator 40 | 41 |
42 | 45 |
46 | 47 |
48 | { 49 | barcode !== '' 50 | ? 51 | // 69 | 70 | : 71 |

No barcode preview

72 | } 73 |
74 |
75 | { 76 | barcode ? 77 | 78 | 79 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | : 92 | '' 93 | } 94 |
95 |
96 | ); 97 | } 98 | 99 | export default BarcodeGenerator; 100 | -------------------------------------------------------------------------------- /src/pages/BarcodeScanner.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import Scanner from './Scanner' 3 | import {Fab, TextareaAutosize, Paper} from '@material-ui/core' 4 | import {ArrowBack} from '@material-ui/icons' 5 | import { Link } from "react-router-dom"; 6 | 7 | class BarcodeScanner extends Component { 8 | state = { 9 | results: [], 10 | } 11 | 12 | _scan = () => { 13 | this.setState({ scanning: !this.state.scanning }) 14 | } 15 | 16 | _onDetected = result => { 17 | this.setState({ results: [] }) 18 | this.setState({ results: this.state.results.concat([result]) }) 19 | } 20 | 21 | render() { 22 | return ( 23 |
24 | 25 | 26 | 27 | 28 | 29 | Barcode Scanner 30 | 31 | 32 | 33 | 34 | 35 | 41 | 42 |
43 | ) 44 | } 45 | } 46 | 47 | export default BarcodeScanner 48 | -------------------------------------------------------------------------------- /src/pages/Home.js: -------------------------------------------------------------------------------- 1 | import {Grid, Button, Typography} from '@material-ui/core'; 2 | import { Link } from "react-router-dom"; 3 | 4 | function Home() { 5 | 6 | return ( 7 |
8 | 9 | 10 | React Barcode 11 | 12 | 13 | 14 | 15 | 16 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 |
35 | ); 36 | } 37 | 38 | export default Home; 39 | -------------------------------------------------------------------------------- /src/pages/Scanner.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import Quagga from 'quagga' 3 | 4 | class Scanner extends Component { 5 | componentDidMount() { 6 | Quagga.init( 7 | { 8 | inputStream: { 9 | type: 'LiveStream', 10 | constraints: { 11 | width: 640, 12 | height: 320, 13 | facingMode: 'environment', 14 | }, 15 | // area: { // defines rectangle of the detection/localization area 16 | // top: "10%", // top offset 17 | // right: "10%", // right offset 18 | // left: "10%", // left offset 19 | // bottom: "10%" // bottom offset 20 | // }, 21 | }, 22 | locator: { 23 | halfSample: true, 24 | patchSize: "large", // x-small, small, medium, large, x-large 25 | debug: { 26 | showCanvas: true, 27 | showPatches: false, 28 | showFoundPatches: false, 29 | showSkeleton: false, 30 | showLabels: false, 31 | showPatchLabels: false, 32 | showRemainingPatchLabels: false, 33 | boxFromPatches: { 34 | showTransformed: true, 35 | showTransformedBox: true, 36 | showBB: true 37 | } 38 | } 39 | }, 40 | numOfWorkers: 4, 41 | decoder: { 42 | readers: ['code_128_reader'], 43 | debug: { 44 | drawBoundingBox: true, 45 | showFrequency: true, 46 | drawScanline: true, 47 | showPattern: true 48 | }, 49 | }, 50 | locate: true, 51 | }, 52 | function(err) { 53 | if (err) { 54 | return console.log(err) 55 | } 56 | Quagga.start() 57 | }, 58 | ) 59 | Quagga.onDetected(this._onDetected) 60 | } 61 | 62 | componentWillUnmount() { 63 | Quagga.offDetected(this._onDetected) 64 | } 65 | 66 | _onDetected = result => { 67 | this.props.onDetected(result) 68 | } 69 | 70 | render() { 71 | return
72 | } 73 | } 74 | 75 | export default Scanner 76 | -------------------------------------------------------------------------------- /src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | --------------------------------------------------------------------------------