@rogieking/figui3 1.0.97 → 1.0.99
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 +60 -9
- package/fig.css +30 -10
- package/fig.js +47 -5
- package/package.json +1 -1
package/example.html
CHANGED
|
@@ -64,15 +64,66 @@
|
|
|
64
64
|
<option selected>Fourhundred sixty two</option>
|
|
65
65
|
</fig-dropdown>
|
|
66
66
|
<br /><br />
|
|
67
|
-
<fig-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
67
|
+
<fig-field style="width:300px;">
|
|
68
|
+
<label>Range slider</label>
|
|
69
|
+
<fig-slider min="0"
|
|
70
|
+
max="1"
|
|
71
|
+
transform="100"
|
|
72
|
+
variant="minimal"
|
|
73
|
+
step="0.01"
|
|
74
|
+
text="true"
|
|
75
|
+
style="width:300px;"
|
|
76
|
+
value="0.5">
|
|
77
|
+
</fig-slider>
|
|
78
|
+
</fig-field>
|
|
79
|
+
<fig-field style="width:300px;">
|
|
80
|
+
<label>Opacity slider</label>
|
|
81
|
+
<fig-slider type="opacity"
|
|
82
|
+
variant="minimal"
|
|
83
|
+
value="0.75"
|
|
84
|
+
color="#ff0000"
|
|
85
|
+
units="%"
|
|
86
|
+
text="true"></fig-slider>
|
|
87
|
+
</fig-field>
|
|
88
|
+
|
|
89
|
+
<fig-field style="width:300px;">
|
|
90
|
+
<label>Hue slider</label>
|
|
91
|
+
<fig-slider type="hue"
|
|
92
|
+
variant="minimal"
|
|
93
|
+
value="55"></fig-slider>
|
|
94
|
+
</fig-field>
|
|
95
|
+
|
|
96
|
+
<fig-field style="width:300px;">
|
|
97
|
+
<label>Stepper slider</label>
|
|
98
|
+
<fig-slider type="stepper"
|
|
99
|
+
variant="minimal"
|
|
100
|
+
value="25"
|
|
101
|
+
default="50"
|
|
102
|
+
step="25">
|
|
103
|
+
<datalist id="markers">
|
|
104
|
+
<option value="0"></option>
|
|
105
|
+
<option value="25"></option>
|
|
106
|
+
<option value="50"></option>
|
|
107
|
+
<option value="75"></option>
|
|
108
|
+
<option value="100"></option>
|
|
109
|
+
</datalist>
|
|
110
|
+
</fig-slider>
|
|
111
|
+
</fig-field>
|
|
112
|
+
|
|
113
|
+
<fig-field style="width:300px;">
|
|
114
|
+
<label>Delta slider</label>
|
|
115
|
+
<fig-slider type="delta"
|
|
116
|
+
variant="minimal"
|
|
117
|
+
value=".25"
|
|
118
|
+
default="0"
|
|
119
|
+
step="0.25"
|
|
120
|
+
max="5"
|
|
121
|
+
min="-5">
|
|
122
|
+
<datalist id="markers">
|
|
123
|
+
<option value="0"></option>
|
|
124
|
+
</datalist>
|
|
125
|
+
</fig-slider>
|
|
126
|
+
</fig-field>
|
|
76
127
|
<br />
|
|
77
128
|
<fig-input-text min="0"
|
|
78
129
|
max="1"
|
package/fig.css
CHANGED
|
@@ -1429,6 +1429,7 @@ details {
|
|
|
1429
1429
|
/* Sliders */
|
|
1430
1430
|
.fig-slider,
|
|
1431
1431
|
fig-slider {
|
|
1432
|
+
--slider-field-height: 1.5rem;
|
|
1432
1433
|
--slider-height: 1rem;
|
|
1433
1434
|
--slider-thumb-size: var(--slider-height);
|
|
1434
1435
|
--slider-percent: calc(var(--slider-complete) * 100%);
|
|
@@ -1442,16 +1443,20 @@ fig-slider {
|
|
|
1442
1443
|
0px 1px 3px 0px rgba(0, 0, 0, 0.1), 0px 3px 8px 0px rgba(0, 0, 0, 0.1),
|
|
1443
1444
|
0px 0px 0.5px 0px rgba(0, 0, 0, 0.18),
|
|
1444
1445
|
0 0 0 1px var(--figma-color-border-selected);
|
|
1446
|
+
--slider-transition: all 0.1s ease-in-out;
|
|
1445
1447
|
|
|
1446
1448
|
display: inline-flex;
|
|
1447
1449
|
align-items: center;
|
|
1448
1450
|
position: relative;
|
|
1451
|
+
height: var(--slider-field-height);
|
|
1452
|
+
transition: var(--slider-transition);
|
|
1449
1453
|
|
|
1450
1454
|
.fig-slider-input-container {
|
|
1451
1455
|
height: var(--slider-height);
|
|
1452
1456
|
position: relative;
|
|
1453
1457
|
display: block;
|
|
1454
1458
|
width: 100%;
|
|
1459
|
+
transition: var(--slider-transition);
|
|
1455
1460
|
|
|
1456
1461
|
/* Track */
|
|
1457
1462
|
&::before {
|
|
@@ -1548,6 +1553,7 @@ fig-slider {
|
|
|
1548
1553
|
display: block;
|
|
1549
1554
|
width: 100%;
|
|
1550
1555
|
background-color: transparent;
|
|
1556
|
+
transition: var(--slider-transition);
|
|
1551
1557
|
|
|
1552
1558
|
&:active::-webkit-slider-thumb {
|
|
1553
1559
|
cursor: grabbing;
|
|
@@ -1561,6 +1567,7 @@ fig-slider {
|
|
|
1561
1567
|
&::-webkit-slider-thumb {
|
|
1562
1568
|
appearance: none;
|
|
1563
1569
|
-webkit-appearance: none;
|
|
1570
|
+
transition: var(--slider-transition);
|
|
1564
1571
|
border-radius: 100%;
|
|
1565
1572
|
height: var(--slider-thumb-size);
|
|
1566
1573
|
width: var(--slider-thumb-size);
|
|
@@ -1594,6 +1601,7 @@ fig-slider {
|
|
|
1594
1601
|
&::-webkit-slider-runnable-track {
|
|
1595
1602
|
height: var(--slider-height);
|
|
1596
1603
|
background-color: transparent;
|
|
1604
|
+
transition: var(--slider-transition);
|
|
1597
1605
|
border-radius: calc(var(--slider-height) / 2);
|
|
1598
1606
|
box-shadow: inset 0 0 0 1px var(--figma-color-bordertranslucent);
|
|
1599
1607
|
background: var(--figma-color-bg-secondary);
|
|
@@ -1618,6 +1626,7 @@ fig-slider {
|
|
|
1618
1626
|
display: block;
|
|
1619
1627
|
width: 100%;
|
|
1620
1628
|
background-color: transparent;
|
|
1629
|
+
transition: var(--slider-transition);
|
|
1621
1630
|
|
|
1622
1631
|
&:focus {
|
|
1623
1632
|
outline: none;
|
|
@@ -1640,6 +1649,7 @@ fig-slider {
|
|
|
1640
1649
|
cursor: grab;
|
|
1641
1650
|
cursor: -moz-grab;
|
|
1642
1651
|
box-shadow: var(--slider-handle-shadow);
|
|
1652
|
+
transition: var(--slider-transition);
|
|
1643
1653
|
}
|
|
1644
1654
|
|
|
1645
1655
|
&:disabled {
|
|
@@ -1665,6 +1675,7 @@ fig-slider {
|
|
|
1665
1675
|
border-radius: calc(var(--slider-height) / 2);
|
|
1666
1676
|
box-shadow: inset 0 0 0 1px var(--figma-color-bordertranslucent);
|
|
1667
1677
|
background: var(--figma-color-bg-secondary);
|
|
1678
|
+
transition: var(--slider-transition);
|
|
1668
1679
|
}
|
|
1669
1680
|
|
|
1670
1681
|
&.hue::-moz-range-track {
|
|
@@ -1680,7 +1691,9 @@ fig-slider {
|
|
|
1680
1691
|
datalist {
|
|
1681
1692
|
position: absolute;
|
|
1682
1693
|
inset: 0;
|
|
1694
|
+
top: calc((var(--slider-field-height) - var(--slider-height))/2);
|
|
1683
1695
|
display: flex;
|
|
1696
|
+
transition: var(--slider-transition);
|
|
1684
1697
|
background: transparent;
|
|
1685
1698
|
align-items: center;
|
|
1686
1699
|
margin: 0;
|
|
@@ -1709,13 +1722,12 @@ fig-slider {
|
|
|
1709
1722
|
}
|
|
1710
1723
|
}
|
|
1711
1724
|
}
|
|
1712
|
-
|
|
1713
|
-
transition: all 0.2s ease-in-out;
|
|
1714
|
-
}
|
|
1725
|
+
|
|
1715
1726
|
&[variant="minimal"] {
|
|
1716
1727
|
--slider-height: 0.25rem;
|
|
1717
1728
|
--slider-thumb-size: 0.5rem;
|
|
1718
|
-
|
|
1729
|
+
--slider-tick-size: calc(var(--slider-height) / 2);
|
|
1730
|
+
|
|
1719
1731
|
.fig-slider-input-container {
|
|
1720
1732
|
height: var(--slider-height);
|
|
1721
1733
|
position: relative;
|
|
@@ -1742,14 +1754,21 @@ fig-slider {
|
|
|
1742
1754
|
&:focus-within {
|
|
1743
1755
|
--slider-height: 1rem;
|
|
1744
1756
|
--slider-thumb-size: 1rem;
|
|
1757
|
+
--slider-tick-size: calc(var(--slider-height) / 4);
|
|
1745
1758
|
.fig-slider-input-container {
|
|
1746
|
-
|
|
1747
|
-
|
|
1759
|
+
&::before {
|
|
1760
|
+
box-shadow: inset 0 0 0 1px var(--figma-color-bordertranslucent);
|
|
1761
|
+
background: var(--figma-color-bg-brand);
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
input[type="range"] {
|
|
1765
|
+
&::-webkit-slider-runnable-track {
|
|
1766
|
+
box-shadow: inset 0 0 0 1px var(--figma-color-bordertranslucent);
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1769
|
+
fig-input-text {
|
|
1770
|
+
height: auto;
|
|
1748
1771
|
}
|
|
1749
|
-
}
|
|
1750
|
-
fig-input-text {
|
|
1751
|
-
height: auto;
|
|
1752
|
-
}
|
|
1753
1772
|
}
|
|
1754
1773
|
}
|
|
1755
1774
|
}
|
|
@@ -2169,6 +2188,7 @@ fig-field,
|
|
|
2169
2188
|
flex: 0;
|
|
2170
2189
|
padding: var(--spacer-1) 0;
|
|
2171
2190
|
display: flex;
|
|
2191
|
+
justify-content: space-between;
|
|
2172
2192
|
min-height: calc(1rem + var(--spacer-1) * 2);
|
|
2173
2193
|
align-items: center;
|
|
2174
2194
|
}
|
package/fig.js
CHANGED
|
@@ -842,9 +842,18 @@ class FigSlider extends HTMLElement {
|
|
|
842
842
|
window.customElements.define("fig-slider", FigSlider);
|
|
843
843
|
|
|
844
844
|
class FigInputText extends HTMLElement {
|
|
845
|
+
#boundMouseMove;
|
|
846
|
+
#boundMouseUp;
|
|
847
|
+
#boundMouseDown;
|
|
848
|
+
|
|
845
849
|
constructor() {
|
|
846
850
|
super();
|
|
851
|
+
// Pre-bind the event handlers once
|
|
852
|
+
this.#boundMouseMove = this.#handleMouseMove.bind(this);
|
|
853
|
+
this.#boundMouseUp = this.#handleMouseUp.bind(this);
|
|
854
|
+
this.#boundMouseDown = this.#handleMouseDown.bind(this);
|
|
847
855
|
}
|
|
856
|
+
|
|
848
857
|
connectedCallback() {
|
|
849
858
|
this.multiline = this.hasAttribute("multiline") || false;
|
|
850
859
|
this.value = this.getAttribute("value") || "";
|
|
@@ -904,6 +913,7 @@ class FigInputText extends HTMLElement {
|
|
|
904
913
|
if (this.getAttribute("step")) {
|
|
905
914
|
this.input.setAttribute("step", this.#transformNumber(this.step));
|
|
906
915
|
}
|
|
916
|
+
this.addEventListener("pointerdown", this.#boundMouseDown);
|
|
907
917
|
}
|
|
908
918
|
this.input.addEventListener("input", this.#handleInput.bind(this));
|
|
909
919
|
});
|
|
@@ -912,15 +922,47 @@ class FigInputText extends HTMLElement {
|
|
|
912
922
|
this.input.focus();
|
|
913
923
|
}
|
|
914
924
|
#transformNumber(value) {
|
|
915
|
-
return value * (this.transform || 1);
|
|
925
|
+
return Number(value) * (this.transform || 1);
|
|
916
926
|
}
|
|
917
927
|
#handleInput(e) {
|
|
918
928
|
let value = e.target.value;
|
|
919
929
|
if (this.type === "number") {
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
930
|
+
if (this.min) {
|
|
931
|
+
value = Math.min(this.min, value);
|
|
932
|
+
}
|
|
933
|
+
if (this.max) {
|
|
934
|
+
value = Math.max(this.max, value);
|
|
935
|
+
}
|
|
936
|
+
value = value / (this.transform || 1);
|
|
923
937
|
}
|
|
938
|
+
this.value = value;
|
|
939
|
+
}
|
|
940
|
+
#handleMouseMove(e) {
|
|
941
|
+
if (e.altKey) {
|
|
942
|
+
const step = (this.step || 1) * e.movementX;
|
|
943
|
+
const value = Number(this.input.value) + step;
|
|
944
|
+
this.setAttribute("value", value / this.transform);
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
#handleMouseDown(e) {
|
|
948
|
+
if (e.altKey) {
|
|
949
|
+
this.input.style.cursor =
|
|
950
|
+
this.style.cursor =
|
|
951
|
+
document.body.style.cursor =
|
|
952
|
+
"ew-resize";
|
|
953
|
+
// Use the pre-bound handlers
|
|
954
|
+
window.addEventListener("pointermove", this.#boundMouseMove);
|
|
955
|
+
window.addEventListener("pointerup", this.#boundMouseUp);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
#handleMouseUp(e) {
|
|
959
|
+
this.input.style.cursor =
|
|
960
|
+
this.style.cursor =
|
|
961
|
+
document.body.style.cursor =
|
|
962
|
+
"";
|
|
963
|
+
// Remove the pre-bound handlers
|
|
964
|
+
window.removeEventListener("pointermove", this.#boundMouseMove);
|
|
965
|
+
window.removeEventListener("pointerup", this.#boundMouseUp);
|
|
924
966
|
}
|
|
925
967
|
|
|
926
968
|
static get observedAttributes() {
|
|
@@ -1461,7 +1503,7 @@ class FigChit extends HTMLElement {
|
|
|
1461
1503
|
this.src = this.getAttribute("src") || "";
|
|
1462
1504
|
this.value = this.getAttribute("value") || "";
|
|
1463
1505
|
this.size = this.getAttribute("size") || "small";
|
|
1464
|
-
this.disabled = this.getAttribute("disabled") === "true"
|
|
1506
|
+
this.disabled = this.getAttribute("disabled") === "true";
|
|
1465
1507
|
this.innerHTML = `<input type="color" value="${this.value}" />`;
|
|
1466
1508
|
this.#updateSrc(this.src);
|
|
1467
1509
|
|