@rogieking/figui3 1.0.35 → 1.0.37

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 (4) hide show
  1. package/example.html +15 -2
  2. package/fig.css +48 -14
  3. package/fig.js +67 -12
  4. package/package.json +1 -1
package/example.html CHANGED
@@ -16,6 +16,9 @@
16
16
  <fig-header>
17
17
  <h3>UI3 Components</h3>
18
18
  </fig-header>
19
+ <fig-avatar src="https://avatars.githubusercontent.com/u/12345678?v=4"
20
+ name="John Doe"></fig-avatar>
21
+ <fig-avatar name="John Doe"></fig-avatar>
19
22
  <fig-content>
20
23
  <fig-tabs>
21
24
  <fig-tab selected>Tab #1</fig-tab>
@@ -114,6 +117,11 @@
114
117
  <fig-input-text type="number"
115
118
  value="10"></fig-input-text>
116
119
  <br /><br />
120
+ <fig-input-text value=""
121
+ placeholder="Number">
122
+ <span slot="prepend">X</span>
123
+ </fig-input-text>
124
+ <br /><br />
117
125
  <fig-field direction="horizontal">
118
126
  <label>Field label</label>
119
127
  <fig-input-text value=""
@@ -126,12 +134,15 @@
126
134
  </fig-field>
127
135
  <fig-field>
128
136
  <label>Default slider</label>
129
- <fig-slider></fig-slider>
137
+ <fig-slider default="25"
138
+ min="0"
139
+ max="500"></fig-slider>
130
140
  </fig-field>
131
141
 
132
142
  <fig-field>
133
143
  <label>Number slider (with number input)</label>
134
144
  <fig-slider text="true"
145
+ default="50"
135
146
  value="50"></fig-slider>
136
147
  </fig-field>
137
148
 
@@ -151,7 +162,9 @@
151
162
 
152
163
  <fig-field>
153
164
  <label>Stepper slider</label>
154
- <fig-slider value="50"
165
+ <fig-slider type="stepper"
166
+ value="25"
167
+ default="50"
155
168
  step="25">
156
169
  <datalist id="markers">
157
170
  <option value="0"></option>
package/fig.css CHANGED
@@ -841,7 +841,8 @@ fig-tabs,
841
841
  }
842
842
 
843
843
  /* Avatar */
844
- .avatar {
844
+ fig-avatar,
845
+ .fig-avatar {
845
846
  width: 1.5rem;
846
847
  display: inline-grid;
847
848
  place-items: center;
@@ -858,7 +859,8 @@ fig-tabs,
858
859
  }
859
860
  }
860
861
 
