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.

133 lines 4.94 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, queryAssignedElements } from 'lit/decorators.js'; import { createRef, ref } from 'lit/directives/ref.js'; import { addThemingController } from '../../theming/theming-controller.js'; import { addKeybindings } from '../common/controllers/key-bindings.js'; import { registerComponent } from '../common/definitions/register.js'; import { EventEmitterMixin } from '../common/mixins/event-emitter.js'; import { isEmpty } from '../common/util.js'; import IgcIconComponent from '../icon/icon.js'; import { styles } from './themes/chip.base.css.js'; import { styles as shared } from './themes/shared/chip.common.css.js'; import { all } from './themes/themes.js'; class IgcChipComponent extends EventEmitterMixin(LitElement) { static register() { registerComponent(IgcChipComponent, IgcIconComponent); } constructor() { super(); this._removePartRef = createRef(); this.disabled = false; this.removable = false; this.selectable = false; this.selected = false; addThemingController(this, all); addKeybindings(this, { ref: this._removePartRef, bindingDefaults: { triggers: ['keyup'] }, }).setActivateHandler(this.handleRemove); } createRenderRoot() { const root = super.createRenderRoot(); root.addEventListener('slotchange', () => this.requestUpdate()); return root; } handleSelect() { if (this.selectable) { this.selected = !this.selected; this.emitEvent('igcSelect', { detail: this.selected }); } } handleRemove(e) { this.emitEvent('igcRemove'); e.stopPropagation(); } render() { return html ` <button part="base" .disabled=${this.disabled} aria-selected=${this.selected} aria-disabled=${this.disabled} @click=${this.handleSelect} > <span part="prefix" .hidden=${isEmpty(this.prefixes) && isEmpty(this.contentStart) && !this.selected} > ${this.selectable && this.selected ? html `<slot name="select"> <igc-icon name="selected" collection="default"></igc-icon> </slot>` : nothing} <slot name="start"></slot> <slot name="prefix"></slot> </span> <slot></slot> <span part="suffix" .hidden=${isEmpty(this.suffixes) && isEmpty(this.contentEnd) && !this.removable} > <slot name="end"></slot> <slot name="suffix"></slot> ${this.removable && !this.disabled ? html `<slot ${ref(this._removePartRef)} @click=${this.handleRemove} name="remove" > <igc-icon name="remove" collection="default" tabindex="0" role="button" aria-label="remove" ></igc-icon> </slot>` : nothing} </span> </button> `; } } IgcChipComponent.tagName = 'igc-chip'; IgcChipComponent.styles = [styles, shared]; export default IgcChipComponent; __decorate([ property({ type: Boolean, reflect: true }) ], IgcChipComponent.prototype, "disabled", void 0); __decorate([ property({ type: Boolean, reflect: true }) ], IgcChipComponent.prototype, "removable", void 0); __decorate([ property({ type: Boolean, reflect: true }) ], IgcChipComponent.prototype, "selectable", void 0); __decorate([ property({ type: Boolean, reflect: true }) ], IgcChipComponent.prototype, "selected", void 0); __decorate([ property({ reflect: true }) ], IgcChipComponent.prototype, "variant", void 0); __decorate([ queryAssignedElements({ slot: 'prefix' }) ], IgcChipComponent.prototype, "prefixes", void 0); __decorate([ queryAssignedElements({ slot: 'start' }) ], IgcChipComponent.prototype, "contentStart", void 0); __decorate([ queryAssignedElements({ slot: 'suffix' }) ], IgcChipComponent.prototype, "suffixes", void 0); __decorate([ queryAssignedElements({ slot: 'end' }) ], IgcChipComponent.prototype, "contentEnd", void 0); //# sourceMappingURL=chip.js.map