@rogieking/figui3 1.0.95 → 1.0.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/example.html +3 -0
  2. package/fig.js +26 -17
  3. package/package.json +1 -1
package/example.html CHANGED
@@ -18,6 +18,9 @@
18
18
  </fig-header>
19
19
  <h2>Heading 2</h2>
20
20
  <h3>Heading 3</h3>
21
+ <form onsubmit="console.log('submit'); return false;">
22
+ <fig-button type="submit">Submit</fig-button>
23
+ </form>
21
24
  <br />
22
25
  <fig-button id="button-progressive-blur"
23
26
  variant="ghost"
package/fig.js CHANGED
@@ -8,14 +8,14 @@ function supportsPopover() {
8
8
  if (window.customElements && !window.customElements.get("fig-button")) {
9
9
  /* Button */
10
10
  class FigButton extends HTMLElement {
11
- #type;
11
+ type;
12
12
  #selected;
13
13
  constructor() {
14
14
  super();
15
15
  this.attachShadow({ mode: "open" });
16
16
  }
17
17
  connectedCallback() {
18
- this.#type = this.getAttribute("type") || "button";
18
+ this.type = this.getAttribute("type") || "button";
19
19
  this.shadowRoot.innerHTML = `
20
20
  <style>
21
21
  button, button:hover, button:active {
@@ -36,7 +36,7 @@ if (window.customElements && !window.customElements.get("fig-button")) {
36
36
  height: var(--spacer-4);
37
37
  }
38
38
  </style>
39
- <button type="${this.#type}">
39
+ <button type="${this.type}">
40
40
  <slot></slot>
41
41
  </button>
42
42
  `;
@@ -44,45 +44,54 @@ if (window.customElements && !window.customElements.get("fig-button")) {
44
44
  this.#selected =
45
45
  this.hasAttribute("selected") &&
46
46
  this.getAttribute("selected") !== "false";
47
- this.addEventListener("click", this.#handleClick.bind(this));
48
47
 
49
48
  requestAnimationFrame(() => {
50
- this.button = this.querySelector("button");
49
+ this.button = this.shadowRoot.querySelector("button");
50
+ this.button.addEventListener("click", this.#handleClick.bind(this));
51
51
  });
52
52
  }
53
53
 
54
54
  get type() {
55
- return this.#type;
55
+ return this.type;
56
56
  }
57
57
  set type(value) {
58
- this.#type = value;
59
- this.button.type = value;
60
58
  this.setAttribute("type", value);
61
59
  }
62
60
  get selected() {
63
61
  return this.#selected;
64
62
  }
65
63
  set selected(value) {
66
- this.#selected = value;
67
64
  this.setAttribute("selected", value);
68
65
  }
69
66
 
70
- #handleClick(event) {
71
- if (this.#type === "toggle") {
72
- this.selected = !this.#selected;
67
+ #handleClick() {
68
+ if (this.type === "toggle") {
69
+ this.toggleAttribute("selected", !this.hasAttribute("selected"));
73
70
  }
74
- if (this.#type === "submit") {
75
- this.button.click();
71
+ if (this.type === "submit") {
72
+ this.closest("form").dispatchEvent(new Event("submit"));
76
73
  }
77
74
  }
78
75
  static get observedAttributes() {
79
- return ["disabled"];
76
+ return ["disabled", "selected"];
80
77
  }
81
78
  attributeChangedCallback(name, oldValue, newValue) {
82
79
  if (this.button) {
83
80
  this.button[name] = newValue;
84
- if (newValue === "false") {
85
- this.button.removeAttribute(name);
81
+ switch (name) {
82
+ case "disabled":
83
+ this.disabled = this.button.disabled =
84
+ newValue === "true" ||
85
+ (newValue === undefined && newValue !== null);
86
+ break;
87
+ case "type":
88
+ this.type = newValue;
89
+ this.button.type = this.type;
90
+ this.button.setAttribute("type", this.type);
91
+ break;
92
+ case "selected":
93
+ this.#selected = newValue === "true";
94
+ break;
86
95
  }
87
96
  }
88
97
  }
package/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "1.0.95"
3
+ "version": "1.0.96"
4
4
  }