Skip to content

Commit

Permalink
v1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
aeltorio committed Jun 28, 2024
1 parent 6f2b361 commit d76ea0d
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 46 deletions.
39 changes: 29 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
54 changes: 37 additions & 17 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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'
}
Expand Down Expand Up @@ -116,11 +116,14 @@ function App() {
const handleOptions = (event: React.ChangeEvent<HTMLInputElement & HTMLSelectElement>) => {
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 = ''
Expand All @@ -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)
Expand Down Expand Up @@ -201,7 +206,7 @@ function App() {
},
width: options.size,
height: options.size,
image,
image: image,
dotsOptions: {
type: options.mainShape,
color: options.shapeColor
Expand All @@ -215,7 +220,7 @@ function App() {
color: options.cornersDotColor
},
imageOptions: {
margin: options.imageMargin
margin: options.imageMargin === undefined ? 0 : options.imageMargin/10,
}
})
}, [qrCode, options])
Expand Down Expand Up @@ -322,11 +327,16 @@ function App() {
onChange={handleOptions}
>
<option value='square'>Square</option>
<option value='small-square'>Small square</option>
<option value='dots'>Dots</option>
<option value='random-dot'>Random dots</option>
<option value='rounded'>Rounded</option>
<option value='extra-rounded'>Extra rounded</option>
<option value='classy'>Classy</option>
<option value='classy-rounded'>Classy rounded</option>
<option value='vertical-line'>Vertical lines</option>
<option value='horizontal-line'>Horizontal lines</option>
<option value='diamond'>Diamond</option>
</select>
</div>
</div>
Expand Down Expand Up @@ -363,9 +373,12 @@ function App() {
value={options.squareShape}
onChange={handleOptions}
>
<option value='square'>Square</option>
<option value='dot'>Dot</option>
<option value='extra-rounded'>Extra rounded</option>
<option value={CornerSquareType.square}>Square</option>
<option value={CornerSquareType.dot}>Dot</option>
<option value={CornerSquareType.extraRounded}>Extra rounded</option>
<option value={CornerSquareType.classy}>Classy</option>
<option value={CornerSquareType.inpoint}>Inpoint</option>
<option value={CornerSquareType.outpoint}>Outpoint</option>
</select>
</div>
</div>
Expand Down Expand Up @@ -402,8 +415,13 @@ function App() {
value={options.cornersDotShape}
onChange={handleOptions}
>
<option value='square'>Square</option>
<option value='dot'>Dot</option>
<option value={CornerDotType.square}>Square</option>
<option value={CornerDotType.dot}>Dot</option>
<option value={CornerDotType.classy}>Classy</option>
<option value={CornerDotType.extraRounded}>Extra rounded</option>
<option value={CornerDotType.heart}>Heart</option>
<option value={CornerDotType.inpoint}>Inpoint</option>
<option value={CornerDotType.outpoint}>Outpoint</option>
</select>
</div>
</div>
Expand Down Expand Up @@ -464,6 +482,7 @@ function App() {
<div className='col-sm-6'>
<select
id='internalImage'
title='Internal Logo'
className='form-select'
name='image'
value={options.image}
Expand Down Expand Up @@ -506,6 +525,7 @@ function App() {
id='errorCorrectionLevel'
className='form-select'
name='errorCorrectionLevel'
title='Error Correction Level'
value={options.errorCorrectionLevel}
onChange={handleOptions}
>
Expand Down
5 changes: 3 additions & 2 deletions src/Components/Download.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React, { useCallback, useContext } from 'react'
import { AppContext } from '../Context'

import { browserUtils } from '@liquid-js/qr-code-styling'
const Download = (): JSX.Element => {
const { qrCode } = useContext(AppContext)

const handleDownload = useCallback((ext: string) => qrCode.download(ext), [qrCode])

const handleDownload = useCallback((ext: string) => browserUtils?.download(qrCode, ext as any), [qrCode])

return (
<div className='d-flex align-items-center pt-4'>
Expand Down
6 changes: 4 additions & 2 deletions src/Context.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { createContext, createRef, useEffect } from 'react'
import QRCodeStyling from 'qr-code-styling'
import {QRCodeStyling} from "@liquid-js/qr-code-styling"

const canvasRef = createRef<HTMLDivElement>()

Expand All @@ -17,7 +17,9 @@ const qrCode = new QRCodeStyling({
image: `${window.location.origin}/scanme.svg`,

imageOptions: {
crossOrigin: 'anonymous'
crossOrigin: 'anonymous',
margin: 1,
imageSize: 0.5
}
})

Expand Down
13 changes: 7 additions & 6 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React from 'react'
import ReactDOM from 'react-dom'
import ReactDOM from 'react-dom/client'
import ContextProvider from './Context'
import App from './App'
import './bootstrap.min.css'
import './App.css'

ReactDOM.render(
const container = document.getElementById('root');
if (!container) throw new Error('Container not found');
const root = ReactDOM.createRoot(container); // Créez le root avec le conteneur
root.render(
<React.StrictMode>
<ContextProvider>
<App />
</ContextProvider>
</React.StrictMode>,
document.getElementById('root')
)

</React.StrictMode>
);
19 changes: 11 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,11 @@
resolved "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.5.tgz"
integrity sha512-Vo+PSpZG2/fmgmiNzYK9qWRh8h/CHrwD0mo1h1DzL4yzHNSfWYujGTYsWGreD000gcgmZ7K4Ys6Tx9TxtsKdDw==

"@liquid-js/qr-code-styling@^3.1.1":
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==

"@nicolo-ribaudo/[email protected]":
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"
Expand Down Expand Up @@ -4795,6 +4800,11 @@ fs.realpath@^1.0.0:
resolved "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz"
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==

fsevents@^2.3.2, fsevents@~2.3.2:
version "2.3.3"
resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz"
integrity sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==

function-bind@^1.1.2:
version "1.1.2"
resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz"
Expand Down Expand Up @@ -7658,14 +7668,7 @@ q@^1.1.2:
resolved "https://registry.npmjs.org/q/-/q-1.5.1.tgz"
integrity sha512-kV/CThkXo6xyFEZUugw/+pIOywXcDbFYgSct5cT3gqlbkBE1SJdwy6UQoZvodiWF/ckQLZyDE/Bu1M6gVu5lVw==

qr-code-styling@^1.6.0-rc.1:
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"

qrcode-generator@^1.4.3:
qrcode-generator@^1.4.4:
version "1.4.4"
resolved "https://registry.npmjs.org/qrcode-generator/-/qrcode-generator-1.4.4.tgz"
integrity sha512-HM7yY8O2ilqhmULxGMpcHSF1EhJJ9yBj8gvDEuZ6M+KGJ0YY2hKpnXvRD+hZPLrDVck3ExIGhmPtSdcjC+guuw==
Expand Down

0 comments on commit d76ea0d

Please sign in to comment.