@rogieking/figui3 1.0.3 → 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.
Files changed (2) hide show
  1. package/fig.js +26 -52
  2. package/package.json +1 -1
package/fig.js CHANGED
@@ -109,7 +109,7 @@ class FigTooltip extends HTMLElement {
109
109
  this.popup = document.createElement('span');
110
110
  this.popup.setAttribute("class", "fig-tooltip")
111
111
  this.popup.style.position = "fixed"
112
- this.popup.style.display = "none"
112
+ this.popup.style.visibility = "hidden"
113
113
  this.popup.style.pointerEvents = "none"
114
114
  this.popup.innerText = this.getAttribute("text")
115
115
  document.body.append(this.popup)
@@ -177,6 +177,7 @@ class FigTooltip extends HTMLElement {
177
177
  this.popup.style.top = `${top}px`;
178
178
  this.popup.style.left = `${left}px`;
179
179
  this.popup.style.opacity = "1";
180
+ this.popup.style.visibility = "visible"
180
181
  this.popup.style.display = "block"
181
182
  this.popup.style.pointerEvents = "all"
182
183
  this.popup.style.zIndex = parseInt((new Date()).getTime() / 1000)
@@ -397,72 +398,42 @@ window.customElements.define('fig-popover-2', FigPopover2);
397
398
 
398
399
 
399
400
  /* Tabs */
400
- class FigTabs extends HTMLElement {
401
+ class FigTab extends HTMLElement {
401
402
  constructor() {
402
403
  super()
403
404
  }
404
405
  connectedCallback() {
405
- const tabs = this.querySelectorAll('fig-tab')
406
- const name = this.getAttribute("name") || ("tabs-" + this.uniqueId())
407
- for (const tab of tabs) {
408
- let input = document.createElement('input')
409
- input.type = "radio"
410
- input.name = name
411
- input.checked = tab.hasAttribute("selected")
412
- input.value = tab.getAttribute("value") || this.slugify(tab.innerText)
413
- tab.setAttribute("label", tab.innerText)
414
- tab.append(input)
415
- input.addEventListener("input", this.handleInput.bind(this))
416
- }
417
- }
418
- uniqueId() {
419
- return Date.now().toString(36) + Math.random().toString(36).substring(2)
420
- }
421
- slugify(text) {
422
- return text
423
- .toLowerCase()
424
- .trim()
425
- .replace(/[^\w\s-]/g, '')
426
- .replace(/[\s_-]+/g, '-')
427
- .replace(/^-+|-+$/g, '');
406
+ this.setAttribute("label", this.innerText)
407
+ this.addEventListener("click", this.handleClick.bind(this))
428
408
  }
429
- handleInput() {
430
- const radios = this.querySelectorAll("[type=radio]")
431
- for (const radio of radios) {
432
- if (radio.checked) {
433
- this.value = radio.value
434
- radio.parentNode.setAttribute("selected", "")
435
- } else {
436
- radio.parentNode.removeAttribute("selected")
437
- }
438
- }
409
+ handleClick() {
410
+ this.setAttribute("selected", "true")
439
411
  }
440
412
  }
441
- window.customElements.define('fig-tabs', FigTabs);
413
+ window.customElements.define('fig-tab', FigTab);
442
414
 
443
- /* Segmented Control */
444
- class FigSegmentedControl extends HTMLElement {
415
+ class FigTabs extends HTMLElement {
445
416
  constructor() {
446
417
  super()
447
418
  }
448
419
  connectedCallback() {
449
- const segments = this.querySelectorAll('fig-segment')
450
- const name = this.getAttribute("name") || "segmented-control"
451
- for (const segment of segments) {
452
- let input = document.createElement('input')
453
- input.type = "radio"
454
- input.name = name
455
- input.checked = segment.hasAttribute("selected")
456
- input.value = segment.getAttribute("value")
457
- segment.append(input)
458
- input.addEventListener("input", this.handleInput.bind(this))
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
+ }
459
433
  }
460
434
  }
461
- handleInput() {
462
- this.value = this.querySelector(":checked").value
463
- }
464
435
  }
465
- window.customElements.define('fig-segmented-control', FigSegmentedControl);
436
+ window.customElements.define('fig-tabs', FigTabs);
466
437
 
467
438
 
468
439
 
@@ -655,6 +626,9 @@ class FigField extends HTMLElement {
655
626
  }
656
627
  }
657
628
  focus() {
629
+ if (!this.input) {
630
+ this.input = Array.from(this.childNodes).find(node => node.nodeName.toLowerCase().startsWith("fig-"))
631
+ }
658
632
  console.log('input:', this.input)
659
633
  this.input.focus()
660
634
  }
package/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "1.0.3"
3
+ "version": "1.0.5"
4
4
  }