@rogieking/figui3 1.0.64 → 1.0.65

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 (4) hide show
  1. package/example.html +2 -1
  2. package/fig.css +2 -13
  3. package/fig.js +132 -94
  4. package/package.json +1 -1
package/example.html CHANGED
@@ -45,7 +45,8 @@
45
45
  <br />
46
46
  <fig-field direction="horizontal">
47
47
  <label>Blend mode</label>
48
- <fig-dropdown full>
48
+ <fig-dropdown full
49
+ type="dropdown">
49
50
  <option>One</option>
50
51
  <option>Two</option>
51
52
  </fig-dropdown>
package/fig.css CHANGED
@@ -713,19 +713,6 @@ fig-button {
713
713
  flex-basis: var(--spacer-4);
714
714
  }
715
715
 
716
- /* Upload */
717
- &[upload],
718
- &[upload] > button {
719
- position: relative;
720
-
721
- & input[type="file"] {
722
- opacity: 0;
723
- position: absolute;
724
- inset: 0;
725
- appearance: none;
726
- }
727
- }
728
-
729
716
  /* Disabled */
730
717
  &[disabled="true"],
731
718
  &[disabled="true"] > button {
@@ -765,6 +752,7 @@ fig-button {
765
752
  &[type="select"],
766
753
  &[type="upload"] {
767
754
  position: relative;
755
+ overflow: hidden;
768
756
  > select,
769
757
  > input,
770
758
  > fig-dropdown {
@@ -1984,6 +1972,7 @@ vstack,
1984
1972
  [vstack] {
1985
1973
  display: flex;
1986
1974
  flex-direction: column;
1975
+ align-items: start;
1987
1976
  gap: var(--spacer-2);
1988
1977
  flex-wrap: wrap;
1989
1978
  }
package/fig.js CHANGED
@@ -5,20 +5,21 @@ function supportsPopover() {
5
5
  return HTMLElement.prototype.hasOwnProperty("popover");
6
6
  }
7
7
 
8
- /* Button */
9
- class FigButton extends HTMLElement {
10
- #type;
11
- #selected;
12
- constructor() {
13
- super();
14
- this.attachShadow({ mode: "open" });
15
- }
16
- connectedCallback() {
17
- this.render();
18
- }
19
- render() {
20
- this.#type = this.getAttribute("type") || "button";
21
- this.shadowRoot.innerHTML = `
8
+ if (window.customElements && !window.customElements.get("fig-button")) {
9
+ /* Button */
10
+ class FigButton extends HTMLElement {
11
+ #type;
12
+ #selected;
13
+ constructor() {
14
+ super();
15
+ this.attachShadow({ mode: "open" });
16
+ }
17
+ connectedCallback() {
18
+ this.render();
19
+ }
20
+ render() {
21
+ this.#type = this.getAttribute("type") || "button";
22
+ this.shadowRoot.innerHTML = `
22
23
  <style>
23
24
  button, button:hover, button:active {
24
25
  padding: 0 var(--spacer-2);
@@ -43,108 +44,143 @@ class FigButton extends HTMLElement {
43
44
  </button>
44
45
  `;
45
46
 
46
- this.#selected =
47
- this.hasAttribute("selected") &&
48
- this.getAttribute("selected") !== "false";
49
- this.addEventListener("click", this.handleClick.bind(this));
47
+ this.#selected =
48
+ this.hasAttribute("selected") &&
49
+ this.getAttribute("selected") !== "false";
50
+ this.addEventListener("click", this.handleClick.bind(this));
50
51
 
51
- this.button = this.querySelector("button");
52
- }
53
- get type() {
54
- return this.#type;
55
- }
56
- set type(value) {
57
- this.#type = value;
58
- this.button.type = value;
59
- this.setAttribute("type", value);
60
- }
61
- get selected() {
62
- return this.#selected;
63
- }
64
- set selected(value) {
65
- this.#selected = value;
66
- this.setAttribute("selected", value);
67
- }
52
+ this.button = this.querySelector("button");
53
+ }
54
+ get type() {
55
+ return this.#type;
56
+ }
57
+ set type(value) {
58
+ this.#type = value;
59
+ this.button.type = value;
60
+ this.setAttribute("type", value);
61
+ }
62
+ get selected() {
63
+ return this.#selected;
64
+ }
65
+ set selected(value) {
66
+ this.#selected = value;
67
+ this.setAttribute("selected", value);
68
+ }
68
69
 
69
- handleClick(event) {
70
- if (this.#type === "toggle") {
71
- this.selected = !this.#selected;
70
+ handleClick(event) {
71
+ if (this.#type === "toggle") {
72
+ this.selected = !this.#selected;
73
+ }
74
+ if (this.#type === "submit") {
75
+ this.button.click();
76
+ }
72
77
  }
73
- if (this.#type === "submit") {
74
- this.button.click();
78
+ static get observedAttributes() {
79
+ return ["disabled"];
75
80
  }
76
- }
77
- static get observedAttributes() {
78
- return ["disabled"];
79
- }
80
- attributeChangedCallback(name, oldValue, newValue) {
81
- if (this.button) {
82
- this.button[name] = newValue;
83
- if (newValue === "false") {
84
- this.button.removeAttribute(name);
81
+ attributeChangedCallback(name, oldValue, newValue) {
82
+ if (this.button) {
83
+ this.button[name] = newValue;
84
+ if (newValue === "false") {
85
+ this.button.removeAttribute(name);
86
+ }
85
87
  }
86
88
  }
87
89
  }
90
+ window.customElements.define("fig-button", FigButton);
88
91
  }
89
- window.customElements.define("fig-button", FigButton);
90
92
 
91
- /* Dropdown */
92
- class FigDropdown extends HTMLElement {
93
- constructor() {
94
- super();
95
- this.attachShadow({ mode: "open" });
96
- }
93
+ if (window.customElements && !window.customElements.get("fig-dropdown")) {
94
+ /* Dropdown */
95
+ class FigDropdown extends HTMLElement {
96
+ constructor() {
97
+ super();
98
+ this.select = document.createElement("select");
99
+ this.optionsSlot = document.createElement("slot");
100
+ this.attachShadow({ mode: "open" });
101
+ }
97
102
 
98
- connectedCallback() {
99
- this.type = this.getAttribute("type") || "select";
100
- this.value = this.getAttribute("value") || "";
103
+ connectedCallback() {
104
+ this.type = this.getAttribute("type") || "select";
105
+ this.value = this.getAttribute("value") || "";
101
106
 
102
- this.select = document.createElement("select");
103
- this.optionsSlot = document.createElement("slot");
104
- this.appendChild(this.select);
105
- this.shadowRoot.appendChild(this.optionsSlot);
107
+ this.appendChild(this.select);
108
+ this.shadowRoot.appendChild(this.optionsSlot);
106
109
 
107
- this.optionsSlot.addEventListener("slotchange", this.slotChange.bind(this));
110
+ this.optionsSlot.addEventListener(
111
+ "slotchange",
112
+ this.slotChange.bind(this)
113
+ );
108
114
 
109
- this.select.addEventListener("input", this.handleDropdownInput.bind(this));
110
- }
115
+ this.select.addEventListener(
116
+ "input",
117
+ this.handleDropdownInput.bind(this)
118
+ );
119
+ this.select.addEventListener(
120
+ "change",
121
+ this.handleDropdownChange.bind(this)
122
+ );
123
+ }
111
124
 
112
- slotChange() {
113
- while (this.select.firstChild) {
114
- this.select.firstChild.remove();
115
- }
116
- if (this.type === "dropdown") {
117
- const hiddenOption = document.createElement("option");
118
- hiddenOption.setAttribute("hidden", "true");
119
- hiddenOption.setAttribute("selected", "true");
120
- this.select.appendChild(hiddenOption);
121
- }
122
- this.optionsSlot.assignedNodes().forEach((option) => {
123
- if (option.nodeName === "OPTION" || option.nodeName === "OPTGROUP") {
124
- if (option.hasAttribute("value") && option.hasAttribute("selected")) {
125
- this.value = option.getAttribute("value");
125
+ slotChange() {
126
+ while (this.select.firstChild) {
127
+ this.select.firstChild.remove();
128
+ }
129
+ if (this.type === "dropdown") {
130
+ const hiddenOption = document.createElement("option");
131
+ hiddenOption.setAttribute("hidden", "true");
132
+ hiddenOption.setAttribute("selected", "true");
133
+ this.select.appendChild(hiddenOption);
134
+ }
135
+ this.optionsSlot.assignedNodes().forEach((option) => {
136
+ if (option.nodeName === "OPTION" || option.nodeName === "OPTGROUP") {
137
+ if (option.hasAttribute("value") && option.hasAttribute("selected")) {
138
+ this.value = option.getAttribute("value");
139
+ }
140
+ this.select.appendChild(option.cloneNode(true));
126
141
  }
127
- this.select.appendChild(option.cloneNode(true));
142
+ });
143
+ if (this.type === "dropdown") {
144
+ this.select.selectedIndex = -1;
128
145
  }
129
- });
130
- if (this.type === "dropdown") {
131
- this.select.selectedIndex = -1;
132
146
  }
133
- }
134
147
 
135
- handleDropdownInput() {
136
- if (this.type === "dropdown") {
148
+ handleDropdownInput() {
137
149
  this.value = this.select.value;
138
150
  this.setAttribute("value", this.value);
139
- this.select.selectedIndex = -1;
151
+ }
152
+ handleDropdownChange() {
153
+ if (this.type === "dropdown") {
154
+ this.select.selectedIndex = -1;
155
+ }
156
+ }
157
+ focus() {
158
+ this.select.focus();
159
+ }
160
+ blur() {
161
+ this.select.blur();
162
+ }
163
+ get value() {
164
+ return this.select?.value;
165
+ }
166
+ set value(value) {
167
+ this.setAttribute("value", value);
168
+ }
169
+ static get observedAttributes() {
170
+ return ["value", "type"];
171
+ }
172
+ attributeChangedCallback(name, oldValue, newValue) {
173
+ if (name === "value") {
174
+ this.select.value = newValue;
175
+ }
176
+ if (name === "type") {
177
+ this.type = newValue;
178
+ }
140
179
  }
141
180
  }
142
- focus() {
143
- this.select.focus();
144
- }
145
- }
146
181
 
147
- customElements.define("fig-dropdown", FigDropdown);
182
+ customElements.define("fig-dropdown", FigDropdown);
183
+ }
148
184
 
149
185
  /* Tooltip */
150
186
  class FigTooltip extends HTMLElement {
@@ -1391,7 +1427,9 @@ class FigImage extends HTMLElement {
1391
1427
  attributeChangedCallback(name, oldValue, newValue) {
1392
1428
  if (name === "src") {
1393
1429
  this.src = newValue;
1394
- this.chit.setAttribute("src", this.src);
1430
+ if (this.chit) {
1431
+ this.chit.setAttribute("src", this.src);
1432
+ }
1395
1433
  }
1396
1434
  if (name === "upload") {
1397
1435
  this.upload = newValue.toLowerCase() === "true";
package/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "1.0.64"
3
+ "version": "1.0.65"
4
4
  }