@scandit/web-datacapture-barcode
Version:
Scandit Data Capture SDK for the Web
1 lines • 1.59 kB
JavaScript
import{sparkScanViewToastTag as e}from"./constants/tags.js";import{ScanditHTMLElement as t,Timeout as n,css as r,defineCustomElements as i,html as a}from"@scandit/web-datacapture-core/build/js/private/utils/index.js";var o=class o extends t{get styleElement(){return this._styleElement??=r`${e}{min-width:calc(100% - 32px);opacity:0;pointer-events:none;transition:.3s ease;user-select:none;width:fit-content}${e}[visible]{opacity:1}.${e}{border-radius:4px;font-family:sans-serif;font-size:14px;font-weight:500;margin:0 auto;padding:8px 12px;width:fit-content}.${e}--${`info`}{background:#fff}.${e}--${`warning`}{background:#fbc02c}.${e}--${`error`}{background:#fa4446;color:#fff}`,this._styleElement}get type(){return this.getAttribute(`type`)??`info`}set type(e){this.setAttribute(`type`,e)}get message(){return this.getAttribute(`message`)??``}set message(e){this.setAttribute(`message`,e)}get visible(){return this.hasAttribute(`visible`)}set visible(e){this.toggleAttribute(`visible`,e)}static create(){return i({[e]:o}),document.createElement(e)}show(e,t,r){this.hide(),this.type=e,this.message=t,this.visible=!0,this.timeout=new n(r,this.hide.bind(this)),this.timeout.start()}hide(){var e;(e=this.timeout)==null||e.stop(),this.visible=!1}render(){this.innerHTML=a`<div class="${e} ${e}--${this.type}">${this.message}</div>`}connectedCallback(){this.render(),this.append(this.styleElement)}disconnectedCallback(){this.hide()}attributeChangedCallback(e,t,n){n!==t&&(this.render(),this.append(this.styleElement))}};o.observedAttributes=[`type`,`message`];export{o as SparkScanViewToast};