push.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { types } from "assets/types.js";
  2. import { widget } from "interface/widget.js";
  3. class push extends widget {
  4. #is_pressed;
  5. constructor(name = undefined, submit = false) {
  6. types.check_boolean(submit);
  7. const target = document.createElement("button");
  8. if (submit) {
  9. target.type = "submit";
  10. }
  11. if (typeof(name) === "string") {
  12. target.name = name;
  13. }
  14. super(target, "push", name);
  15. this.#is_pressed = false;
  16. this._add_event("mousedown", () => { this.#pressed(); });
  17. this._add_event("mouseup", () => { this.#released(); });
  18. this._add_event("mouseover", () => { this.#released(); });
  19. }
  20. #pressed() {
  21. this.#is_pressed = true;
  22. }
  23. #released() {
  24. this.#is_pressed = false;
  25. }
  26. set icon(target) {
  27. if (!(target instanceof icon)) {
  28. throw new TypeError("Icon for button must be an icon.");
  29. }
  30. this._drop_content();
  31. this._append(target);
  32. }
  33. set text(target) {
  34. this._drop_content();
  35. this._content = text;
  36. }
  37. get is_pressed() {
  38. return this.#is_pressed;
  39. }
  40. }
  41. export { push };