@aurelia-mdc-web/list
Version:
Wrapper for Material Components Web List
90 lines • 3.19 kB
JavaScript
import { __decorate, __metadata } from "tslib";
import { inject, useView, customElement, processContent } from 'aurelia-framework';
import { PLATFORM } from 'aurelia-pal';
import { bindable } from 'aurelia-typed-observable-plugin';
let listItemId = 0;
const ENTER = 13;
const SPACE = 32;
const LIST_ITEM_ACTION = 'mdclistitem:action';
/**
* @selector mdc-deprecated-list-item
*/
let MdcDeprecatedListItem = class MdcDeprecatedListItem {
constructor(root) {
this.root = root;
this.id = ++listItemId;
}
static processContent(_viewCompiler, _resources, element) {
const graphic = element.querySelector('mdc-checkbox:not([mdc-deprecated-list-item-meta]),[mdc-deprecated-list-item-graphic]');
if (graphic) {
element.removeChild(graphic);
}
const meta = element.querySelector('[mdc-deprecated-list-item-meta]');
if (meta) {
element.removeChild(meta);
}
const itemText = document.createElement('span');
itemText.classList.add('mdc-deprecated-list-item__text');
const children = [].slice.call(element.childNodes);
for (let i = 0; i < children.length; ++i) {
itemText.appendChild(children[i]);
}
if (graphic) {
element.appendChild(graphic);
}
element.appendChild(itemText);
if (meta) {
element.appendChild(meta);
}
return true;
}
hrefChanged() {
if (this.href) {
this.root.setAttribute('href', this.href);
}
else {
this.root.removeAttribute('href');
}
}
onKeydown(evt) {
if ((evt.keyCode === ENTER || evt.keyCode === SPACE) && !this.disabled) {
this.root.dispatchEvent(new CustomEvent(LIST_ITEM_ACTION, { detail: { item: this, data: this.value }, bubbles: true }));
}
return true;
}
onClick() {
if (!this.disabled) {
this.root.dispatchEvent(new CustomEvent(LIST_ITEM_ACTION, { detail: { item: this, data: this.value }, bubbles: true }));
}
return true;
}
};
__decorate([
bindable.booleanAttr,
__metadata("design:type", Boolean)
], MdcDeprecatedListItem.prototype, "disabled", void 0);
__decorate([
bindable.booleanAttr,
__metadata("design:type", Boolean)
], MdcDeprecatedListItem.prototype, "activated", void 0);
__decorate([
bindable.none,
__metadata("design:type", Object)
], MdcDeprecatedListItem.prototype, "value", void 0);
__decorate([
bindable.booleanAttr,
__metadata("design:type", Boolean)
], MdcDeprecatedListItem.prototype, "disableRipple", void 0);
__decorate([
bindable.none,
__metadata("design:type", String)
], MdcDeprecatedListItem.prototype, "href", void 0);
MdcDeprecatedListItem = __decorate([
inject(Element),
useView(PLATFORM.moduleName('./mdc-deprecated-list-item.html')),
customElement('mdc-deprecated-list-item'),
processContent(MdcDeprecatedListItem.processContent),
__metadata("design:paramtypes", [HTMLElement])
], MdcDeprecatedListItem);
export { MdcDeprecatedListItem };
//# sourceMappingURL=mdc-deprecated-list-item.js.map