UNPKG

@larva.io/webcomponents

Version:

Fentrica SmartUnits WebComponents package

154 lines (153 loc) 4.9 kB
/*! * (C) Fentrica http://fentrica.com - Seee LICENSE.md */ import { Host, h } from "@stencil/core"; import { now } from "../../../utils/helpers"; export class Backdrop { constructor() { this.lastClick = -10000; /** * If `true`, the backdrop will be visible. Defaults to `true`. */ this.visible = true; /** * If `true`, the backdrop will can be clicked and will emit the `larbackdroptap` event. Defaults to `true`. */ this.tappable = true; /** * If `true`, the backdrop will stop propagation on tap. Defaults to `true`. */ this.stopPropagation = true; } onTouchStart(ev) { this.lastClick = now(ev); this.emitTap(ev); } onMouseDown(ev) { if (this.lastClick < now(ev) - 2500) { this.emitTap(ev); } } emitTap(ev) { if (this.stopPropagation) { ev.preventDefault(); ev.stopPropagation(); } if (this.tappable) { this.larbackdroptap.emit(); } } render() { return (h(Host, { key: 'a69aabe4dbcb78596ae7dab9000241d2fee2e63b', tabindex: "-1", class: { 'lar-backdrop-hide': !this.visible, 'lar-backdrop-no-tappable': !this.tappable } })); } static get is() { return "lar-backdrop"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["backdrop.scss"] }; } static get styleUrls() { return { "$": ["backdrop.css"] }; } static get properties() { return { "visible": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "If `true`, the backdrop will be visible. Defaults to `true`." }, "getter": false, "setter": false, "reflect": false, "attribute": "visible", "defaultValue": "true" }, "tappable": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "If `true`, the backdrop will can be clicked and will emit the `larbackdroptap` event. Defaults to `true`." }, "getter": false, "setter": false, "reflect": false, "attribute": "tappable", "defaultValue": "true" }, "stopPropagation": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "If `true`, the backdrop will stop propagation on tap. Defaults to `true`." }, "getter": false, "setter": false, "reflect": false, "attribute": "stop-propagation", "defaultValue": "true" } }; } static get events() { return [{ "method": "larbackdroptap", "name": "larbackdroptap", "bubbles": true, "cancelable": true, "composed": true, "docs": { "tags": [], "text": "Emitted when the backdrop is tapped." }, "complexType": { "original": "void", "resolved": "void", "references": {} } }]; } static get listeners() { return [{ "name": "touchstart", "method": "onTouchStart", "target": undefined, "capture": true, "passive": false }, { "name": "click", "method": "onMouseDown", "target": undefined, "capture": true, "passive": false }]; } } //# sourceMappingURL=backdrop.js.map