From 4268dc204cd402abb5f607fb44d343f3afe7bc1a Mon Sep 17 00:00:00 2001 From: thomasrosen Date: Mon, 19 Jul 2021 21:35:52 +0200 Subject: [PATCH] added transparent background option --- src/locales/de.ftl | 1 + src/locales/en.ftl | 1 + src/pages/Generator.js | 28 +++++++++++++++++++++------- src/pages/Generator.module.css | 6 ++++++ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/locales/de.ftl b/src/locales/de.ftl index ccfbb7a..c2a4b42 100644 --- a/src/locales/de.ftl +++ b/src/locales/de.ftl @@ -20,6 +20,7 @@ yellow = Gelb green = GrĂ¼n blue = Blau red = Rot +transparent = Transparent display_logo_headline = Logo Wassermarke label_display_logo_yes = Ja diff --git a/src/locales/en.ftl b/src/locales/en.ftl index 805969d..0a18322 100644 --- a/src/locales/en.ftl +++ b/src/locales/en.ftl @@ -20,6 +20,7 @@ yellow = Yellow green = Green blue = Blue red = Red +transparent = Transparent display_logo_headline = Display Logo label_display_logo_yes = Yes diff --git a/src/pages/Generator.js b/src/pages/Generator.js index 83a89f9..6b78222 100644 --- a/src/pages/Generator.js +++ b/src/pages/Generator.js @@ -47,6 +47,7 @@ const colors = { 'green': '#1BBE6F', 'blue': '#82D0F4', 'red': '#E63E12', + 'transparent': 'transparent', } function generate_qr_code({ content, size, errorCorrectionLevel, backgroundColor, foregroundColor, displayLogo }) { @@ -119,7 +120,7 @@ function generate_qr_code({ content, size, errorCorrectionLevel, backgroundColor } } - if (this_foregroundColor !== 'white') { + if (this_foregroundColor !== 'white' && this_backgroundColor !== 'transparent') { this_backgroundColor = 'white' } @@ -183,7 +184,7 @@ function Generator({ getString }) { const [qrcode, setQrcode] = useState(null) const [qrcodeWorks, setQrcodeWorks] = useState(null) - const [backgroundColor, setBackgroundColor] = useState('purple') + const [backgroundColor, setBackgroundColor] = useState('white') const [foregroundColor, setForegroundColor] = useState('purple') const [displayLogo, setDisplayLogo] = useState('yes') @@ -212,13 +213,22 @@ function Generator({ getString }) { }, [setContent]) useEffect(() => { + let backgroundColor_to_use = backgroundColor + if (backgroundColor_to_use === 'transparent') { + if (foregroundColor === 'white') { + backgroundColor_to_use = 'black' + } else { + backgroundColor_to_use = 'white' + } + } + async function checkQrcode(displayLogo, min_error_correction_level) { const errorCorrectionLevel = errorCorrectionLevels[min_error_correction_level] const { qrcode_svg, realCanvasSize } = generate_qr_code({ content, size: 1000, errorCorrectionLevel, - backgroundColor, + backgroundColor: backgroundColor_to_use, foregroundColor, displayLogo, }) @@ -349,11 +359,11 @@ function Generator({ getString }) { title: getString(color) })) - let background_colors = ['purple', 'white', 'black'] // 'yellow', 'green', 'red', 'blue' + let background_colors = ['purple', 'white', 'black', 'transparent'] // 'yellow', 'green', 'red', 'blue' if (foregroundColor !== 'white') { - background_colors = ['white'] + background_colors = ['white', 'transparent'] } else if (foregroundColor === 'white') { - background_colors = ['purple', 'black'] // 'yellow', 'green', 'blue', 'red', + background_colors = ['purple', 'black', 'transparent'] // 'yellow', 'green', 'blue', 'red', } background_colors = background_colors.map(color => ({ value: color, @@ -499,8 +509,12 @@ function Generator({ getString }) {

- + { + backgroundColor === 'transparent' + ? null + : + } :

) diff --git a/src/pages/Generator.module.css b/src/pages/Generator.module.css index 0315cc7..7f1dedf 100644 --- a/src/pages/Generator.module.css +++ b/src/pages/Generator.module.css @@ -18,6 +18,12 @@ width: 320px; max-width: 100%; display: block; + + font-size: 0; + + background-position: 0px 0px, 8px 8px; + background-size: 16px 16px; + background-image: linear-gradient(45deg, #ccc 25%, transparent 25%, transparent 75%, #ccc 75%, #ccc 100%), linear-gradient(45deg, #ccc 25%, white 25%, white 75%, #ccc 75%, #ccc 100%); } .qrCodeSvgWrapper svg{ max-width: 100%;