From d76ea0d2f7d6283a13e24bc67c64aae0776373aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=A6Ltorio?= Date: Fri, 28 Jun 2024 20:19:34 +0200 Subject: [PATCH] v1.5 --- package-lock.json | 39 ++++++++++++++++++++------- package.json | 2 +- src/App.tsx | 54 +++++++++++++++++++++++++------------ src/Components/Download.tsx | 5 ++-- src/Context.tsx | 6 +++-- src/index.tsx | 13 ++++----- yarn.lock | 19 +++++++------ 7 files changed, 92 insertions(+), 46 deletions(-) diff --git a/package-lock.json b/package-lock.json index 30f3ba6..35d9a72 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,7 +8,7 @@ "name": "custom-qr-code-styling", "version": "0.2.0", "dependencies": { - "qr-code-styling": "^1.6.0-rc.1", + "@liquid-js/qr-code-styling": "^3.1.1", "react": "^18.3.1", "react-dom": "^18.3.1", "react-scripts": "5.0.1", @@ -3205,6 +3205,31 @@ "resolved": "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.5.tgz", "integrity": "sha512-Vo+PSpZG2/fmgmiNzYK9qWRh8h/CHrwD0mo1h1DzL4yzHNSfWYujGTYsWGreD000gcgmZ7K4Ys6Tx9TxtsKdDw==" }, + "node_modules/@liquid-js/qr-code-styling": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@liquid-js/qr-code-styling/-/qr-code-styling-3.1.1.tgz", + "integrity": "sha512-tl11pz53jMisrcRgXSOAcTH4WW+pc3u0qG4+SDE8mCVw6gP0gSEpIJSPQcK+tX6q/8w7U+bCe+Kqdewt8dkjAw==", + "peerDependencies": { + "@xmldom/xmldom": "^0.8.10", + "file-type": "^19.0.0", + "qrcode-generator": "^1.4.4", + "sharp": ">0.32.1 <1.0.0" + }, + "peerDependenciesMeta": { + "@xmldom/xmldom": { + "optional": true + }, + "file-type": { + "optional": true + }, + "qrcode-generator": { + "optional": true + }, + "sharp": { + "optional": true + } + } + }, "node_modules/@nicolo-ribaudo/eslint-scope-5-internals": { "version": "5.1.1-v1", "resolved": "https://registry.npmjs.org/@nicolo-ribaudo/eslint-scope-5-internals/-/eslint-scope-5-internals-5.1.1-v1.tgz", @@ -14065,18 +14090,12 @@ "teleport": ">=0.2.0" } }, - "node_modules/qr-code-styling": { - "version": "1.6.0-rc.1", - "resolved": "https://registry.npmjs.org/qr-code-styling/-/qr-code-styling-1.6.0-rc.1.tgz", - "integrity": "sha512-ModRIiW6oUnsP18QzrRYZSc/CFKFKIdj7pUs57AEVH20ajlglRpN3HukjHk0UbNMTlKGuaYl7Gt6/O5Gg2NU2Q==", - "dependencies": { - "qrcode-generator": "^1.4.3" - } - }, "node_modules/qrcode-generator": { "version": "1.4.4", "resolved": "https://registry.npmjs.org/qrcode-generator/-/qrcode-generator-1.4.4.tgz", - "integrity": "sha512-HM7yY8O2ilqhmULxGMpcHSF1EhJJ9yBj8gvDEuZ6M+KGJ0YY2hKpnXvRD+hZPLrDVck3ExIGhmPtSdcjC+guuw==" + "integrity": "sha512-HM7yY8O2ilqhmULxGMpcHSF1EhJJ9yBj8gvDEuZ6M+KGJ0YY2hKpnXvRD+hZPLrDVck3ExIGhmPtSdcjC+guuw==", + "optional": true, + "peer": true }, "node_modules/qs": { "version": "6.11.0", diff --git a/package.json b/package.json index 255d37d..97a060f 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.2.0", "private": false, "dependencies": { - "qr-code-styling": "^1.6.0-rc.1", + "@liquid-js/qr-code-styling":"^3.1.1", "react": "^18.3.1", "react-dom": "^18.3.1", "react-scripts": "5.0.1", diff --git a/src/App.tsx b/src/App.tsx index c5f05e6..e2cc43f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,6 @@ /* eslint-disable jsx-a11y/label-has-associated-control */ import React, { useState, useEffect, useRef, useContext, useReducer } from 'react' -import { DotType, CornerSquareType, CornerDotType } from 'qr-code-styling' +import { DotType, CornerSquareType, CornerDotType } from "@liquid-js/qr-code-styling" import { AppContext } from './Context' import Header from './Components/Header' import Tabs from './Components/Tabs' @@ -69,11 +69,11 @@ const initialOptions: Options = { removeBrand: false, image: defaultBrand, imageMargin: 10, - mainShape: 'dots', + mainShape: DotType.dot, shapeColor: '#1E2470', - squareShape: 'extra-rounded', + squareShape: CornerSquareType.extraRounded, squareColor: '#008ADC', - cornersDotShape: 'dot', + cornersDotShape: CornerDotType.dot, cornersDotColor: '#D90012', errorCorrectionLevel: 'H' } @@ -116,11 +116,14 @@ function App() { const handleOptions = (event: React.ChangeEvent) => { const { type, name, value, checked, files } = event.target - setOptions((prev) => ({ - ...prev, - [name]: type === 'checkbox' ? checked : value - })) - if (!files) return + + if (!files) { + setOptions((prev) => ({ + ...prev, + [name]: type === 'checkbox' ? checked : value + })) + return + } const image = files[0] uploadError.current = '' @@ -145,9 +148,11 @@ function App() { } fileReader.onload = () => { + const image = fileReader.result as string + setOptions((prev) => ({ ...prev, - image: fileReader.result as string + image: image })) } fileReader.readAsDataURL(image) @@ -201,7 +206,7 @@ function App() { }, width: options.size, height: options.size, - image, + image: image, dotsOptions: { type: options.mainShape, color: options.shapeColor @@ -215,7 +220,7 @@ function App() { color: options.cornersDotColor }, imageOptions: { - margin: options.imageMargin + margin: options.imageMargin === undefined ? 0 : options.imageMargin/10, } }) }, [qrCode, options]) @@ -322,11 +327,16 @@ function App() { onChange={handleOptions} > + + + + + @@ -363,9 +373,12 @@ function App() { value={options.squareShape} onChange={handleOptions} > - - - + + + + + + @@ -402,8 +415,13 @@ function App() { value={options.cornersDotShape} onChange={handleOptions} > - - + + + + + + + @@ -464,6 +482,7 @@ function App() {