@rogieking/figui3 1.3.6 → 1.3.7
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/example.html +21 -0
- package/fig.css +4 -0
- package/fig.js +29 -19
- package/package.json +1 -1
package/example.html
CHANGED
|
@@ -23,6 +23,27 @@
|
|
|
23
23
|
<h2>UI3 Components</h2>
|
|
24
24
|
</fig-header>
|
|
25
25
|
<fig-content>
|
|
26
|
+
<fig-input-text type="number"
|
|
27
|
+
min="1"
|
|
28
|
+
style="width: 100px;"
|
|
29
|
+
max="2"
|
|
30
|
+
step="0.01"
|
|
31
|
+
value="1.5"
|
|
32
|
+
type="range"
|
|
33
|
+
units="%"
|
|
34
|
+
onInput="console.log(event.target.value)"
|
|
35
|
+
transform="100">
|
|
36
|
+
</fig-input-text>
|
|
37
|
+
<fig-slider min="1"
|
|
38
|
+
max="2"
|
|
39
|
+
step="0.01"
|
|
40
|
+
value="1.5"
|
|
41
|
+
type="range"
|
|
42
|
+
units="%"
|
|
43
|
+
text="true"
|
|
44
|
+
onInput="console.log(event.target.value)"
|
|
45
|
+
transform="100">
|
|
46
|
+
</fig-slider>
|
|
26
47
|
<fig-input-angle text="true"
|
|
27
48
|
value="0"
|
|
28
49
|
onInput="console.log(event.target.adjacent, event.target.opposite)"></fig-input-angle>
|
package/fig.css
CHANGED
|
@@ -2213,12 +2213,14 @@ fig-field,
|
|
|
2213
2213
|
justify-content: space-between;
|
|
2214
2214
|
min-height: calc(1rem + var(--spacer-1) * 2);
|
|
2215
2215
|
align-items: center;
|
|
2216
|
+
width: 100%;
|
|
2216
2217
|
}
|
|
2217
2218
|
|
|
2218
2219
|
&[direction="horizontal"] {
|
|
2219
2220
|
gap: var(--spacer-2);
|
|
2220
2221
|
align-items: start;
|
|
2221
2222
|
flex-direction: row;
|
|
2223
|
+
width: auto;
|
|
2222
2224
|
|
|
2223
2225
|
& > label {
|
|
2224
2226
|
min-width: 4rem;
|
|
@@ -2259,10 +2261,12 @@ fig-segmented-control {
|
|
|
2259
2261
|
justify-content: center;
|
|
2260
2262
|
position: relative;
|
|
2261
2263
|
appearance: none;
|
|
2264
|
+
color: var(--figma-color-text-secondary);
|
|
2262
2265
|
padding: 0 var(--spacer-2);
|
|
2263
2266
|
|
|
2264
2267
|
&[selected]:not([selected="false"]),
|
|
2265
2268
|
&[selected="true"] {
|
|
2269
|
+
color: var(--figma-color-text);
|
|
2266
2270
|
background-color: var(--figma-color-bg);
|
|
2267
2271
|
border-radius: calc(var(--radius-medium) - 1px);
|
|
2268
2272
|
box-shadow: 0 0 0 1px var(--figma-color-border);
|
package/fig.js
CHANGED
|
@@ -959,30 +959,42 @@ class FigInputText extends HTMLElement {
|
|
|
959
959
|
this.input.focus();
|
|
960
960
|
}
|
|
961
961
|
#transformNumber(value) {
|
|
962
|
-
|
|
962
|
+
if (value === "") return "";
|
|
963
|
+
let transformed = Number(value) * (this.transform || 1);
|
|
963
964
|
transformed = this.#formatNumber(transformed);
|
|
964
965
|
return transformed;
|
|
965
966
|
}
|
|
966
967
|
#handleInput(e) {
|
|
968
|
+
console.log("handleInput", e.target.value);
|
|
969
|
+
e.stopPropagation();
|
|
967
970
|
let value = e.target.value;
|
|
971
|
+
let valueTransformed = value;
|
|
968
972
|
if (this.type === "number") {
|
|
969
|
-
value = this.#sanitizeInput(value);
|
|
970
|
-
//value = Number(value);
|
|
971
973
|
value = value / (this.transform || 1);
|
|
974
|
+
value = this.#sanitizeInput(value, false);
|
|
975
|
+
valueTransformed = value * (this.transform || 1);
|
|
972
976
|
}
|
|
973
|
-
this.
|
|
977
|
+
this.value = value;
|
|
978
|
+
this.input.value = valueTransformed;
|
|
979
|
+
this.dispatchEvent(new CustomEvent("input", { bubbles: true }));
|
|
974
980
|
}
|
|
975
981
|
#handleMouseMove(e) {
|
|
982
|
+
if (this.type !== "number") return;
|
|
976
983
|
if (e.altKey) {
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
this
|
|
984
|
+
let step = (this.step || 1) * e.movementX;
|
|
985
|
+
let value = Number(this.input.value);
|
|
986
|
+
value = value / (this.transform || 1) + step;
|
|
987
|
+
value = this.#sanitizeInput(value, false);
|
|
988
|
+
let valueTransformed = value * (this.transform || 1);
|
|
989
|
+
value = this.#formatNumber(value);
|
|
990
|
+
valueTransformed = this.#formatNumber(valueTransformed);
|
|
991
|
+
this.value = value;
|
|
992
|
+
this.input.value = valueTransformed;
|
|
993
|
+
this.dispatchEvent(new CustomEvent("input", { bubbles: true }));
|
|
983
994
|
}
|
|
984
995
|
}
|
|
985
996
|
#handleMouseDown(e) {
|
|
997
|
+
if (this.type !== "number") return;
|
|
986
998
|
if (e.altKey) {
|
|
987
999
|
this.input.style.cursor =
|
|
988
1000
|
this.style.cursor =
|
|
@@ -995,6 +1007,7 @@ class FigInputText extends HTMLElement {
|
|
|
995
1007
|
}
|
|
996
1008
|
}
|
|
997
1009
|
#handleMouseUp(e) {
|
|
1010
|
+
if (this.type !== "number") return;
|
|
998
1011
|
this.input.style.cursor =
|
|
999
1012
|
this.style.cursor =
|
|
1000
1013
|
document.body.style.cursor =
|
|
@@ -1020,6 +1033,7 @@ class FigInputText extends HTMLElement {
|
|
|
1020
1033
|
sanitized
|
|
1021
1034
|
);
|
|
1022
1035
|
}
|
|
1036
|
+
|
|
1023
1037
|
sanitized = this.#formatNumber(sanitized);
|
|
1024
1038
|
}
|
|
1025
1039
|
return sanitized;
|
|
@@ -1056,18 +1070,15 @@ class FigInputText extends HTMLElement {
|
|
|
1056
1070
|
case "transform":
|
|
1057
1071
|
if (this.type === "number") {
|
|
1058
1072
|
this.transform = Number(newValue) || 1;
|
|
1059
|
-
this.
|
|
1060
|
-
this.max = this.#transformNumber(this.max);
|
|
1061
|
-
this.step = this.#transformNumber(this.step);
|
|
1062
|
-
this.value = this.#transformNumber(this.value);
|
|
1073
|
+
this.input.value = this.#transformNumber(this.value);
|
|
1063
1074
|
}
|
|
1064
1075
|
break;
|
|
1065
1076
|
case "value":
|
|
1066
1077
|
let value = newValue;
|
|
1067
1078
|
if (this.type === "number") {
|
|
1068
|
-
|
|
1069
|
-
this.value =
|
|
1070
|
-
this.input.value = this.#transformNumber(
|
|
1079
|
+
value = this.#sanitizeInput(value, false);
|
|
1080
|
+
this.value = value;
|
|
1081
|
+
this.input.value = this.#transformNumber(value);
|
|
1071
1082
|
} else {
|
|
1072
1083
|
this.value = value;
|
|
1073
1084
|
this.input.value = value;
|
|
@@ -1935,6 +1946,7 @@ class FigInputJoystick extends HTMLElement {
|
|
|
1935
1946
|
this.#updatePosition(e.touches[0]);
|
|
1936
1947
|
|
|
1937
1948
|
const handleTouchMove = (e) => {
|
|
1949
|
+
this.plane.classList.add("dragging");
|
|
1938
1950
|
if (this.isDragging) this.#updatePosition(e.touches[0]);
|
|
1939
1951
|
};
|
|
1940
1952
|
|
|
@@ -2251,5 +2263,3 @@ class FigInputAngle extends HTMLElement {
|
|
|
2251
2263
|
}
|
|
2252
2264
|
}
|
|
2253
2265
|
}
|
|
2254
|
-
|
|
2255
|
-
customElements.define("fig-input-angle", FigInputAngle);
|