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.
118 lines • 4.38 kB
JavaScript
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 { addAnimationController } from '../../../animations/player.js';
import { fadeIn, fadeOut } from '../../../animations/presets/fade/index.js';
import { addCommandController } from '../controllers/command.js';
import { addInternalsController } from '../controllers/internals.js';
import { getVisibleAncestor, isPopoverOpen } from '../util.js';
export class IgcBaseAlertLikeComponent extends LitElement {
constructor() {
super();
this._player = addAnimationController(this);
this.open = false;
this.displayTime = 4000;
this.keepOpen = false;
this.position = 'bottom';
this.positioning = 'viewport';
addCommandController(this)
.set('--show', this.show)
.set('--hide', this.hide)
.set('--toggle', this.toggle);
addInternalsController(this, {
initialARIA: {
role: 'status',
ariaLive: 'polite',
},
});
}
connectedCallback() {
super.connectedCallback();
this.popover = 'manual';
}
update(props) {
if (props.has('open')) {
if (this.open && !isPopoverOpen(this)) {
this._showPopover();
}
else if (!this.open && isPopoverOpen(this)) {
this.hidePopover();
}
}
if (this.open && (props.has('positioning') || props.has('position'))) {
this.hidePopover();
this._showPopover();
}
if (props.has('open') ||
props.has('displayTime') ||
props.has('keepOpen')) {
this._setAutoHideTimer();
}
super.update(props);
}
_showPopover() {
if (this.positioning !== 'container') {
this.showPopover();
return true;
}
const visibleAncestor = getVisibleAncestor(this);
if (!visibleAncestor) {
return false;
}
this.showPopover({ source: visibleAncestor });
return true;
}
async _setOpenState(open) {
if (open) {
this.open = true;
if (!this._showPopover()) {
this.open = false;
return false;
}
const state = await this._player.playExclusive(fadeIn());
this._setAutoHideTimer();
return state;
}
clearTimeout(this._autoHideTimeout);
const state = await this._player.playExclusive(fadeOut());
this.hidePopover();
this.open = false;
return state;
}
_setAutoHideTimer() {
clearTimeout(this._autoHideTimeout);
if (this.open && this.displayTime > 0 && !this.keepOpen) {
this._autoHideTimeout = setTimeout(() => this.hide(), this.displayTime);
}
}
async show() {
return this.open ? false : this._setOpenState(true);
}
async hide() {
return this.open ? this._setOpenState(false) : false;
}
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([
property({ reflect: true })
], IgcBaseAlertLikeComponent.prototype, "positioning", void 0);
//# sourceMappingURL=alert.js.map