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.
100 lines • 3.74 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;
};
var IgcBannerComponent_1;
import { LitElement, html } from 'lit';
import { property } from 'lit/decorators.js';
import { createRef, ref } from 'lit/directives/ref.js';
import { addAnimationController } from '../../animations/player.js';
import { growVerIn, growVerOut } from '../../animations/presets/grow/index.js';
import { themes } from '../../theming/theming-decorator.js';
import IgcButtonComponent from '../button/button.js';
import { registerComponent } from '../common/definitions/register.js';
import { EventEmitterMixin } from '../common/mixins/event-emitter.js';
import { styles } from './themes/banner.base.css.js';
import { all } from './themes/themes.js';
let IgcBannerComponent = IgcBannerComponent_1 = class IgcBannerComponent extends EventEmitterMixin(LitElement) {
static register() {
registerComponent(IgcBannerComponent_1, IgcButtonComponent);
}
constructor() {
super();
this._bannerRef = createRef();
this._animationPlayer = addAnimationController(this, this._bannerRef);
this.open = false;
this._internals = this.attachInternals();
this._internals.role = 'status';
this._internals.ariaLive = 'polite';
}
async show() {
if (this.open) {
return false;
}
this.open = true;
return await this.toggleAnimation('open');
}
async hide() {
if (!this.open) {
return false;
}
await this.toggleAnimation('close');
this.open = false;
return true;
}
async toggle() {
return this.open ? await this.hide() : await this.show();
}
async toggleAnimation(dir) {
const animation = dir === 'open' ? growVerIn : growVerOut;
const [_, event] = await Promise.all([
this._animationPlayer.stopAll(),
this._animationPlayer.play(animation()),
]);
return event.type === 'finish';
}
async handleClick() {
if (this.emitEvent('igcClosing', { cancelable: true })) {
await this.hide();
this.emitEvent('igcClosed');
}
}
render() {
return html `
<div ${ref(this._bannerRef)} part="base" .inert=${!this.open}>
<div part="spacer">
<div part="message">
<div part="illustration">
<slot name="prefix"></slot>
</div>
<div part="content">
<slot></slot>
</div>
</div>
<div part="actions">
<slot name="actions">
<igc-button
type="button"
variant="flat"
=${this.handleClick}
>OK</igc-button
>
</slot>
</div>
</div>
</div>
`;
}
};
IgcBannerComponent.tagName = 'igc-banner';
IgcBannerComponent.styles = [styles];
__decorate([
property({ type: Boolean, reflect: true })
], IgcBannerComponent.prototype, "open", void 0);
IgcBannerComponent = IgcBannerComponent_1 = __decorate([
themes(all)
], IgcBannerComponent);
export default IgcBannerComponent;
//# sourceMappingURL=banner.js.map