mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
41 lines
955 B
JavaScript
41 lines
955 B
JavaScript
//#region src/dom/ui/button.ts
|
|
function createButton(options) {
|
|
const { onActivate, isDisabled } = options;
|
|
return {
|
|
role: "button",
|
|
tabIndex: 0,
|
|
onClick(event) {
|
|
if (isDisabled()) {
|
|
event.preventDefault();
|
|
return;
|
|
}
|
|
onActivate(event);
|
|
},
|
|
onPointerDown(event) {
|
|
if (isDisabled()) event.preventDefault();
|
|
},
|
|
onMouseDown(event) {
|
|
if (isDisabled()) event.preventDefault();
|
|
},
|
|
onKeyDown(event) {
|
|
if (event.target !== event.currentTarget) return;
|
|
if (isDisabled()) {
|
|
if (event.key !== "Tab") event.preventDefault();
|
|
return;
|
|
}
|
|
if (event.key === "Enter") {
|
|
event.preventDefault();
|
|
onActivate(event);
|
|
} else if (event.key === " ") event.preventDefault();
|
|
},
|
|
onKeyUp(event) {
|
|
if (event.target !== event.currentTarget) return;
|
|
if (isDisabled()) return;
|
|
if (event.key === " ") onActivate(event);
|
|
}
|
|
};
|
|
}
|
|
//#endregion
|
|
export { createButton };
|
|
|
|
//# sourceMappingURL=button.js.map
|