861
- .avatar img {
862
+ fig-avatar img,
863
+ .fig-avatar img {
862
864
  position: absolute;
863
865
  background: var(--checkerboard);
864
866
  width: 1.5rem;
@@ -867,7 +869,8 @@ fig-tabs,
867
869
  box-shadow: inset 0 0 0 1px var(--figma-color-bordertranslucent);
868
870
  }
869
871
 
870
- .avatar::after {
872
+ fig-avatar::after,
873
+ .fig-avatar::after {
871
874
  content: attr(initials);
872
875
  }
873
876
 
@@ -1098,9 +1101,9 @@ input[type="radio"] {
1098
1101
 
1099
1102
  &::after {
1100
1103
  content: "";
1101
- width: 0.5rem;
1102
- height: 0.5rem;
1103
- border-radius: 0.25rem;
1104
+ width: 0.375rem;
1105
+ height: 0.375rem;
1106
+ border-radius: 100%;
1104
1107
  background-color: var(--figma-color-text-onbrand);
1105
1108
  transform: scale(0);
1106
1109
  box-shadow: 0px 0 0 0.75px rgba(0, 0, 0, 0.1),
@@ -1235,7 +1238,8 @@ fig-slider {
1235
1238
  --slider-percent: calc(var(--slider-complete) * 100%);
1236
1239
  --start-percent: calc(var(--default, 0) * 100%);
1237
1240
  --slider-tick-size: calc(var(--slider-height) / 4);
1238
- --slider-handle-shadow: inset 0 0 0 4px var(--figma-color-icon-onbrand),
1241
+ --slider-handle-shadow: inset 0 0 0 calc(4px + 0.5rem * var(--unchanged))
1242
+ var(--figma-color-icon-onbrand),
1239
1243
  inset 0 0 0 5px rgba(0, 0, 0, 0.1), 0px 0 0 0.75px rgba(0, 0, 0, 0.1),
1240
1244
  0px 1px 3px 0px rgba(0, 0, 0, 0.1), 0px 3px 8px 0px rgba(0, 0, 0, 0.1),
1241
1245
  0px 0px 0.5px 0px rgba(0, 0, 0, 0.18);
@@ -1273,17 +1277,42 @@ fig-slider {
1273
1277
  max-width: 100%;
1274
1278
  }
1275
1279
  }
1280
+ &[type="stepper"] {
1281
+ .fig-slider-input-container {
1282
+ &::before {
1283
+ display: none;
1284
+ }
1285
+ /* Default tick */
1286
+ &::after {
1287
+ content: "";
1288
+ display: block;
1289
+ width: var(--slider-tick-size);
1290
+ height: var(--slider-tick-size);
1291
+ border-radius: 100%;
1292
+ background: var(--figma-color-icon);
1293
+ position: absolute;
1294
+ left: calc(var(--default) * 100% - var(--slider-tick-size) / 2);
1295
+ top: calc(50% - var(--slider-tick-size) / 2);
1296
+ }
1297
+ }
1298
+ }
1276
1299
 
1277
- /* TODO: Delta sizing */
1278
1300
  &[type="delta"] {
1279
1301
  .fig-slider-input-container {
1280
1302
  &::before {
1281
1303
  --left-start: calc(var(--start-percent) - var(--slider-height) / 2);
1282
- left: min(var(--left-start), var(--slider-percent));
1304
+ left: min(
1305
+ var(--left-start),
1306
+ var(--slider-percent) - (var(--slider-complete)) *
1307
+ var(--slider-height)
1308
+ );
1283
1309
  --width: calc(var(--slider-percent) - var(--start-percent));
1284
1310
  --abs-width: max(
1285
- var(--width) + var(--slider-height) / 2,
1286
- -1 * var(--width) + var(--slider-height) / 2
1311
+ var(--width) + var(--slider-height) / 2 + (1 - var(--slider-complete)) *
1312
+ var(--slider-height),
1313
+ -1 * var(--width) + var(--slider-height) / 2 + (
1314
+ var(--slider-complete)
1315
+ ) * var(--slider-height)
1287
1316
  );
1288
1317
  width: var(--abs-width);
1289
1318
  --delta: calc(var(--slider-complete) - var(--default));
@@ -1345,6 +1374,7 @@ fig-slider {
1345
1374
  aspect-ratio: 1;
1346
1375
  border: none;
1347
1376
  position: relative;
1377
+ z-index: 1;
1348
1378
  box-shadow: var(--slider-handle-shadow);
1349
1379
  }
1350
1380
 
@@ -1412,6 +1442,7 @@ fig-slider {
1412
1442
  aspect-ratio: 1;
1413
1443
  border: none;
1414
1444
  position: relative;
1445
+ z-index: 1;
1415
1446
  box-shadow: var(--slider-handle-shadow);
1416
1447
  }
1417
1448
 
@@ -1470,13 +1501,16 @@ fig-slider {
1470
1501
  width: var(--slider-tick-size);
1471
1502
  height: var(--slider-tick-size);
1472
1503
  aspect-ratio: 1;
1473
- margin: 0 auto;
1474
1504
  padding: 0;
1475
1505
  border: 0;
1476
1506
  border-radius: 100%;
1477
1507
  font-size: 0;
1478
1508
  background: var(--figma-color-icon-tertiary);
1479
1509
  display: block;
1510
+
1511
+ &:first-child:last-child {
1512
+ margin: 0 auto;
1513
+ }
1480
1514
  }
1481
1515
  }
1482
1516
  }
@@ -1772,9 +1806,9 @@ fig-input-text {
1772
1806
  }
1773
1807
 
1774
1808
  & [slot] {
1775
- padding: 0.25rem 0.5rem;
1776
- flex: 0;
1777
1809
  user-select: none;
1810
+ width: 1.5rem;
1811
+ margin-right: calc(var(--spacer-2) * -1);
1778
1812
  color: var(--figma-color-text-secondary);
1779
1813
  }
1780
1814
 
package/fig.js CHANGED
@@ -554,6 +554,7 @@ class FigSlider extends HTMLElement {
554
554
  range: { min: 0, max: 100, step: 1 },
555
555
  hue: { min: 0, max: 255, step: 1 },
556
556
  delta: { min: -100, max: 100, step: 1 },
557
+ stepper: { min: 0, max: 100, step: 25 },
557
558
  opacity: { min: 0, max: 1, step: 0.01, color: "#FF0000" },
558
559
  };
559
560
  constructor() {
@@ -640,7 +641,6 @@ class FigSlider extends HTMLElement {
640
641
 
641
642
  attributeChangedCallback(name, oldValue, newValue) {
642
643
  if (this.input) {
643
- console.log("attributeChangedCallback:", name, oldValue, newValue);
644
644
  switch (name) {
645
645
  case "color":
646
646
  this.color = newValue;
@@ -685,7 +685,10 @@ class FigSlider extends HTMLElement {
685
685
  console.log(val);
686
686
  this.value = val;
687
687
  let complete = this.calculateNormal(val);
688
+ let defaultValue = this.calculateNormal(this.default);
688
689
  this.style.setProperty("--slider-complete", complete);
690
+ this.style.setProperty("--default", defaultValue);
691
+ this.style.setProperty("--unchanged", complete === defaultValue ? 1 : 0);
689
692
  if (this.textInput) {
690
693
  this.textInput.value = val;
691
694
  }
@@ -698,8 +701,6 @@ class FigInputText extends HTMLElement {
698
701
  super();
699
702
  }
700
703
  connectedCallback() {
701
- const append = this.querySelector("[slot=append]");
702
- const prepend = this.querySelector("[slot=prepend]");
703
704
  this.multiline = this.hasAttribute("multiline") || false;
704
705
  this.value = this.getAttribute("value");
705
706
  this.type = this.getAttribute("type") || "text";
@@ -715,17 +716,22 @@ class FigInputText extends HTMLElement {
715
716
  }
716
717
  this.innerHTML = html;
717
718
 
718
- if (prepend) {
719
- prepend.addEventListener("click", this.focus.bind(this));
720
- this.prepend(prepend);
721
- }
722
- if (append) {
723
- append.addEventListener("click", this.focus.bind(this));
724
- this.append(append);
725
- }
726
-
727
719
  //child nodes hack
728
720
  requestAnimationFrame(() => {
721
+ const append = this.querySelector("[slot=append]");
722
+ const prepend = this.querySelector("[slot=prepend]");
723
+
724
+ console.log(append, prepend);
725
+
726
+ if (prepend) {
727
+ prepend.addEventListener("click", this.focus.bind(this));
728
+ this.prepend(prepend);
729
+ }
730
+ if (append) {
731
+ append.addEventListener("click", this.focus.bind(this));
732
+ this.append(append);
733
+ }
734
+
729
735
  this.input = this.querySelector("input,textarea");
730
736
 
731
737
  if (this.getAttribute("min")) {
@@ -776,6 +782,55 @@ class FigInputText extends HTMLElement {
776
782
  }
777
783
  window.customElements.define("fig-input-text", FigInputText);
778
784
 
785
+ /* Avatar */
786
+ class FigAvatar extends HTMLElement {
787
+ constructor() {
788
+ super();
789
+ }
790
+ connectedCallback() {
791
+ this.src = this.getAttribute("src");
792
+ this.name = this.getAttribute("name");
793
+ this.initials = this.getInitials(this.name);
794
+ this.setAttribute("initials", this.initials);
795
+ this.setSrc(this.src);
796
+ requestAnimationFrame(() => {
797
+ this.img = this.querySelector("img");
798
+ });
799
+ }
800
+ setSrc(src) {
801
+ this.src = src;
802
+ if (src) {
803
+ this.innerHTML = `<img src="${this.src}" ${
804
+ this.name ? `alt="${this.name}"` : ""
805
+ } />`;
806
+ }
807
+ }
808
+ getInitials(name) {
809
+ return name
810
+ ? name
811
+ .split(" ")
812
+ .map((n) => n[0])
813
+ .join("")
814
+ : "";
815
+ }
816
+ static get observedAttributes() {
817
+ return ["src", "href", "name"];
818
+ }
819
+ attributeChangedCallback(name, oldValue, newValue) {
820
+ this[name] = newValue;
821
+ if (name === "name") {
822
+ this.img.setAttribute("alt", newValue);
823
+ this.name = newValue;
824
+ this.initials = this.getInitials(this.name);
825
+ this.setAttribute("initials", this.initials);
826
+ } else if (name === "src") {
827
+ this.src = newValue;
828
+ this.setSrc(this.src);
829
+ }
830
+ }
831
+ }
832
+ window.customElements.define("fig-avatar", FigAvatar);
833
+
779
834
  /* Form Field */
780
835
  class FigField extends HTMLElement {
781
836
  constructor() {
package/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "1.0.35"
3
+ "version": "1.0.37"
4
4
  }