-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
218 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,52 @@ | ||
<html> | ||
|
||
<head> | ||
|
||
<title>ZXinger Demo</title> | ||
|
||
<script type="importmap"> | ||
{ | ||
"imports": { | ||
"lit": "https://cdn.jsdelivr.net/npm/lit@2/index.js", | ||
"lit/": "https://cdn.jsdelivr.net/npm/lit@2/", | ||
"@material/web/": "https://cdn.jsdelivr.net/npm/@material/[email protected]/", | ||
"@lit/reactive-element": "https://cdn.jsdelivr.net/npm/@lit/reactive-element@1/reactive-element.js", | ||
"@lit/reactive-element/": "https://cdn.jsdelivr.net/npm/@lit/reactive-element@1/", | ||
"lit-element/lit-element.js": "https://cdn.jsdelivr.net/npm/lit-element@3/lit-element.js", | ||
"lit-html": "https://cdn.jsdelivr.net/npm/lit-html@2/lit-html.js", | ||
"lit-html/": "https://cdn.jsdelivr.net/npm/lit-html@2/", | ||
"tslib": "https://cdn.jsdelivr.net/npm/tslib@2/tslib.es6.mjs" | ||
} | ||
} | ||
</script> | ||
|
||
</head> | ||
|
||
<body> | ||
|
||
<qr-code-scanner id="scanner" @change=${this.scanComplete}></qr-code-scanner> | ||
<script type="module"> | ||
import './zxinger-dialog.js' | ||
import '@material/web/button/filled-button.js' | ||
|
||
document.querySelector("#zxinger").addEventListener("change", (e) => { | ||
console.log("result:", e.detail.value) | ||
document.querySelector("#result").innerHTML = e.detail.value | ||
}) | ||
document.querySelector("#scanButton").addEventListener("click", () => document.querySelector("#zxinger").open()) | ||
|
||
</script> | ||
|
||
<xzinger-dialog id="zxinger"></xzinger-dialog> | ||
|
||
<div style="display: flex; flex-direction: column; gap: 20px; justify-content: center; align-items: center;"> | ||
<h1>ZXinger Demo</h1> | ||
<div> | ||
<span id="result"></span> | ||
</div> | ||
<div> | ||
<md-filled-button id="scanButton">Scan</md-filled-button> | ||
</div> | ||
</div> | ||
|
||
</body> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import { html, css, LitElement } from 'lit' | ||
import '@material/web/button/filled-button.js' | ||
// import '@material/web/button/outlined-button.js' | ||
// import '@material/web/button/text-button.js' | ||
// import '@material/web/iconbutton/icon-button.js' | ||
// import '@material/web/iconbutton/filled-icon-button.js' | ||
// import '@material/web/progress/circular-progress.js' | ||
// import '@material/web/progress/linear-progress.js' | ||
// import '@material/web/menu/menu.js' | ||
// import '@material/web/menu/menu-item.js' | ||
// import '@material/web/list/list.js' | ||
// import '@material/web/list/list-item.js' | ||
import '@material/web/dialog/dialog.js' | ||
import './zxinger-scanner.js' | ||
|
||
export class ZXingerDialog extends LitElement { | ||
|
||
static properties = { | ||
selectedDeviceId: { type: String }, | ||
result: { type: String }, | ||
codeReader: { type: Object }, | ||
error: { type: Object }, | ||
} | ||
|
||
static styles = [ | ||
css` | ||
.column { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
.row { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
` | ||
] | ||
|
||
constructor() { | ||
super() | ||
this.selectedDeviceId = "" | ||
this.result = "" | ||
|
||
this.error = null | ||
} | ||
|
||
connectedCallback() { | ||
super.connectedCallback() | ||
} | ||
|
||
render() { | ||
return html` | ||
<md-dialog id="dialog" @close=${this.dialogClose} @cancel=${this.dialogCancel}> | ||
<span slot="headline">Scan a code</span> | ||
<div slot="content"> | ||
<div class="column"> | ||
<div class="row"> | ||
<xzinger-scanner id="zxinger" @change=${this.changed}></zxinger-scanner> | ||
</div> | ||
<div class="row"> | ||
<pre> | ||
<code id="result"> | ||
${this.result} | ||
</code> | ||
</pre> | ||
</div> | ||
</div> | ||
</div> | ||
<div slot="actions"> | ||
<md-outlined-button type="button" @click=${this.close}>Cancel</md-outlined-button> | ||
<!-- <md-outlined-button type="button" @click=${this._choose}>Ok</md-outlined-button> --> | ||
</div> | ||
</md-dialog> | ||
` | ||
} | ||
|
||
changed(e) { | ||
console.log("changed", e.detail.value) | ||
this.result = e.detail.value | ||
this.dispatchEvent(new CustomEvent("change", { detail: { value: this.result } })) | ||
this.close() | ||
} | ||
|
||
dialogClose() { | ||
console.log('dialogClose') | ||
this.reset() | ||
} | ||
|
||
reset() { | ||
this.renderRoot.querySelector("#zxinger").close() | ||
this.result = '' | ||
} | ||
|
||
dialogCancel() { | ||
// console.log('dialogCancel') | ||
// this.reset() | ||
} | ||
|
||
firstUpdated() { | ||
super.firstUpdated() | ||
} | ||
|
||
_choose() { | ||
this.dispatchEvent(new CustomEvent("change", { detail: { result: this.result } })) | ||
this.close() | ||
} | ||
|
||
close() { | ||
// this.reset() | ||
const dialog = this.renderRoot.querySelector('#dialog') | ||
dialog.close() | ||
} | ||
|
||
async start() { | ||
|
||
let controls = this.decodeOnce(this.codeReader, this.selectedDeviceId) | ||
|
||
} | ||
|
||
|
||
async open() { | ||
const dialog = this.renderRoot.querySelector('#dialog') | ||
dialog.show() | ||
|
||
let z = this.renderRoot.querySelector("#zxinger") | ||
|
||
try { | ||
z.start() | ||
} catch (err) { | ||
console.error(err) | ||
} | ||
} | ||
|
||
} | ||
|
||
customElements.define("xzinger-dialog", ZXingerDialog) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters