@rogieking/figui3 1.2.6 → 1.2.8

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 CHANGED
@@ -524,7 +524,7 @@
524
524
  <label>Stepper slider</label>
525
525
  <fig-slider type="stepper"
526
526
  value="25"
527
- default="50"
527
+ default="75"
528
528
  step="25">
529
529
  <datalist>
530
530
  <option value="0"></option>
@@ -535,12 +535,14 @@
535
535
  </datalist>
536
536
  </fig-slider>
537
537
  </fig-field>
538
- <fig-field>
538
+ <fig-field direction="horizontal">
539
539
  <label>Stepper slider (auto)</label>
540
540
  <fig-slider type="stepper"
541
- value="25"
542
- default="50"
543
- step="25">
541
+ value="3"
542
+ min="1"
543
+ max="10"
544
+ step="1"
545
+ text="true">
544
546
  </fig-slider>
545
547
  </fig-field>
546
548
 
package/fig.css CHANGED
@@ -1494,18 +1494,6 @@ fig-slider {
1494
1494
  &::before {
1495
1495
  display: none;
1496
1496
  }
1497
- /* Default tick */
1498
- &::after {
1499
- content: "";
1500
- display: block;
1501
- width: var(--slider-tick-size);
1502
- height: var(--slider-tick-size);
1503
- border-radius: 100%;
1504
- background: var(--figma-color-icon);
1505
- position: absolute;
1506
- left: calc(var(--default) * 100% - var(--slider-tick-size) / 2);
1507
- top: calc(50% - var(--slider-tick-size) / 2);
1508
- }
1509
1497
  }
1510
1498
  }
1511
1499
 
@@ -1704,7 +1692,7 @@ fig-slider {
1704
1692
  datalist {
1705
1693
  position: absolute;
1706
1694
  inset: 0;
1707
- top: calc((var(--slider-field-height) - var(--slider-height)) / 2);
1695
+ top: 0;
1708
1696
  display: flex;
1709
1697
  transition: var(--slider-transition);
1710
1698
  background: transparent;
@@ -1729,6 +1717,9 @@ fig-slider {
1729
1717
  font-size: 0;
1730
1718
  background: var(--figma-color-icon-tertiary);
1731
1719
  display: block;
1720
+ &[default] {
1721
+ background: var(--figma-color-icon);
1722
+ }
1732
1723
 
1733
1724
  &:first-child:last-child {
1734
1725
  margin: 0 auto;
package/fig.js CHANGED
@@ -673,7 +673,6 @@ class FigSlider extends HTMLElement {
673
673
  }
674
674
  #regenerateInnerHTML() {
675
675
  this.value = Number(this.getAttribute("value") || 0);
676
- this.default = this.getAttribute("default") || null;
677
676
  this.type = this.getAttribute("type") || "range";
678
677
  this.text = this.getAttribute("text") || false;
679
678
  this.units = this.getAttribute("units") || "";
@@ -685,6 +684,7 @@ class FigSlider extends HTMLElement {
685
684
  this.max = Number(this.getAttribute("max") || defaults.max);
686
685
  this.step = Number(this.getAttribute("step") || defaults.step);
687
686
  this.color = this.getAttribute("color") || defaults?.color;
687
+ this.default = this.getAttribute("default") || this.min;
688
688
 
689
689
  if (this.color) {
690
690
  this.style.setProperty("--color", this.color);
@@ -726,6 +726,7 @@ class FigSlider extends HTMLElement {
726
726
  //child nodes hack
727
727
  requestAnimationFrame(() => {
728
728
  this.input = this.querySelector("[type=range]");
729
+ this.inputContainer = this.querySelector(".fig-slider-input-container");
729
730
  this.input.removeEventListener("input", this.handleInput);
730
731
  this.input.addEventListener("input", this.handleInput.bind(this));
731
732
 
@@ -739,6 +740,7 @@ class FigSlider extends HTMLElement {
739
740
  this.datalist = this.querySelector("datalist");
740
741
  this.figInputText = this.querySelector("fig-input-text");
741
742
  if (this.datalist) {
743
+ this.inputContainer.append(this.datalist);
742
744
  this.datalist.setAttribute(
743
745
  "id",
744
746
  this.datalist.getAttribute("id") || figUniqueId()
@@ -753,9 +755,17 @@ class FigSlider extends HTMLElement {
753
755
  option.setAttribute("value", this.min + i * this.step);
754
756
  this.datalist.append(option);
755
757
  }
756
- this.append(this.datalist);
758
+ this.inputContainer.append(this.datalist);
757
759
  this.input.setAttribute("list", this.datalist.getAttribute("id"));
758
760
  }
761
+ if (this.datalist) {
762
+ let defaultOption = this.datalist.querySelector(
763
+ `option[value='${this.default}']`
764
+ );
765
+ if (defaultOption) {
766
+ defaultOption.setAttribute("default", "true");
767
+ }
768
+ }
759
769
  if (this.figInputText) {
760
770
  this.figInputText.removeEventListener("input", this.handleTextInput);
761
771
  this.figInputText.addEventListener(
@@ -841,15 +851,14 @@ class FigSlider extends HTMLElement {
841
851
  }
842
852
  }
843
853
  #calculateNormal(value) {
844
- let min = Number(this.input.min);
845
- let max = Number(this.input.max);
846
- let val = value;
847
- return (val - min) / (max - min);
854
+ let min = Number(this.min);
855
+ let max = Number(this.max);
856
+ return (Number(value) - min) / (max - min);
848
857
  }
849
858
  #syncProperties() {
850
859
  let complete = this.#calculateNormal(this.value);
851
- let defaultValue = this.#calculateNormal(this.default);
852
860
  this.style.setProperty("--slider-complete", complete);
861
+ let defaultValue = this.#calculateNormal(this.default);
853
862
  this.style.setProperty("--default", defaultValue);
854
863
  this.style.setProperty("--unchanged", complete === defaultValue ? 1 : 0);
855
864
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "devDependencies": {