UNPKG

igniteui-webcomponents

Version:

Ignite UI for Web Components is a complete library of UI components, giving you the ability to build modern web applications using encapsulation and the concept of reusable components in a dependency-free approach.

82 lines 3.14 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { LitElement } from 'lit'; import { property } from 'lit/decorators.js'; import { fadeIn, fadeOut } from '../../../animations/presets/fade/index.js'; import { watch } from '../decorators/watch.js'; export class IgcBaseAlertLikeComponent extends LitElement { displayTimeChange() { this.setAutoHideTimer(); } keepOpenChange() { clearTimeout(this._autoHideTimeout); } constructor() { super(); this.open = false; this.displayTime = 4000; this.keepOpen = false; this.position = 'bottom'; this._internals = this.attachInternals(); this._internals.role = 'status'; this._internals.ariaLive = 'polite'; } async toggleAnimation(state) { const animation = state === 'open' ? fadeIn : fadeOut; const [_, event] = await Promise.all([ this._animationPlayer.stopAll(), this._animationPlayer.play(animation()), ]); return event.type === 'finish'; } setAutoHideTimer() { clearTimeout(this._autoHideTimeout); if (this.open && this.displayTime > 0 && !this.keepOpen) { this._autoHideTimeout = setTimeout(() => this.hide(), this.displayTime); } } async show() { if (this.open) { return false; } this.open = true; await this.toggleAnimation('open'); this.setAutoHideTimer(); return true; } async hide() { if (!this.open) { return false; } clearTimeout(this._autoHideTimeout); await this.toggleAnimation('close'); this.open = false; return true; } async toggle() { return this.open ? this.hide() : this.show(); } } __decorate([ property({ type: Boolean, reflect: true }) ], IgcBaseAlertLikeComponent.prototype, "open", void 0); __decorate([ property({ type: Number, attribute: 'display-time' }) ], IgcBaseAlertLikeComponent.prototype, "displayTime", void 0); __decorate([ property({ type: Boolean, reflect: true, attribute: 'keep-open' }) ], IgcBaseAlertLikeComponent.prototype, "keepOpen", void 0); __decorate([ property({ reflect: true }) ], IgcBaseAlertLikeComponent.prototype, "position", void 0); __decorate([ watch('displayTime', { waitUntilFirstUpdate: true }) ], IgcBaseAlertLikeComponent.prototype, "displayTimeChange", null); __decorate([ watch('keepOpen', { waitUntilFirstUpdate: true }) ], IgcBaseAlertLikeComponent.prototype, "keepOpenChange", null); //# sourceMappingURL=alert.js.map