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.
113 lines • 4.3 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 IgcChipComponent_1;
import { LitElement, html, nothing } from 'lit';
import { property } from 'lit/decorators.js';
import { createRef, ref } from 'lit/directives/ref.js';
import { themes } from '../../theming/theming-decorator.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 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';
let IgcChipComponent = IgcChipComponent_1 = class IgcChipComponent extends EventEmitterMixin(LitElement) {
static register() {
registerComponent(IgcChipComponent_1, IgcIconComponent);
}
constructor() {
super();
this._removePartRef = createRef();
this.disabled = false;
this.removable = false;
this.selectable = false;
this.selected = false;
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 ? 'true' : 'false'}"
aria-disabled="${this.disabled ? 'true' : 'false'}"
=${this.handleSelect}
>
<span part="prefix">
${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">
<slot name="end"></slot>
<slot name="suffix"></slot>
${this.removable && !this.disabled
? html `<slot
${ref(this._removePartRef)}
=${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];
__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);
IgcChipComponent = IgcChipComponent_1 = __decorate([
themes(all)
], IgcChipComponent);
export default IgcChipComponent;
//# sourceMappingURL=chip.js.map