@rogieking/figui3 1.0.38 → 1.0.39

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 +17 -0
  2. package/fig.css +52 -8
  3. package/fig.js +69 -27
  4. package/package.json +1 -1
package/example.html CHANGED
@@ -81,6 +81,23 @@
81
81
  placeholder="Type of residence">
82
82
 
83
83
  </fig-combo-input>
84
+ <br /><br />
85
+ <hstack>
86
+ <fig-chit type="color"
87
+ disabled="true"
88
+ value="#00FF00"></fig-chit>
89
+ <fig-chit type="color"
90
+ disabled="true"
91
+ value="#FF0000"></fig-chit>
92
+ <fig-chit type="image"
93
+ disabled="true"
94
+ size="large"
95
+ src="https://avatars.githubusercontent.com/u/12345678?v=4"></fig-chit>
96
+ <fig-chit type="image"
97
+ disabled="true"
98
+ size="large"
99
+ src="https://img.freepik.com/free-vector/gradient-grainy-gradient-background_23-2149922133.jpg?semt=ais_hybrid"></fig-chit>
100
+ </hstack>
84
101
  <br />
85
102
  <fig-tooltip text="Tooltip text">
86
103
  <p>Tooltip</p>
package/fig.css CHANGED
@@ -420,16 +420,19 @@
420
420
 
421
421
  color-scheme: light dark;
422
422
  /* Icons */
423
- --icon-chevron: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5.87868 7.12132L8 9.24264L10.1213 7.12132' stroke='rgb(0 0 0 / 50%)' stroke-linecap='round'/%3E%3C/svg%3E%0A");
423
+ --icon-chevron: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5.87868 7.12132L8 9.24264L10.1213 7.12132' stroke='rgb(0 0 0 / 90%)' stroke-linecap='round'/%3E%3C/svg%3E%0A");
424
424
 
425
425
  /* Elevations */
426
426
  --figma-elevation-100: 0px 0px 0.5px 0px rgba(0, 0, 0, 0.3),
427
427
  0px 1px 3px 0px rgba(0, 0, 0, 0.15);
428
+
429
+ --figma-elevation-200: 0px 1px 3px 0px rgba(0, 0, 0, 0.102),
430
+ 0px 3px 8px 0px rgba(0, 0, 0, 0.102), 0px 0px 0.5px 0px rgba(0, 0, 0, 0.18);
428
431
  }
429
432
 
