@rogieking/figui3 1.0.33 → 1.0.35

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 +54 -57
  2. package/package.json +1 -1
package/fig.js CHANGED
@@ -11,44 +11,44 @@ class FigButton extends HTMLElement {
11
11
  #selected;
12
12
  constructor() {
13
13
  super();
14
- //this.attachShadow({ mode: 'open' })
14
+ this.attachShadow({ mode: "open" });
15
15
  }
16
16
  connectedCallback() {
17
17
  this.render();
18
18
  }
19
19
  render() {
20
20
  this.#type = this.getAttribute("type") || "button";
21
- /*this.shadowRoot.innerHTML = `
21
+ this.shadowRoot.innerHTML = `
22
22
  <style>
23
23
  button, button:hover, button:active {
24
- padding: 0;
24
+ padding: 0 var(--spacer-2);
25
25
  appearance: none;
26
26
  display: flex;
27
27
  border: 0;
28
+ flex: 1;
29
+ text-align: center;
30
+ align-items: stretch;
31
+ justify-content: center;
28
32
  font: inherit;
29
33
  color: inherit;
30
34
  outline: 0;
31
35
  place-items: center;
32
36
  background: transparent;
37
+ margin: calc(var(--spacer-2)*-1);
38
+ height: var(--spacer-4);
33
39
  }
34
40
  </style>
35
41
  <button type="${this.#type}">
36
42
  <slot></slot>
37
43
  </button>
38
- `;*/
44
+ `;
39
45
 
40
46
  this.#selected =
41
47
  this.hasAttribute("selected") &&
42
48
  this.getAttribute("selected") !== "false";
43
49
  this.addEventListener("click", this.handleClick.bind(this));
44
50
 
45
- //child nodes hack
46
- requestAnimationFrame(() => {
47
- this.innerHTML = `<button type="${this.#type}">${
48
- this.innerHTML
49
- }</button>`;
50
- this.button = this.querySelector("button");
51
- });
51
+ this.button = this.querySelector("button");
52
52
  }
53
53
  get type() {
54
54
  return this.#type;
@@ -603,22 +603,18 @@ class FigSlider extends HTMLElement {
603
603
 
604
604
  this.innerHTML = html;
605
605
 
606
- this.textInput = this.querySelector("input[type=number]");
607
-
608
- this.input = this.querySelector("[type=range]");
609
- this.input.addEventListener("input", this.handleInput.bind(this));
610
- this.handleInput();
611
-
612
- if (this.textInput) {
613
- this.textInput.addEventListener("input", this.handleTextInput.bind(this));
614
- }
615
-
616
- if (this.default) {
617
- this.style.setProperty("--default", this.calculateNormal(this.default));
618
- }
619
606
  //child nodes hack
620
607
  requestAnimationFrame(() => {
608
+ this.input = this.querySelector("[type=range]");
609
+ this.input.addEventListener("input", this.handleInput.bind(this));
610
+ this.handleInput();
611
+
612
+ if (this.default) {
613
+ this.style.setProperty("--default", this.calculateNormal(this.default));
614
+ }
615
+
621
616
  this.datalist = this.querySelector("datalist");
617
+ this.textInput = this.querySelector("input[type=number]");
622
618
  if (this.datalist) {
623
619
  this.datalist.setAttribute(
624
620
  "id",
@@ -626,6 +622,12 @@ class FigSlider extends HTMLElement {
626
622
  );
627
623
  this.input.setAttribute("list", this.datalist.getAttribute("id"));
628
624
  }
625
+ if (this.textInput) {
626
+ this.textInput.addEventListener(
627
+ "input",
628
+ this.handleTextInput.bind(this)
629
+ );
630
+ }
629
631
  });
630
632
  }
631
633
  static get observedAttributes() {
@@ -680,6 +682,7 @@ class FigSlider extends HTMLElement {
680
682
 
681
683
  handleInput() {
682
684
  let val = Number(this.input.value);
685
+ console.log(val);
683
686
  this.value = val;
684
687
  let complete = this.calculateNormal(val);
685
688
  this.style.setProperty("--slider-complete", complete);
@@ -712,9 +715,6 @@ class FigInputText extends HTMLElement {
712
715
  }
713
716
  this.innerHTML = html;
714
717
 
715
- this.input = this.querySelector("input,textarea");
716
- this.input.addEventListener("input", this.handleInput.bind(this));
717
-
718
718
  if (prepend) {
719
719
  prepend.addEventListener("click", this.focus.bind(this));
720
720
  this.prepend(prepend);
@@ -723,6 +723,22 @@ class FigInputText extends HTMLElement {
723
723
  append.addEventListener("click", this.focus.bind(this));
724
724
  this.append(append);
725
725
  }
726
+
727
+ //child nodes hack
728
+ requestAnimationFrame(() => {
729
+ this.input = this.querySelector("input,textarea");
730
+
731
+ if (this.getAttribute("min")) {
732
+ this.input.setAttribute("min", this.getAttribute("min"));
733
+ }
734
+ if (this.getAttribute("max")) {
735
+ this.input.setAttribute("max", this.getAttribute("max"));
736
+ }
737
+ if (this.getAttribute("step")) {
738
+ this.input.setAttribute("step", this.getAttribute("step"));
739
+ }
740
+ this.input.addEventListener("input", this.handleInput.bind(this));
741
+ });
726
742
  }
727
743
  focus() {
728
744
  this.input.focus();
@@ -732,7 +748,16 @@ class FigInputText extends HTMLElement {
732
748
  }
733
749
 
734
750
  static get observedAttributes() {
735
- return ["value", "placeholder", "label", "disabled", "type"];
751
+ return [
752
+ "value",
753
+ "placeholder",
754
+ "label",
755
+ "disabled",
756
+ "type",
757
+ "step",
758
+ "min",
759
+ "max",
760
+ ];
736
761
  }
737
762
 
738
763
  attributeChangedCallback(name, oldValue, newValue) {
@@ -743,6 +768,7 @@ class FigInputText extends HTMLElement {
743
768
  break;
744
769
  default:
745
770
  this[name] = this.input[name] = newValue;
771
+ this.input.setAttribute(name, newValue);
746
772
  break;
747
773
  }
748
774
  }
@@ -1051,7 +1077,6 @@ class FigCheckbox extends HTMLElement {
1051
1077
  }
1052
1078
 
1053
1079
  attributeChangedCallback(name, oldValue, newValue) {
1054
- console.log(`Attribute ${name} change:`, oldValue, newValue);
1055
1080
  switch (name) {
1056
1081
  case "label":
1057
1082
  this.labelElement.innerText = newValue;
@@ -1096,31 +1121,3 @@ class FigSwitch extends FigCheckbox {
1096
1121
  }
1097
1122
  }
1098
1123
  window.customElements.define("fig-switch", FigSwitch);
1099
-
1100
- /* Template */
1101
- class MyCustomElement extends HTMLElement {
1102
- static observedAttributes = ["color", "size"];
1103
-
1104
- constructor() {
1105
- // Always call super first in constructor
1106
- super();
1107
- }
1108
-
1109
- connectedCallback() {
1110
- console.log("Custom element added to page.");
1111
- }
1112
-
1113
- disconnectedCallback() {
1114
- console.log("Custom element removed from page.");
1115
- }
1116
-
1117
- adoptedCallback() {
1118
- console.log("Custom element moved to new page.");
1119
- }
1120
-
1121
- attributeChangedCallback(name, oldValue, newValue) {
1122
- console.log(`Attribute ${name} has changed.`);
1123
- }
1124
- }
1125
-
1126
- customElements.define("my-custom-element", MyCustomElement);
package/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "1.0.33"
3
+ "version": "1.0.35"
4
4
  }