-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qr-code.js
59 lines (50 loc) · 1.51 KB
/
qr-code.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { html, LitElement } from 'lit'
import QRious from 'https://cdn.jsdelivr.net/npm/qrious@4/+esm'
export class QrCode extends LitElement {
static properties = {
value: { type: String }, // value for QR code
size: { type: Number }, // size of QR code
error: { type: Object },
}
constructor() {
super()
this.value = ''
this.size = 128
this.error = null
}
async connectedCallback() {
super.connectedCallback()
}
attributeChangedCallback(name, oldValue, newValue) {
super.attributeChangedCallback(name, oldValue, newValue)
// console.log("qr-code.js: ATTR CHANGED:", name, oldValue, newValue)
}
firstUpdated() {
super.firstUpdated()
var canvas = this.renderRoot.querySelector('#qr')
// console.log("canvas:", canvas)
// console.log(this.value)
// https://github.com/neocotic/qrious#readme
var qr = new QRious({
element: canvas,
value: this.value,
// background: '#303030',// '#01368d',
// backgroundAlpha: 0.5,
foreground: '#4361ee',
size: this.size,
})
}
async getUpdateComplete() {
await super.getUpdateComplete();
return true
}
render() {
if (this.error) {
return html`<div class="error">${this.error}</div>`
}
return html`
<canvas id="qr"></canvas>
`
}
}
customElements.define('qr-code', QrCode)