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.

83 lines 3.05 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 { html, LitElement, nothing } from 'lit'; import { property, state } from 'lit/decorators.js'; import { ifDefined } from 'lit/directives/if-defined.js'; import { addThemingController } from '../../theming/theming-controller.js'; import { addInternalsController } from '../common/controllers/internals.js'; import { registerComponent } from '../common/definitions/register.js'; import { styles } from './themes/avatar.base.css.js'; import { styles as shared } from './themes/shared/avatar.common.css.js'; import { all } from './themes/themes.js'; class IgcAvatarComponent extends LitElement { static register() { registerComponent(IgcAvatarComponent); } constructor() { super(); this._internals = addInternalsController(this, { initialARIA: { role: 'image', ariaLabel: 'avatar', }, }); this._hasError = false; this.shape = 'square'; addThemingController(this, all); } willUpdate(changedProperties) { if (changedProperties.has('initials') || changedProperties.has('alt')) { this._internals.setARIA({ ariaRoleDescription: this.alt ?? this.initials, }); } if (changedProperties.has('src')) { this._hasError = false; } } _handleError() { this._hasError = true; } render() { return html ` <div part="base"> ${this.initials ? html `<span part="initials">${this.initials}</span>` : html `<slot></slot>`} ${this.src && !this._hasError ? html ` <img part="image" alt=${ifDefined(this.alt)} src=${ifDefined(this.src)} @error=${this._handleError} /> ` : nothing} </div> `; } } IgcAvatarComponent.tagName = 'igc-avatar'; IgcAvatarComponent.styles = [styles, shared]; export default IgcAvatarComponent; __decorate([ state() ], IgcAvatarComponent.prototype, "_hasError", void 0); __decorate([ property() ], IgcAvatarComponent.prototype, "src", void 0); __decorate([ property() ], IgcAvatarComponent.prototype, "alt", void 0); __decorate([ property() ], IgcAvatarComponent.prototype, "initials", void 0); __decorate([ property({ reflect: true }) ], IgcAvatarComponent.prototype, "shape", void 0); //# sourceMappingURL=avatar.js.map