2
0
mirror of https://github.com/esiur/iui.git synced 2026-04-04 15:08:21 +00:00
Files
iui/src/UI/Button.js
2021-02-22 11:39:50 +03:00

70 lines
1.6 KiB
JavaScript

import IUIElement from "../Core/IUIElement.js";
import { IUI } from "../Core/IUI.js";
export default IUI.module(class Button extends IUIElement {
constructor() {
super({ cssClass: 'button' });
this.addEventListener("mousedown", (e)=>{
var r = this.getBoundingClientRect();
this.style.setProperty("--x", (e.x - r.x) + "px");
this.style.setProperty("--y", (e.y - r.y) + "px");
this.style.setProperty("--w", r.width + "px");
this.style.setProperty("--h", r.height + "px");
this.classList.remove(this.cssClass + "-clicked");
void this.offsetWidth;
this.classList.add(this.cssClass + "-clicked");
}, true);
this._register("check");
}
get type() {
return this.getAttribute("type");
}
set type(value)
{
this.setAttribute("type", value);
}
get checked() {
return this.hasAttribute("checked");
}
set checked(value)
{
if (value)
this.setAttribute("checked", "");
else
this.removeAttribute("checked");
}
get disabled() {
return this.getAttribute("disabled");
}
set disabled(value) {
this.setAttribute("disabled", value);
}
create() {
if (this.type == "check")
{
this.addEventListener("click", ()=>{
let checked = !this.checked;
this.checked = checked;
this._emit("check", {checked});
});
}
//this.classList.add(this.cssClass);
}
});