@rogieking/figui3 1.0.4 → 1.0.5
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 +21 -51
- package/package.json +1 -1
package/fig.js
CHANGED
|
@@ -398,72 +398,42 @@ window.customElements.define('fig-popover-2', FigPopover2);
|
|
|
398
398
|
|
|
399
399
|
|
|
400
400
|
/* Tabs */
|
|
401
|
-
class
|
|
401
|
+
class FigTab extends HTMLElement {
|
|
402
402
|
constructor() {
|
|
403
403
|
super()
|
|
404
404
|
}
|
|
405
405
|
connectedCallback() {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
for (const tab of tabs) {
|
|
409
|
-
let input = document.createElement('input')
|
|
410
|
-
input.type = "radio"
|
|
411
|
-
input.name = name
|
|
412
|
-
input.checked = tab.hasAttribute("selected")
|
|
413
|
-
input.value = tab.getAttribute("value") || this.slugify(tab.innerText)
|
|
414
|
-
tab.setAttribute("label", tab.innerText)
|
|
415
|
-
tab.append(input)
|
|
416
|
-
input.addEventListener("input", this.handleInput.bind(this))
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
uniqueId() {
|
|
420
|
-
return Date.now().toString(36) + Math.random().toString(36).substring(2)
|
|
421
|
-
}
|
|
422
|
-
slugify(text) {
|
|
423
|
-
return text
|
|
424
|
-
.toLowerCase()
|
|
425
|
-
.trim()
|
|
426
|
-
.replace(/[^\w\s-]/g, '')
|
|
427
|
-
.replace(/[\s_-]+/g, '-')
|
|
428
|
-
.replace(/^-+|-+$/g, '');
|
|
406
|
+
this.setAttribute("label", this.innerText)
|
|
407
|
+
this.addEventListener("click", this.handleClick.bind(this))
|
|
429
408
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
for (const radio of radios) {
|
|
433
|
-
if (radio.checked) {
|
|
434
|
-
this.value = radio.value
|
|
435
|
-
radio.parentNode.setAttribute("selected", "")
|
|
436
|
-
} else {
|
|
437
|
-
radio.parentNode.removeAttribute("selected")
|
|
438
|
-
}
|
|
439
|
-
}
|
|
409
|
+
handleClick() {
|
|
410
|
+
this.setAttribute("selected", "true")
|
|
440
411
|
}
|
|
441
412
|
}
|
|
442
|
-
window.customElements.define('fig-
|
|
413
|
+
window.customElements.define('fig-tab', FigTab);
|
|
443
414
|
|
|
444
|
-
|
|
445
|
-
class FigSegmentedControl extends HTMLElement {
|
|
415
|
+
class FigTabs extends HTMLElement {
|
|
446
416
|
constructor() {
|
|
447
417
|
super()
|
|
448
418
|
}
|
|
449
419
|
connectedCallback() {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
420
|
+
this.name = this.getAttribute("name") || "tabs"
|
|
421
|
+
this.addEventListener("click", this.handleClick.bind(this))
|
|
422
|
+
}
|
|
423
|
+
handleClick(event) {
|
|
424
|
+
const target = event.target;
|
|
425
|
+
if (target.nodeName.toLowerCase() === "fig-tab") {
|
|
426
|
+
const tabs = this.querySelectorAll("fig-tab")
|
|
427
|
+
console.log("change", target, tabs, target.nodeName)
|
|
428
|
+
for (const tab of tabs) {
|
|
429
|
+
if (tab !== target) {
|
|
430
|
+
tab.removeAttribute("selected")
|
|
431
|
+
}
|
|
432
|
+
}
|
|
460
433
|
}
|
|
461
434
|
}
|
|
462
|
-
handleInput() {
|
|
463
|
-
this.value = this.querySelector(":checked").value
|
|
464
|
-
}
|
|
465
435
|
}
|
|
466
|
-
window.customElements.define('fig-
|
|
436
|
+
window.customElements.define('fig-tabs', FigTabs);
|
|
467
437
|
|
|
468
438
|
|
|
469
439
|
|
package/package.json
CHANGED