mirror of
https://github.com/esiur/iui.git
synced 2026-04-04 06:58:22 +00:00
initial commit
This commit is contained in:
58
src/UI/Check.js
Normal file
58
src/UI/Check.js
Normal file
@@ -0,0 +1,58 @@
|
||||
import IUIElement from "../Core/IUIElement.js";
|
||||
import { IUI } from "../Core/IUI.js";
|
||||
|
||||
export default IUI.module(class Check extends IUIElement {
|
||||
constructor(properties) {
|
||||
super(IUI.extend(properties, { cssClass: 'check' }));
|
||||
|
||||
this._register("check");
|
||||
|
||||
this.on("click", () => {
|
||||
this.checked = !this.checked;
|
||||
});
|
||||
}
|
||||
|
||||
get checked() {
|
||||
return this.hasAttribute("checked");
|
||||
}
|
||||
|
||||
set checked(value) {
|
||||
this.check(value);
|
||||
this._emit("check", { checked: value });
|
||||
}
|
||||
|
||||
check(value) {
|
||||
if (value)
|
||||
this.setAttribute("checked", "checked");
|
||||
else
|
||||
this.removeAttribute("checked");
|
||||
}
|
||||
|
||||
create() {
|
||||
this.field = this.getAttribute("field");
|
||||
}
|
||||
|
||||
async setData(value) {
|
||||
await super.setData(value);
|
||||
if (value != null && this.field != null)
|
||||
this.value = value[this.field];
|
||||
else if (this.field != null)
|
||||
this.value = null;
|
||||
}
|
||||
|
||||
|
||||
modified(name, value) {
|
||||
if (name == this.field) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
get value() {
|
||||
return this.checked;
|
||||
}
|
||||
|
||||
set value(value) {
|
||||
this.checked = value;
|
||||
}
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user