430
433
  @media (prefers-color-scheme: dark) {
431
434
  :root {
432
- --icon-chevron: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5.87868 7.12132L8 9.24264L10.1213 7.12132' stroke='rgb(255 255 255 / 50%)' stroke-linecap='round'/%3E%3C/svg%3E%0A");
435
+ --icon-chevron: url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5.87868 7.12132L8 9.24264L10.1213 7.12132' stroke='rgb(255 255 255 / 100%)' stroke-linecap='round'/%3E%3C/svg%3E%0A");
433
436
  --handle-shadow: 0px 0 0 0.75px rgba(255, 255, 255, 0.1),
434
437
  0px 0px 0.5px 0px rgba(255, 255, 255, 0.1);
435
438
  --figma-color-bg-ghost-hover: rgba(255, 255, 255, 0.05);
@@ -882,15 +885,15 @@ fig-avatar::after,
882
885
 
883
886
  /* Color input */
884
887
  input[type="color"] {
885
- width: 14px;
886
- height: 14px;
888
+ width: 0.875rem;
889
+ height: 0.875rem;
887
890
  -webkit-appearance: none;
888
891
  appearance: none;
889
892
  border: 0;
890
893
  padding: 0;
891
894
  margin: 0;
892
895
  background: none;
893
- padding: 5px;
896
+ padding: 0.3125rem;
894
897
  flex-shrink: 0;
895
898
  box-sizing: content-box;
896
899
  border-radius: var(--radius-medium);
@@ -934,6 +937,49 @@ input[type="color"]::-webkit-color-swatch {
934
937
  );
935
938
  }
936
939
 
940
+ fig-chit {
941
+ display: inline-grid;
942
+ width: 1.5rem;
943
+ height: 1.5rem;
944
+ border-radius: var(--radius-medium);
945
+
946
+ &[size="large"] {
947
+ width: 1.75rem;
948
+ height: 1.75rem;
949
+
950
+ &[type="image"]::after,
951
+ input[type="color"] {
952
+ padding: 0;
953
+ width: 1.75rem;
954
+ height: 1.75rem;
955
+ border-radius: var(--radius-medium);
956
+ }
957
+ }
958
+
959
+ &[type="image"] {
960
+ &::after {
961
+ content: "";
962
+ width: 0.875rem;
963
+ height: 0.875rem;
964
+ background-image: var(--src);
965
+ border-radius: 0.125rem;
966
+ background-size: cover;
967
+ box-shadow: inset 0 0 0 1px var(--figma-color-bordertranslucent);
968
+ }
969
+ &::after,
970
+ input {
971
+ grid-area: 1/1;
972
+ place-self: center;
973
+ }
974
+ input[type="color"]::-webkit-color-swatch-wrapper {
975
+ background: none;
976
+ }
977
+ input[type="color"]::-webkit-color-swatch {
978
+ opacity: 0;
979
+ }
980
+ }
981
+ }
982
+
937
983
  /* Combo input */
938
984
  .input-combo {
939
985
  display: inline-flex;
@@ -1246,9 +1292,7 @@ fig-slider {
1246
1292
  --slider-tick-size: calc(var(--slider-height) / 4);
1247
1293
  --slider-handle-shadow: inset 0 0 0 calc(4px + 0.5rem * var(--unchanged))
1248
1294
  var(--figma-color-icon-onbrand),
1249
- inset 0 0 0 5px rgba(0, 0, 0, 0.1), 0px 0 0 0.75px rgba(0, 0, 0, 0.1),
1250
- 0px 1px 3px 0px rgba(0, 0, 0, 0.1), 0px 3px 8px 0px rgba(0, 0, 0, 0.1),
1251
- 0px 0px 0.5px 0px rgba(0, 0, 0, 0.18);
1295
+ inset 0 0 0 5px rgba(0, 0, 0, 0.1), var(--figma-elevation-200);
1252
1296
  --slider-handle-shadow-focus: inset 0 0 0 4px var(--figma-color-icon-onbrand),
1253
1297
  inset 0 0 0 5px rgba(0, 0, 0, 0.1), 0px 0 0 0.75px rgba(0, 0, 0, 0.1),
1254
1298
  0px 1px 3px 0px rgba(0, 0, 0, 0.1), 0px 3px 8px 0px rgba(0, 0, 0, 0.1),
package/fig.js CHANGED
@@ -96,11 +96,8 @@ class FigDropdown extends HTMLElement {
96
96
  }
97
97
 
98
98
  connectedCallback() {
99
- this.render();
100
- }
101
-
102
- render() {
103
99
  this.type = this.getAttribute("type") || "select";
100
+ this.value = this.getAttribute("value") || "";
104
101
  this.select = document.createElement("select");
105
102
  this.optionsSlot = document.createElement("slot");
106
103
 
@@ -110,8 +107,9 @@ class FigDropdown extends HTMLElement {
110
107
  // Move slotted options into the select element
111
108
  this.optionsSlot.addEventListener("slotchange", this.slotChange.bind(this));
112
109
 
113
- this.select.addEventListener("change", this.handleChange.bind(this));
110
+ this.select.addEventListener("input", this.handleDropdownInput.bind(this));
114
111
  }
112
+
115
113
  slotChange() {
116
114
  while (this.select.firstChild) {
117
115
  this.select.firstChild.remove();
@@ -122,17 +120,22 @@ class FigDropdown extends HTMLElement {
122
120
  hiddenOption.setAttribute("selected", "true");
123
121
  this.select.appendChild(hiddenOption);
124
122
  }
125
- this.optionsSlot.assignedNodes().forEach((node) => {
126
- if (node.nodeName === "OPTION") {
127
- this.select.appendChild(node.cloneNode(true));
123
+ this.optionsSlot.assignedNodes().forEach((option) => {
124
+ if (option.nodeName === "OPTION") {
125
+ if (option.hasAttribute("value") && option.hasAttribute("selected")) {
126
+ this.value = option.getAttribute("value");
127
+ }
128
+ this.select.appendChild(option.cloneNode(true));
128
129
  }
129
130
  });
130
131
  if (this.type === "dropdown") {
131
132
  this.select.selectedIndex = -1;
132
133
  }
133
134
  }
134
- handleChange() {
135
+ handleDropdownInput() {
135
136
  if (this.type === "dropdown") {
137
+ this.value = this.select.value;
138
+ this.setAttribute("value", this.value);
136
139
  this.select.selectedIndex = -1;
137
140
  }
138
141
  }
@@ -908,20 +911,20 @@ class FigInputColor extends HTMLElement {
908
911
  </fig-tooltip>`;
909
912
  }
910
913
  html = `<div class="input-combo">
911
- <input type="color" value="${this.value}" />
914
+ <fig-chit type="color" disabled="false" value="${this.value}"></fig-chit>
912
915
  ${label}
913
916
  </div>`;
914
917
  } else {
915
- html = `<input type="color" value="${this.value}" />`;
918
+ html = `<fig-chit type="color" disabled="false" value="${this.value}"></fig-chit>`;
916
919
  }
917
920
  this.innerHTML = html;
918
921
 
919
922
  this.style.setProperty("--alpha", this.#rgba.a);
920
923
 
921
924
  requestAnimationFrame(() => {
922
- this.#swatch = this.querySelector("[type=color]");
923
- this.textInput = this.querySelector("[type=text]");
924
- this.#alphaInput = this.querySelector("[type=number]");
925
+ this.#swatch = this.querySelector("input[type=color]");
926
+ this.textInput = this.querySelector("input[type=text]");
927
+ this.#alphaInput = this.querySelector("input[type=number]");
925
928
 
926
929
  this.#swatch.disabled = this.hasAttribute("disabled");
927
930
  this.#swatch.addEventListener("input", this.handleInput.bind(this));
@@ -1234,28 +1237,24 @@ class FigComboInput extends HTMLElement {
1234
1237
  </fig-input-text>
1235
1238
  <fig-button type="select" variant="input" icon>
1236
1239
  <svg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'>
1237
- <path d='M5.87868 7.12132L8 9.24264L10.1213 7.12132' stroke='currentColor' stroke-opacity="0.5" stroke-linecap='round'/>
1240
+ <path d='M5.87868 7.12132L8 9.24264L10.1213 7.12132' stroke='currentColor' stroke-opacity="0.9" stroke-linecap='round'/>
1238
1241
  </svg>
1239
1242
  <fig-dropdown type="dropdown">
1240
- ${this.options
1241
- .map((option) => `<option>${option}</option>`)
1242
- .join("")}
1243
- </fig-dropdown>
1243
+ ${this.options
1244
+ .map((option) => `<option>${option}</option>`)
1245
+ .join("")}
1246
+ </fig-dropdown>
1244
1247
  </fig-button>
1245
1248
  </div>`;
1246
1249
  requestAnimationFrame(() => {
1247
1250
  this.input = this.querySelector("fig-input-text");
1248
- this.dropdown = this.querySelector("fig-dropdown");
1251
+ this.select = this.querySelector("fig-dropdown");
1249
1252
 
1250
- this.dropdown.addEventListener(
1251
- "input",
1252
- this.handleDropdownChange.bind(this)
1253
- );
1253
+ this.select.addEventListener("input", this.handleSelectInput.bind(this));
1254
1254
  });
1255
1255
  }
1256
- handleDropdownChange(e) {
1257
- console.log(e.target.value);
1258
- this.value = e.target.value;
1256
+ handleSelectInput(e) {
1257
+ this.value = e.target.parentNode.value;
1259
1258
  this.setAttribute("value", this.value);
1260
1259
  }
1261
1260
  handleInput(e) {
@@ -1283,3 +1282,46 @@ class FigComboInput extends HTMLElement {
1283
1282
  }
1284
1283
  }
1285
1284
  window.customElements.define("fig-combo-input", FigComboInput);
1285
+
1286
+ /* Chit */
1287
+ class FigChit extends HTMLElement {
1288
+ constructor() {
1289
+ super();
1290
+ }
1291
+ connectedCallback() {
1292
+ this.type = this.getAttribute("type") || "color";
1293
+ this.src = this.getAttribute("src") || "";
1294
+ this.value = this.getAttribute("value") || "";
1295
+ this.size = this.getAttribute("size") || "small";
1296
+ this.disabled = this.getAttribute("disabled") === "true" ? true : false;
1297
+ this.variant = this.getAttribute("variant") || "square";
1298
+ this.innerHTML = `<input type="color" value="${this.value}" />`;
1299
+
1300
+ requestAnimationFrame(() => {
1301
+ this.input = this.querySelector("input");
1302
+ this.input.disabled = this.disabled;
1303
+ this.updateSrc(this.src);
1304
+ });
1305
+ }
1306
+ updateSrc(src) {
1307
+ if (src) {
1308
+ this.src = src;
1309
+ this.style.setProperty("--src", `url(${src})`);
1310
+ } else {
1311
+ this.style.removeProperty("--src");
1312
+ }
1313
+ }
1314
+ static get observedAttributes() {
1315
+ return ["type", "src", "size", "variant", "value", "disabled"];
1316
+ }
1317
+ attributeChangedCallback(name, oldValue, newValue) {
1318
+ if (name === "src") {
1319
+ this.updateSrc(newValue);
1320
+ }
1321
+ if (name === "disabled") {
1322
+ this.disabled = newValue.toLowerCase() === "true";
1323
+ this.input.disabled = this.disabled;
1324
+ }
1325
+ }
1326
+ }
1327
+ window.customElements.define("fig-chit", FigChit);
package/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "1.0.38"
3
+ "version": "1.0.39"
4
4
  }