@rogieking/figui3 2.17.3 → 2.17.4
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.
- package/fig.js +42 -11
- package/package.json +1 -1
package/fig.js
CHANGED
|
@@ -4540,18 +4540,37 @@ customElements.define("fig-toast", FigToast, { extends: "dialog" });
|
|
|
4540
4540
|
* @attr {string} value - The current input value
|
|
4541
4541
|
*/
|
|
4542
4542
|
class FigComboInput extends HTMLElement {
|
|
4543
|
+
#usesCustomDropdown = false;
|
|
4544
|
+
#boundHandleSelectInput = null;
|
|
4545
|
+
|
|
4543
4546
|
constructor() {
|
|
4544
4547
|
super();
|
|
4548
|
+
this.#boundHandleSelectInput = this.handleSelectInput.bind(this);
|
|
4545
4549
|
}
|
|
4546
4550
|
getOptionsFromAttribute() {
|
|
4547
4551
|
return (this.getAttribute("options") || "").split(",");
|
|
4548
4552
|
}
|
|
4549
4553
|
connectedCallback() {
|
|
4554
|
+
const customDropdown =
|
|
4555
|
+
Array.from(this.children).find((child) => child.tagName === "FIG-DROPDOWN") ||
|
|
4556
|
+
null;
|
|
4557
|
+
this.#usesCustomDropdown = customDropdown !== null;
|
|
4558
|
+
if (customDropdown) {
|
|
4559
|
+
customDropdown.remove();
|
|
4560
|
+
}
|
|
4561
|
+
|
|
4550
4562
|
this.options = this.getOptionsFromAttribute();
|
|
4551
4563
|
this.placeholder = this.getAttribute("placeholder") || "";
|
|
4552
4564
|
this.value = this.getAttribute("value") || "";
|
|
4553
4565
|
const experimental = this.getAttribute("experimental");
|
|
4554
4566
|
const expAttr = experimental ? `experimental="${experimental}"` : "";
|
|
4567
|
+
const dropdownHTML = this.#usesCustomDropdown
|
|
4568
|
+
? ""
|
|
4569
|
+
: `<fig-dropdown type="dropdown" ${expAttr}>
|
|
4570
|
+
${this.options
|
|
4571
|
+
.map((option) => `<option>${option}</option>`)
|
|
4572
|
+
.join("")}
|
|
4573
|
+
</fig-dropdown>`;
|
|
4555
4574
|
this.innerHTML = `<div class="input-combo">
|
|
4556
4575
|
<fig-input-text placeholder="${this.placeholder}">
|
|
4557
4576
|
</fig-input-text>
|
|
@@ -4559,21 +4578,30 @@ class FigComboInput extends HTMLElement {
|
|
|
4559
4578
|
<svg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'>
|
|
4560
4579
|
<path d='M5.87868 7.12132L8 9.24264L10.1213 7.12132' stroke='currentColor' stroke-opacity="0.9" stroke-linecap='round'/>
|
|
4561
4580
|
</svg>
|
|
4562
|
-
|
|
4563
|
-
${this.options
|
|
4564
|
-
.map((option) => `<option>${option}</option>`)
|
|
4565
|
-
.join("")}
|
|
4566
|
-
</fig-dropdown>
|
|
4581
|
+
${dropdownHTML}
|
|
4567
4582
|
</fig-button>
|
|
4568
4583
|
</div>`;
|
|
4569
4584
|
requestAnimationFrame(() => {
|
|
4570
4585
|
this.input = this.querySelector("fig-input-text");
|
|
4586
|
+
const button = this.querySelector("fig-button");
|
|
4587
|
+
|
|
4588
|
+
if (this.#usesCustomDropdown && customDropdown && button) {
|
|
4589
|
+
if (!customDropdown.hasAttribute("type")) {
|
|
4590
|
+
customDropdown.setAttribute("type", "dropdown");
|
|
4591
|
+
}
|
|
4592
|
+
if (experimental) {
|
|
4593
|
+
customDropdown.setAttribute("experimental", experimental);
|
|
4594
|
+
}
|
|
4595
|
+
button.append(customDropdown);
|
|
4596
|
+
}
|
|
4571
4597
|
this.dropdown = this.querySelector("fig-dropdown");
|
|
4572
4598
|
|
|
4573
|
-
this.dropdown
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
)
|
|
4599
|
+
this.dropdown?.removeEventListener("input", this.#boundHandleSelectInput);
|
|
4600
|
+
this.dropdown?.addEventListener("input", this.#boundHandleSelectInput);
|
|
4601
|
+
|
|
4602
|
+
if (this.input) {
|
|
4603
|
+
this.input.setAttribute("value", this.value);
|
|
4604
|
+
}
|
|
4577
4605
|
|
|
4578
4606
|
// Apply initial disabled state
|
|
4579
4607
|
if (this.hasAttribute("disabled")) {
|
|
@@ -4581,6 +4609,9 @@ class FigComboInput extends HTMLElement {
|
|
|
4581
4609
|
}
|
|
4582
4610
|
});
|
|
4583
4611
|
}
|
|
4612
|
+
disconnectedCallback() {
|
|
4613
|
+
this.dropdown?.removeEventListener("input", this.#boundHandleSelectInput);
|
|
4614
|
+
}
|
|
4584
4615
|
handleSelectInput(e) {
|
|
4585
4616
|
this.setAttribute("value", e.target.closest("fig-dropdown").value);
|
|
4586
4617
|
}
|
|
@@ -4614,7 +4645,7 @@ class FigComboInput extends HTMLElement {
|
|
|
4614
4645
|
switch (name) {
|
|
4615
4646
|
case "options":
|
|
4616
4647
|
this.options = newValue.split(",");
|
|
4617
|
-
if (this.dropdown) {
|
|
4648
|
+
if (this.dropdown && !this.#usesCustomDropdown) {
|
|
4618
4649
|
this.dropdown.innerHTML = this.options
|
|
4619
4650
|
.map((option) => `<option>${option}</option>`)
|
|
4620
4651
|
.join("");
|
|
@@ -4639,7 +4670,7 @@ class FigComboInput extends HTMLElement {
|
|
|
4639
4670
|
if (this.dropdown) {
|
|
4640
4671
|
if (newValue) {
|
|
4641
4672
|
this.dropdown.setAttribute("experimental", newValue);
|
|
4642
|
-
} else {
|
|
4673
|
+
} else if (!this.#usesCustomDropdown) {
|
|
4643
4674
|
this.dropdown.removeAttribute("experimental");
|
|
4644
4675
|
}
|
|
4645
4676
|
}
|
package/package.json
CHANGED