cx-ui.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. export class cx_ui {
  2. static #generator(type, manipulator = null) {
  3. return (name, click = null, manipulate = null) => {
  4. const item = document.createElement(type);
  5. item.id = `${type}-${name}`;
  6. item.classList.add(name);
  7. item.classList.add(`${type}-${name}`);
  8. if (manipulator !== null) {
  9. manipulator(item);
  10. }
  11. if (click !== null) {
  12. item.addEventListener("click", click);
  13. }
  14. if (manipulate !== null) {
  15. manipulate(item);
  16. }
  17. return item;
  18. };
  19. }
  20. static get div() {
  21. return this.#generator("div");
  22. }
  23. static get push() {
  24. return this.#generator("input", (item) => {
  25. item.type = "button";
  26. item.classList.add("push");
  27. });
  28. }
  29. static p(name, text, click = null, manipulate = null) {
  30. const generator = this.#generator("p", (p) => { p.innerText = text; });
  31. const result = generator(name, click, manipulate);
  32. return result;
  33. }
  34. static get input() {
  35. return this.#generator("input");
  36. }
  37. static image(name, url, click = null, manipulate = null) {
  38. const generator = this.#generator("img", (img) => { img.src = url; });
  39. const result = generator(name, click, manipulate);
  40. return result;
  41. }
  42. }