Skip to content

Barcode QRcode #16015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
May 16, 2025
Merged

Barcode QRcode #16015

merged 18 commits into from
May 16, 2025

Conversation

mikesealey
Copy link
Collaborator

Description

This PR adds a new component to display QR Codes and Barcodes based on the value passed. This could be a static value, or one passed in using bindings/JS.

image

This component also has options such as "Display Value"
image

And also "Show logo"
image

QR Codes can also select their primary color
image

Barcode/QR Code Generators can also be used in repeaters
image

Barcode/QR Code Generator in PDF screens
image

Addresses

  • <Enter the Link to the issue(s) this PR addresses>
  • ...more if required

App Export

Barcode Gen-export-1745587460313.tar.gz

Screenshots

If a UI facing feature, a short video of the happy path, and some screenshots of the new functionality.

Launchcontrol

Adds Barcode/QR Code generator.

Copy link

qa-wolf bot commented Apr 25, 2025

QA Wolf here! As you write new code it's important that your test coverage is keeping up.
Click here to request test coverage for this PR!

@mikesealey mikesealey marked this pull request as ready for review April 25, 2025 14:12
@@ -35,7 +35,10 @@
"sanitize-html": "^2.13.0",
"screenfull": "^6.0.1",
"shortid": "^2.2.15",
"svelte-spa-router": "^4.0.1"
"svelte-spa-router": "^4.0.1",
"atrament": "^4.3.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

atrament doesn't seem to be used, so can be removed.

import { onMount, afterUpdate } from "svelte"
import JsBarcode from "jsbarcode"
import { createQrSvgString } from "@svelte-put/qr"
import "@spectrum-css/vars/dist/spectrum-global.css"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need to manually import spectrum CSS - the client library already does this.

export let customLogo: string
export let size: number
export let primColor: string
export let vertical: boolean
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of these settings are required in the manifest, so the types should account for the fact they may be undefined. The boolean settings are fine as long as you have defaultValue in the manifest (which you do). But for the strings and number setting you'll need to type those as string | undefined and handle that as needed.

</div>
{:else}
<div id="barcode-container">
<div id="logo-and-barcode" style="height: {size}px, width: 100%">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see that you're using quite a lot of ids here. You should never use the same ID more than once on a page, but adding multiple of this component will create multiple elements with the same ID.

The 2 options here are:

  • Generate a unique ID for each instance of the component. This is harder to style because you'll need to get this ID into your styles section, so I don't recomment this approach.
  • Don't use ID attributes at all. You can style elements using classes, and you can get the reference to your DOM element for jsbarcode by using binding, like you do with the qrContainer. I checked the source and it looks like it supports passing a DOM element in as the parameter instead of a string selector.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched the way in which the barcode element is created, meaning it no long requires an element-ID to target. The rest of the IDs have been replaced.

generateBarcode()
} else {
generateQr()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you just double check that this can't cause an endless loop? afterUpdate fires after any component DOM update, and you're mutating the DOM inside the callback, which smells a little risky. I'd also just double check that this does properly react to all settings changes as expected - e.g. try changing all of these props at runtime and check the component redraws the barcode as expected without needing a page refresh.

Basically if you could just add a console log or something, and ensure it's not constantly firing! And just check both barcode and QR code to be sure.

The usual way to handle this would be doing a (rather large) reactive statement and passing in all the required props that we'd want to observe and re-render the barcode when they change, but this is fine too as long as it doesn't cause too many wasted invocation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was an interesting one - updating a setting triggered off a handful of console.logs()

@mikesealey mikesealey requested a review from aptkingston May 8, 2025 15:55
@github-actions github-actions bot added the stale label May 15, 2025
Copy link
Member

@aptkingston aptkingston left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work addressing that feedback 👌 LGTM!

@github-actions github-actions bot removed the stale label May 15, 2025
@mikesealey mikesealey merged commit 0148f84 into master May 16, 2025
22 checks passed
@mikesealey mikesealey deleted the barcode-qrcode branch May 16, 2025 10:11
@github-actions github-actions bot locked and limited conversation to collaborators May 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants