aurelia-materialize-bridge
Version:
Aurelia interface to http://materializecss.com/
74 lines (61 loc) • 1.55 kB
text/typescript
import * as au from "../aurelia";
.customElement("md-checkbox")
.autoinject
export class MdCheckbox {
constructor(private element: Element) {
this.controlId = `md-checkbox-${MdCheckbox.id++}`;
}
static id = 0;
controlId: string;
attributeManager: au.AttributeManager;
checkbox: HTMLInputElement;
.bindable({ defaultBindingMode: au.bindingMode.twoWay })
checked: boolean | any[];
.ato.bindable.booleanMd
disabled: boolean;
disabledChanged(newValue) {
if (this.checkbox) {
this.checkbox.disabled = !!newValue;
}
}
.ato.bindable.booleanMd
readonly: boolean = false;
readonlyChanged() {
if (!this.checkbox) {
return;
}
if (this.readonly) {
this.checkbox.addEventListener("change", this.preventChange);
} else {
this.checkbox.removeEventListener("change", this.preventChange);
}
}
.ato.bindable.booleanMd
filledIn: boolean;
.bindable
matcher: (a: any, b: any) => boolean;
.bindable
model: any;
attached() {
this.attributeManager = new au.AttributeManager(this.checkbox);
if (this.filledIn) {
this.attributeManager.addClasses("filled-in");
}
if (this.checked === null) {
this.checkbox.indeterminate = true;
} else {
this.checkbox.indeterminate = false;
}
if (this.disabled) {
this.checkbox.disabled = true;
}
this.readonlyChanged();
}
detached() {
this.attributeManager.removeClasses(["filled-in", "disabled"]);
}
// it is called with an element as this
preventChange(this: HTMLInputElement) {
this.checked = !this.checked;
}
}