@rogieking/figui3 1.0.38 → 1.0.40
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 +32 -0
- package/fig.css +71 -8
- package/fig.js +75 -28
- package/package.json +1 -1
package/example.html
CHANGED
|
@@ -81,6 +81,38 @@
|
|
|
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="gradient"
|
|
93
|
+
variant="linear"
|
|
94
|
+
size="large"
|
|
95
|
+
disabled="true"></fig-chit>
|
|
96
|
+
<fig-chit type="gradient"
|
|
97
|
+
variant="angular"
|
|
98
|
+
size="large"
|
|
99
|
+
disabled="true"></fig-chit>
|
|
100
|
+
<fig-chit type="gradient"
|
|
101
|
+
variant="radial"
|
|
102
|
+
size="large"
|
|
103
|
+
disabled="true"></fig-chit>
|
|
104
|
+
<fig-chit type="image"
|
|
105
|
+
disabled="true"
|
|
106
|
+
src="https://img.freepik.com/free-vector/gradient-grainy-gradient-background_23-2149922133.jpg?semt=ais_hybrid"></fig-chit>
|
|
107
|
+
<fig-chit type="image"
|
|
108
|
+
disabled="true"
|
|
109
|
+
size="large"
|
|
110
|
+
src="https://avatars.githubusercontent.com/u/12345678?v=4"></fig-chit>
|
|
111
|
+
<fig-chit type="image"
|
|
112
|
+
disabled="true"
|
|
113
|
+
size="large"
|
|
114
|
+
src="https://img.freepik.com/free-vector/gradient-grainy-gradient-background_23-2149922133.jpg?semt=ais_hybrid"></fig-chit>
|
|
115
|
+
</hstack>
|
|
84
116
|
<br />
|
|
85
117
|
<fig-tooltip text="Tooltip text">
|
|
86
118
|
<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 /
|
|
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 /
|
|
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:
|
|
886
|
-
height:
|
|
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:
|
|
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,68 @@ 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="gradient"]::after,
|
|
951
|
+
&[type="image"]::after,
|
|
952
|
+
input[type="color"] {
|
|
953
|
+
padding: 0;
|
|
954
|
+
width: 1.75rem;
|
|
955
|
+
height: 1.75rem;
|
|
956
|
+
border-radius: var(--radius-medium);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
&[disabled="true"] {
|
|
960
|
+
input {
|
|
961
|
+
pointer-events: none;
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
&[type="gradient"],
|
|
966
|
+
&[type="image"] {
|
|
967
|
+
&::after {
|
|
968
|
+
content: "";
|
|
969
|
+
width: 0.875rem;
|
|
970
|
+
height: 0.875rem;
|
|
971
|
+
background-image: var(--src);
|
|
972
|
+
border-radius: 0.125rem;
|
|
973
|
+
background-size: cover;
|
|
974
|
+
box-shadow: inset 0 0 0 1px var(--figma-color-bordertranslucent);
|
|
975
|
+
}
|
|
976
|
+
&::after,
|
|
977
|
+
input {
|
|
978
|
+
grid-area: 1/1;
|
|
979
|
+
place-self: center;
|
|
980
|
+
}
|
|
981
|
+
input[type="color"]::-webkit-color-swatch-wrapper {
|
|
982
|
+
background: none;
|
|
983
|
+
}
|
|
984
|
+
input[type="color"]::-webkit-color-swatch {
|
|
985
|
+
opacity: 0;
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
&[type="gradient"] {
|
|
990
|
+
&[variant="linear"]::after {
|
|
991
|
+
background: linear-gradient(to right, red, blue);
|
|
992
|
+
}
|
|
993
|
+
&[variant="angular"]::after {
|
|
994
|
+
background: conic-gradient(red, orange, yellow, green, blue);
|
|
995
|
+
}
|
|
996
|
+
&[variant="radial"]::after {
|
|
997
|
+
background: radial-gradient(circle, red, blue);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
}
|
|
1001
|
+
|
|
937
1002
|
/* Combo input */
|
|
938
1003
|
.input-combo {
|
|
939
1004
|
display: inline-flex;
|
|
@@ -1246,9 +1311,7 @@ fig-slider {
|
|
|
1246
1311
|
--slider-tick-size: calc(var(--slider-height) / 4);
|
|
1247
1312
|
--slider-handle-shadow: inset 0 0 0 calc(4px + 0.5rem * var(--unchanged))
|
|
1248
1313
|
var(--figma-color-icon-onbrand),
|
|
1249
|
-
inset 0 0 0 5px 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);
|
|
1314
|
+
inset 0 0 0 5px rgba(0, 0, 0, 0.1), var(--figma-elevation-200);
|
|
1252
1315
|
--slider-handle-shadow-focus: inset 0 0 0 4px var(--figma-color-icon-onbrand),
|
|
1253
1316
|
inset 0 0 0 5px rgba(0, 0, 0, 0.1), 0px 0 0 0.75px rgba(0, 0, 0, 0.1),
|
|
1254
1317
|
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("
|
|
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,20 +120,28 @@ class FigDropdown extends HTMLElement {
|
|
|
122
120
|
hiddenOption.setAttribute("selected", "true");
|
|
123
121
|
this.select.appendChild(hiddenOption);
|
|
124
122
|
}
|
|
125
|
-
this.optionsSlot.assignedNodes().forEach((
|
|
126
|
-
if (
|
|
127
|
-
|
|
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
|
-
|
|
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
|
}
|
|
142
|
+
focus() {
|
|
143
|
+
this.select.focus();
|
|
144
|
+
}
|
|
139
145
|
}
|
|
140
146
|
|
|
141
147
|
customElements.define("fig-dropdown", FigDropdown);
|
|
@@ -895,7 +901,7 @@ class FigInputColor extends HTMLElement {
|
|
|
895
901
|
let label = `<fig-input-text placeholder="Text" value="${this.getAttribute(
|
|
896
902
|
"value"
|
|
897
903
|
)}"></fig-input-text>`;
|
|
898
|
-
if (this.getAttribute("alpha")) {
|
|
904
|
+
if (this.getAttribute("alpha") === "true") {
|
|
899
905
|
label += `<fig-tooltip text="Opacity">
|
|
900
906
|
<fig-input-text
|
|
901
907
|
placeholder="##"
|
|
@@ -908,20 +914,20 @@ class FigInputColor extends HTMLElement {
|
|
|
908
914
|
</fig-tooltip>`;
|
|
909
915
|
}
|
|
910
916
|
html = `<div class="input-combo">
|
|
911
|
-
<
|
|
917
|
+
<fig-chit type="color" disabled="false" value="${this.value}"></fig-chit>
|
|
912
918
|
${label}
|
|
913
919
|
</div>`;
|
|
914
920
|
} else {
|
|
915
|
-
html = `<
|
|
921
|
+
html = `<fig-chit type="color" disabled="false" value="${this.value}"></fig-chit>`;
|
|
916
922
|
}
|
|
917
923
|
this.innerHTML = html;
|
|
918
924
|
|
|
919
925
|
this.style.setProperty("--alpha", this.#rgba.a);
|
|
920
926
|
|
|
921
927
|
requestAnimationFrame(() => {
|
|
922
|
-
this.#swatch = this.querySelector("[type=color]");
|
|
923
|
-
this.textInput = this.querySelector("[type=text]");
|
|
924
|
-
this.#alphaInput = this.querySelector("[type=number]");
|
|
928
|
+
this.#swatch = this.querySelector("input[type=color]");
|
|
929
|
+
this.textInput = this.querySelector("input[type=text]");
|
|
930
|
+
this.#alphaInput = this.querySelector("input[type=number]");
|
|
925
931
|
|
|
926
932
|
this.#swatch.disabled = this.hasAttribute("disabled");
|
|
927
933
|
this.#swatch.addEventListener("input", this.handleInput.bind(this));
|
|
@@ -1234,28 +1240,24 @@ class FigComboInput extends HTMLElement {
|
|
|
1234
1240
|
</fig-input-text>
|
|
1235
1241
|
<fig-button type="select" variant="input" icon>
|
|
1236
1242
|
<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.
|
|
1243
|
+
<path d='M5.87868 7.12132L8 9.24264L10.1213 7.12132' stroke='currentColor' stroke-opacity="0.9" stroke-linecap='round'/>
|
|
1238
1244
|
</svg>
|
|
1239
1245
|
<fig-dropdown type="dropdown">
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1246
|
+
${this.options
|
|
1247
|
+
.map((option) => `<option>${option}</option>`)
|
|
1248
|
+
.join("")}
|
|
1249
|
+
</fig-dropdown>
|
|
1244
1250
|
</fig-button>
|
|
1245
1251
|
</div>`;
|
|
1246
1252
|
requestAnimationFrame(() => {
|
|
1247
1253
|
this.input = this.querySelector("fig-input-text");
|
|
1248
|
-
this.
|
|
1254
|
+
this.select = this.querySelector("fig-dropdown");
|
|
1249
1255
|
|
|
1250
|
-
this.
|
|
1251
|
-
"input",
|
|
1252
|
-
this.handleDropdownChange.bind(this)
|
|
1253
|
-
);
|
|
1256
|
+
this.select.addEventListener("input", this.handleSelectInput.bind(this));
|
|
1254
1257
|
});
|
|
1255
1258
|
}
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
this.value = e.target.value;
|
|
1259
|
+
handleSelectInput(e) {
|
|
1260
|
+
this.value = e.target.parentNode.value;
|
|
1259
1261
|
this.setAttribute("value", this.value);
|
|
1260
1262
|
}
|
|
1261
1263
|
handleInput(e) {
|
|
@@ -1283,3 +1285,48 @@ class FigComboInput extends HTMLElement {
|
|
|
1283
1285
|
}
|
|
1284
1286
|
}
|
|
1285
1287
|
window.customElements.define("fig-combo-input", FigComboInput);
|
|
1288
|
+
|
|
1289
|
+
/* Chit */
|
|
1290
|
+
class FigChit extends HTMLElement {
|
|
1291
|
+
constructor() {
|
|
1292
|
+
super();
|
|
1293
|
+
}
|
|
1294
|
+
connectedCallback() {
|
|
1295
|
+
this.type = this.getAttribute("type") || "color";
|
|
1296
|
+
this.src = this.getAttribute("src") || "";
|
|
1297
|
+
this.value = this.getAttribute("value") || "";
|
|
1298
|
+
this.size = this.getAttribute("size") || "small";
|
|
1299
|
+
this.disabled = this.getAttribute("disabled") === "true" ? true : false;
|
|
1300
|
+
this.variant = this.getAttribute("variant") || "square";
|
|
1301
|
+
this.innerHTML = `<input type="color" value="${this.value}" />`;
|
|
1302
|
+
|
|
1303
|
+
requestAnimationFrame(() => {
|
|
1304
|
+
this.input = this.querySelector("input");
|
|
1305
|
+
this.input.disabled = this.disabled;
|
|
1306
|
+
this.updateSrc(this.src);
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
updateSrc(src) {
|
|
1310
|
+
if (src) {
|
|
1311
|
+
this.src = src;
|
|
1312
|
+
this.style.setProperty("--src", `url(${src})`);
|
|
1313
|
+
} else {
|
|
1314
|
+
this.style.removeProperty("--src");
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
static get observedAttributes() {
|
|
1318
|
+
return ["type", "src", "size", "variant", "value", "disabled"];
|
|
1319
|
+
}
|
|
1320
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
1321
|
+
if (name === "src") {
|
|
1322
|
+
this.updateSrc(newValue);
|
|
1323
|
+
}
|
|
1324
|
+
if (name === "disabled") {
|
|
1325
|
+
this.disabled = newValue.toLowerCase() === "true";
|
|
1326
|
+
if (this.input) {
|
|
1327
|
+
this.input.disabled = this.disabled;
|
|
1328
|
+
}
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
window.customElements.define("fig-chit", FigChit);
|
package/package.json
CHANGED