@rogieking/figui3 1.7.0 → 1.7.1
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/components.css +5 -0
- package/example.html +9 -2
- package/fig.js +36 -1
- package/package.json +1 -1
package/components.css
CHANGED
package/example.html
CHANGED
|
@@ -240,9 +240,16 @@
|
|
|
240
240
|
</fig-header>
|
|
241
241
|
<fig-field>
|
|
242
242
|
<fig-tabs>
|
|
243
|
-
<fig-tab selected
|
|
244
|
-
|
|
243
|
+
<fig-tab selected
|
|
244
|
+
content="#tab-1-content">Tab #1</fig-tab>
|
|
245
|
+
<fig-tab content="#tab-2-content">Tab #2</fig-tab>
|
|
245
246
|
</fig-tabs>
|
|
247
|
+
<fig-tab-content id="tab-1-content">
|
|
248
|
+
Content for Tab #1
|
|
249
|
+
</fig-tab-content>
|
|
250
|
+
<fig-tab-content id="tab-2-content">
|
|
251
|
+
Content for Tab #2
|
|
252
|
+
</fig-tab-content>
|
|
246
253
|
</fig-field>
|
|
247
254
|
<fig-header>
|
|
248
255
|
<h2>Segmented control</h2>
|
package/fig.js
CHANGED
|
@@ -529,18 +529,53 @@ window.customElements.define("fig-popover-2", FigPopover2);
|
|
|
529
529
|
* @attr {boolean} selected - Whether the tab is currently selected
|
|
530
530
|
*/
|
|
531
531
|
class FigTab extends HTMLElement {
|
|
532
|
+
#selected;
|
|
532
533
|
constructor() {
|
|
533
534
|
super();
|
|
535
|
+
this.content = null;
|
|
536
|
+
this.#selected = false;
|
|
534
537
|
}
|
|
535
538
|
connectedCallback() {
|
|
536
539
|
this.setAttribute("label", this.innerText);
|
|
537
540
|
this.addEventListener("click", this.handleClick.bind(this));
|
|
541
|
+
|
|
542
|
+
requestAnimationFrame(() => {
|
|
543
|
+
if (typeof this.getAttribute("content") === "string") {
|
|
544
|
+
this.content = document.querySelector(this.getAttribute("content"));
|
|
545
|
+
if (this.#selected) {
|
|
546
|
+
this.content.style.display = "block";
|
|
547
|
+
} else {
|
|
548
|
+
this.content.style.display = "none";
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
get selected() {
|
|
554
|
+
return this.#selected;
|
|
555
|
+
}
|
|
556
|
+
set selected(value) {
|
|
557
|
+
this.setAttribute("selected", value ? "true" : "false");
|
|
538
558
|
}
|
|
539
559
|
disconnectedCallback() {
|
|
540
560
|
this.removeEventListener("click", this.handleClick);
|
|
541
561
|
}
|
|
542
562
|
handleClick() {
|
|
543
|
-
this.
|
|
563
|
+
this.selected = true;
|
|
564
|
+
if (this.content) {
|
|
565
|
+
this.content.style.display = "block";
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
static get observedAttributes() {
|
|
570
|
+
return ["selected"];
|
|
571
|
+
}
|
|
572
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
573
|
+
if (name === "selected") {
|
|
574
|
+
this.#selected = newValue !== null && newValue !== "false";
|
|
575
|
+
if (this?.content) {
|
|
576
|
+
this.content.style.display = this.#selected ? "block" : "none";
|
|
577
|
+
}
|
|
578
|
+
}
|
|
544
579
|
}
|
|
545
580
|
}
|
|
546
581
|
window.customElements.define("fig-tab", FigTab);
|