feat(barcode reader): add wrapper for the webcomponent

This commit is contained in:
2026-01-17 18:54:36 -03:00
parent ead327d44f
commit 4655ba4f64
4 changed files with 58 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
<barcode-reader
#reader
(result)="this.result.emit($event)"
(scan-status)="this.scanStatus.emit($event)"
(scan-permission-denied)="this.scanPermissionDenied.emit()"
/>

View File

@@ -0,0 +1,6 @@
barcode-reader {
display: block;
width: 100%;
position: absolute;
top: 0;
}

View File

@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { BarCodeReaderWrapper } from './bar-code-reader';
describe('BarCodeReaderWrapper', () => {
let component: BarCodeReaderWrapper;
let fixture: ComponentFixture<BarCodeReaderWrapper>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [BarCodeReaderWrapper]
})
.compileComponents();
fixture = TestBed.createComponent(BarCodeReaderWrapper);
component = fixture.componentInstance;
await fixture.whenStable();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@@ -0,0 +1,23 @@
import { Component, CUSTOM_ELEMENTS_SCHEMA, effect, ElementRef, input, output, signal, viewChild } from '@angular/core';
import { DetectedBarcode } from '../../types/globalThis';
import { BarcodeReader } from '../../web-components/barcode-reader';
@Component({
selector: 'app-bar-code-reader',
templateUrl: './bar-code-reader.html',
styleUrl: './bar-code-reader.scss',
schemas: [CUSTOM_ELEMENTS_SCHEMA],
})
export class BarCodeReaderWrapper {
private readonly ref = viewChild<ElementRef<BarcodeReader>>('reader');
protected readonly result = output<Event & {detail?: {code: DetectedBarcode | null}}>();
protected readonly scanStatus = output<Event & {detail?: {state: ScanState}}>();
protected readonly scanPermissionDenied = output();
scan = input({scan: false})
constructor() {
effect(() => this.scan().scan && this.ref()?.nativeElement.scan())
}
}
export type ScanState = 'loading'|'started'|'stopped';