@rogieking/figui3 2.13.2 → 2.14.0
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/components.css +1 -1
- package/fig.js +32 -6
- package/index.html +83 -0
- package/package.json +1 -1
package/components.css
CHANGED
package/fig.js
CHANGED
|
@@ -1445,6 +1445,9 @@ class FigSlider extends HTMLElement {
|
|
|
1445
1445
|
this.units = this.getAttribute("units") || "";
|
|
1446
1446
|
this.transform = Number(this.getAttribute("transform") || 1);
|
|
1447
1447
|
this.disabled = this.getAttribute("disabled") ? true : false;
|
|
1448
|
+
this.precision = this.hasAttribute("precision")
|
|
1449
|
+
? Number(this.getAttribute("precision"))
|
|
1450
|
+
: null;
|
|
1448
1451
|
|
|
1449
1452
|
const defaults = this.#typeDefaults[this.type];
|
|
1450
1453
|
this.min = Number(this.getAttribute("min") || defaults.min);
|
|
@@ -1481,7 +1484,8 @@ class FigSlider extends HTMLElement {
|
|
|
1481
1484
|
transform="${this.transform}"
|
|
1482
1485
|
step="${this.step}"
|
|
1483
1486
|
value="${this.value}"
|
|
1484
|
-
${this.units ? `units="${this.units}"` : ""}
|
|
1487
|
+
${this.units ? `units="${this.units}"` : ""}
|
|
1488
|
+
${this.precision !== null ? `precision="${this.precision}"` : ""}>
|
|
1485
1489
|
</fig-input-number>`;
|
|
1486
1490
|
} else {
|
|
1487
1491
|
html = slider;
|
|
@@ -1654,6 +1658,7 @@ class FigSlider extends HTMLElement {
|
|
|
1654
1658
|
"transform",
|
|
1655
1659
|
"text",
|
|
1656
1660
|
"default",
|
|
1661
|
+
"precision",
|
|
1657
1662
|
];
|
|
1658
1663
|
}
|
|
1659
1664
|
|
|
@@ -1690,6 +1695,16 @@ class FigSlider extends HTMLElement {
|
|
|
1690
1695
|
this.figInputNumber.setAttribute("transform", this.transform);
|
|
1691
1696
|
}
|
|
1692
1697
|
break;
|
|
1698
|
+
case "precision":
|
|
1699
|
+
this.precision = newValue !== null ? Number(newValue) : null;
|
|
1700
|
+
if (this.figInputNumber) {
|
|
1701
|
+
if (this.precision !== null) {
|
|
1702
|
+
this.figInputNumber.setAttribute("precision", this.precision);
|
|
1703
|
+
} else {
|
|
1704
|
+
this.figInputNumber.removeAttribute("precision");
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
break;
|
|
1693
1708
|
case "default":
|
|
1694
1709
|
this.default = newValue;
|
|
1695
1710
|
this.#syncProperties();
|
|
@@ -2011,6 +2026,7 @@ class FigInputNumber extends HTMLElement {
|
|
|
2011
2026
|
#boundKeyDown;
|
|
2012
2027
|
#units;
|
|
2013
2028
|
#unitPosition;
|
|
2029
|
+
#precision;
|
|
2014
2030
|
|
|
2015
2031
|
constructor() {
|
|
2016
2032
|
super();
|
|
@@ -2045,6 +2061,9 @@ class FigInputNumber extends HTMLElement {
|
|
|
2045
2061
|
this.name = this.getAttribute("name") || null;
|
|
2046
2062
|
this.#units = this.getAttribute("units") || "";
|
|
2047
2063
|
this.#unitPosition = this.getAttribute("unit-position") || "suffix";
|
|
2064
|
+
this.#precision = this.hasAttribute("precision")
|
|
2065
|
+
? Number(this.getAttribute("precision"))
|
|
2066
|
+
: 2;
|
|
2048
2067
|
|
|
2049
2068
|
if (this.getAttribute("step")) {
|
|
2050
2069
|
this.step = Number(this.getAttribute("step"));
|
|
@@ -2331,10 +2350,12 @@ class FigInputNumber extends HTMLElement {
|
|
|
2331
2350
|
return sanitized;
|
|
2332
2351
|
}
|
|
2333
2352
|
|
|
2334
|
-
#formatNumber(num
|
|
2335
|
-
|
|
2336
|
-
const
|
|
2337
|
-
|
|
2353
|
+
#formatNumber(num) {
|
|
2354
|
+
const precision = this.#precision ?? 2;
|
|
2355
|
+
const factor = Math.pow(10, precision);
|
|
2356
|
+
const rounded = Math.round(num * factor) / factor;
|
|
2357
|
+
// Only show decimals if needed and up to precision
|
|
2358
|
+
return Number.isInteger(rounded) ? rounded : parseFloat(rounded.toFixed(precision));
|
|
2338
2359
|
}
|
|
2339
2360
|
|
|
2340
2361
|
static get observedAttributes() {
|
|
@@ -2350,6 +2371,7 @@ class FigInputNumber extends HTMLElement {
|
|
|
2350
2371
|
"units",
|
|
2351
2372
|
"unit-position",
|
|
2352
2373
|
"steppers",
|
|
2374
|
+
"precision",
|
|
2353
2375
|
];
|
|
2354
2376
|
}
|
|
2355
2377
|
|
|
@@ -2386,6 +2408,10 @@ class FigInputNumber extends HTMLElement {
|
|
|
2386
2408
|
case "step":
|
|
2387
2409
|
this[name] = Number(newValue);
|
|
2388
2410
|
break;
|
|
2411
|
+
case "precision":
|
|
2412
|
+
this.#precision = newValue !== null ? Number(newValue) : 2;
|
|
2413
|
+
this.input.value = this.#formatWithUnit(this.value);
|
|
2414
|
+
break;
|
|
2389
2415
|
case "name":
|
|
2390
2416
|
this[name] = this.input[name] = newValue;
|
|
2391
2417
|
this.input.setAttribute("name", newValue);
|
|
@@ -5920,7 +5946,7 @@ class FigFillPicker extends HTMLElement {
|
|
|
5920
5946
|
|
|
5921
5947
|
container.innerHTML = `
|
|
5922
5948
|
<div class="fig-fill-picker-gradient-header">
|
|
5923
|
-
<fig-dropdown class="fig-fill-picker-gradient-type" value="${
|
|
5949
|
+
<fig-dropdown class="fig-fill-picker-gradient-type" variant="neue" value="${
|
|
5924
5950
|
this.#gradient.type
|
|
5925
5951
|
}">
|
|
5926
5952
|
<option value="linear" selected>Linear</option>
|
package/index.html
CHANGED
|
@@ -1840,6 +1840,31 @@
|
|
|
1840
1840
|
steppers="true"></fig-input-number>
|
|
1841
1841
|
</fig-field>
|
|
1842
1842
|
|
|
1843
|
+
<h3>With Precision</h3>
|
|
1844
|
+
<p class="description">Control decimal places with the <code>precision</code> attribute.</p>
|
|
1845
|
+
<fig-field direction="horizontal">
|
|
1846
|
+
<label>Default (2)</label>
|
|
1847
|
+
<fig-input-number value="3.14159"
|
|
1848
|
+
step="0.001"></fig-input-number>
|
|
1849
|
+
</fig-field>
|
|
1850
|
+
<fig-field direction="horizontal">
|
|
1851
|
+
<label>Precision 0</label>
|
|
1852
|
+
<fig-input-number value="3.14159"
|
|
1853
|
+
precision="0"></fig-input-number>
|
|
1854
|
+
</fig-field>
|
|
1855
|
+
<fig-field direction="horizontal">
|
|
1856
|
+
<label>Precision 1</label>
|
|
1857
|
+
<fig-input-number value="3.14159"
|
|
1858
|
+
precision="1"
|
|
1859
|
+
step="0.1"></fig-input-number>
|
|
1860
|
+
</fig-field>
|
|
1861
|
+
<fig-field direction="horizontal">
|
|
1862
|
+
<label>Precision 4</label>
|
|
1863
|
+
<fig-input-number value="3.14159"
|
|
1864
|
+
precision="4"
|
|
1865
|
+
step="0.0001"></fig-input-number>
|
|
1866
|
+
</fig-field>
|
|
1867
|
+
|
|
1843
1868
|
<h3>States</h3>
|
|
1844
1869
|
<fig-field direction="horizontal">
|
|
1845
1870
|
<label>Disabled</label>
|
|
@@ -2645,6 +2670,64 @@
|
|
|
2645
2670
|
text="true"
|
|
2646
2671
|
units="%"></fig-slider>
|
|
2647
2672
|
|
|
2673
|
+
<h3>With Precision</h3>
|
|
2674
|
+
<p class="description">Control decimal places in the text input with the <code>precision</code> attribute.</p>
|
|
2675
|
+
<fig-field direction="horizontal">
|
|
2676
|
+
<label>Precision 0</label>
|
|
2677
|
+
<fig-slider min="0"
|
|
2678
|
+
max="100"
|
|
2679
|
+
value="33"
|
|
2680
|
+
text="true"
|
|
2681
|
+
precision="0"></fig-slider>
|
|
2682
|
+
</fig-field>
|
|
2683
|
+
<fig-field direction="horizontal">
|
|
2684
|
+
<label>Precision 1</label>
|
|
2685
|
+
<fig-slider min="0"
|
|
2686
|
+
max="10"
|
|
2687
|
+
value="3.5"
|
|
2688
|
+
step="0.1"
|
|
2689
|
+
text="true"
|
|
2690
|
+
precision="1"></fig-slider>
|
|
2691
|
+
</fig-field>
|
|
2692
|
+
<fig-field direction="horizontal">
|
|
2693
|
+
<label>Precision 3</label>
|
|
2694
|
+
<fig-slider min="0"
|
|
2695
|
+
max="1"
|
|
2696
|
+
value="0.333"
|
|
2697
|
+
step="0.001"
|
|
2698
|
+
text="true"
|
|
2699
|
+
precision="3"></fig-slider>
|
|
2700
|
+
</fig-field>
|
|
2701
|
+
<fig-field direction="horizontal">
|
|
2702
|
+
<label>Neue - Precision 0</label>
|
|
2703
|
+
<fig-slider min="0"
|
|
2704
|
+
max="100"
|
|
2705
|
+
value="33"
|
|
2706
|
+
text="true"
|
|
2707
|
+
precision="0"
|
|
2708
|
+
variant="neue"></fig-slider>
|
|
2709
|
+
</fig-field>
|
|
2710
|
+
<fig-field direction="horizontal">
|
|
2711
|
+
<label>Neue - Precision 1</label>
|
|
2712
|
+
<fig-slider min="0"
|
|
2713
|
+
max="10"
|
|
2714
|
+
value="3.5"
|
|
2715
|
+
step="0.1"
|
|
2716
|
+
text="true"
|
|
2717
|
+
precision="1"
|
|
2718
|
+
variant="neue"></fig-slider>
|
|
2719
|
+
</fig-field>
|
|
2720
|
+
<fig-field direction="horizontal">
|
|
2721
|
+
<label>Neue - Precision 3</label>
|
|
2722
|
+
<fig-slider min="0"
|
|
2723
|
+
max="1"
|
|
2724
|
+
value="0.333"
|
|
2725
|
+
step="0.001"
|
|
2726
|
+
text="true"
|
|
2727
|
+
precision="3"
|
|
2728
|
+
variant="neue"></fig-slider>
|
|
2729
|
+
</fig-field>
|
|
2730
|
+
|
|
2648
2731
|
<h3>Variants</h3>
|
|
2649
2732
|
<fig-field direction="horizontal">
|
|
2650
2733
|
<label>Default</label>
|
package/package.json
CHANGED