@rogieking/figui3 1.0.37 → 1.0.38
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 +12 -4
- package/fig.css +8 -1
- package/fig.js +130 -23
- package/package.json +1 -1
package/example.html
CHANGED
|
@@ -69,10 +69,18 @@
|
|
|
69
69
|
</fig-tooltip>
|
|
70
70
|
</hstack>
|
|
71
71
|
<br />
|
|
72
|
-
<fig-
|
|
73
|
-
<
|
|
74
|
-
<
|
|
75
|
-
|
|
72
|
+
<fig-field direction="horizontal">
|
|
73
|
+
<label>Dropdown</label>
|
|
74
|
+
<fig-dropdown>
|
|
75
|
+
<option>One</option>
|
|
76
|
+
<option>Two</option>
|
|
77
|
+
</fig-dropdown>
|
|
78
|
+
</fig-field>
|
|
79
|
+
<br />
|
|
80
|
+
<fig-combo-input options="House, Apartment, Condo, Other"
|
|
81
|
+
placeholder="Type of residence">
|
|
82
|
+
|
|
83
|
+
</fig-combo-input>
|
|
76
84
|
<br />
|
|
77
85
|
<fig-tooltip text="Tooltip text">
|
|
78
86
|
<p>Tooltip</p>
|
package/fig.css
CHANGED
|
@@ -684,6 +684,12 @@ fig-button {
|
|
|
684
684
|
}
|
|
685
685
|
}
|
|
686
686
|
|
|
687
|
+
/* Variant: Input */
|
|
688
|
+
&[variant="input"] {
|
|
689
|
+
background-color: var(--figma-color-bg-secondary);
|
|
690
|
+
box-shadow: none;
|
|
691
|
+
}
|
|
692
|
+
|
|
687
693
|
/* Icon only */
|
|
688
694
|
&[icon],
|
|
689
695
|
&[icon] > button {
|
|
@@ -1808,16 +1814,17 @@ fig-input-text {
|
|
|
1808
1814
|
& [slot] {
|
|
1809
1815
|
user-select: none;
|
|
1810
1816
|
width: 1.5rem;
|
|
1811
|
-
margin-right: calc(var(--spacer-2) * -1);
|
|
1812
1817
|
color: var(--figma-color-text-secondary);
|
|
1813
1818
|
}
|
|
1814
1819
|
|
|
1815
1820
|
& [slot="prepend"] {
|
|
1816
1821
|
padding-right: 0;
|
|
1822
|
+
margin-right: calc(var(--spacer-2) * -1);
|
|
1817
1823
|
}
|
|
1818
1824
|
|
|
1819
1825
|
& [slot="append"] {
|
|
1820
1826
|
padding-left: 0;
|
|
1827
|
+
margin-left: calc(var(--spacer-2) * -1);
|
|
1821
1828
|
}
|
|
1822
1829
|
|
|
1823
1830
|
& input {
|
package/fig.js
CHANGED
|
@@ -100,6 +100,7 @@ class FigDropdown extends HTMLElement {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
render() {
|
|
103
|
+
this.type = this.getAttribute("type") || "select";
|
|
103
104
|
this.select = document.createElement("select");
|
|
104
105
|
this.optionsSlot = document.createElement("slot");
|
|
105
106
|
|
|
@@ -108,16 +109,32 @@ class FigDropdown extends HTMLElement {
|
|
|
108
109
|
|
|
109
110
|
// Move slotted options into the select element
|
|
110
111
|
this.optionsSlot.addEventListener("slotchange", this.slotChange.bind(this));
|
|
112
|
+
|
|
113
|
+
this.select.addEventListener("change", this.handleChange.bind(this));
|
|
111
114
|
}
|
|
112
115
|
slotChange() {
|
|
113
116
|
while (this.select.firstChild) {
|
|
114
117
|
this.select.firstChild.remove();
|
|
115
118
|
}
|
|
119
|
+
if (this.type === "dropdown") {
|
|
120
|
+
const hiddenOption = document.createElement("option");
|
|
121
|
+
hiddenOption.setAttribute("hidden", "true");
|
|
122
|
+
hiddenOption.setAttribute("selected", "true");
|
|
123
|
+
this.select.appendChild(hiddenOption);
|
|
124
|
+
}
|
|
116
125
|
this.optionsSlot.assignedNodes().forEach((node) => {
|
|
117
126
|
if (node.nodeName === "OPTION") {
|
|
118
127
|
this.select.appendChild(node.cloneNode(true));
|
|
119
128
|
}
|
|
120
129
|
});
|
|
130
|
+
if (this.type === "dropdown") {
|
|
131
|
+
this.select.selectedIndex = -1;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
handleChange() {
|
|
135
|
+
if (this.type === "dropdown") {
|
|
136
|
+
this.select.selectedIndex = -1;
|
|
137
|
+
}
|
|
121
138
|
}
|
|
122
139
|
}
|
|
123
140
|
|
|
@@ -318,7 +335,6 @@ class FigDialog extends HTMLElement {
|
|
|
318
335
|
|
|
319
336
|
/* Public methods */
|
|
320
337
|
show() {
|
|
321
|
-
console.log("show dialog", this.dialog, this.dialog?.show);
|
|
322
338
|
this.dialog.show();
|
|
323
339
|
}
|
|
324
340
|
close() {
|
|
@@ -682,7 +698,6 @@ class FigSlider extends HTMLElement {
|
|
|
682
698
|
|
|
683
699
|
handleInput() {
|
|
684
700
|
let val = Number(this.input.value);
|
|
685
|
-
console.log(val);
|
|
686
701
|
this.value = val;
|
|
687
702
|
let complete = this.calculateNormal(val);
|
|
688
703
|
let defaultValue = this.calculateNormal(this.default);
|
|
@@ -702,7 +717,7 @@ class FigInputText extends HTMLElement {
|
|
|
702
717
|
}
|
|
703
718
|
connectedCallback() {
|
|
704
719
|
this.multiline = this.hasAttribute("multiline") || false;
|
|
705
|
-
this.value = this.getAttribute("value");
|
|
720
|
+
this.value = this.getAttribute("value") || "";
|
|
706
721
|
this.type = this.getAttribute("type") || "text";
|
|
707
722
|
this.placeholder = this.getAttribute("placeholder");
|
|
708
723
|
|
|
@@ -714,14 +729,13 @@ class FigInputText extends HTMLElement {
|
|
|
714
729
|
html = `<textarea
|
|
715
730
|
placeholder="${this.placeholder}">${this.value}</textarea>`;
|
|
716
731
|
}
|
|
717
|
-
this.innerHTML = html;
|
|
718
732
|
|
|
719
733
|
//child nodes hack
|
|
720
734
|
requestAnimationFrame(() => {
|
|
721
735
|
const append = this.querySelector("[slot=append]");
|
|
722
736
|
const prepend = this.querySelector("[slot=prepend]");
|
|
723
737
|
|
|
724
|
-
|
|
738
|
+
this.innerHTML = html;
|
|
725
739
|
|
|
726
740
|
if (prepend) {
|
|
727
741
|
prepend.addEventListener("click", this.focus.bind(this));
|
|
@@ -819,7 +833,7 @@ class FigAvatar extends HTMLElement {
|
|
|
819
833
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
820
834
|
this[name] = newValue;
|
|
821
835
|
if (name === "name") {
|
|
822
|
-
this.img
|
|
836
|
+
this.img?.setAttribute("alt", newValue);
|
|
823
837
|
this.name = newValue;
|
|
824
838
|
this.initials = this.getInitials(this.name);
|
|
825
839
|
this.setAttribute("initials", this.initials);
|
|
@@ -904,26 +918,28 @@ class FigInputColor extends HTMLElement {
|
|
|
904
918
|
|
|
905
919
|
this.style.setProperty("--alpha", this.#rgba.a);
|
|
906
920
|
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
921
|
+
requestAnimationFrame(() => {
|
|
922
|
+
this.#swatch = this.querySelector("[type=color]");
|
|
923
|
+
this.textInput = this.querySelector("[type=text]");
|
|
924
|
+
this.#alphaInput = this.querySelector("[type=number]");
|
|
910
925
|
|
|
911
|
-
|
|
912
|
-
|
|
926
|
+
this.#swatch.disabled = this.hasAttribute("disabled");
|
|
927
|
+
this.#swatch.addEventListener("input", this.handleInput.bind(this));
|
|
913
928
|
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
929
|
+
if (this.textInput) {
|
|
930
|
+
this.textInput.value = this.#swatch.value = this.rgbAlphaToHex(
|
|
931
|
+
this.#rgba,
|
|
932
|
+
1
|
|
933
|
+
);
|
|
934
|
+
}
|
|
920
935
|
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
936
|
+
if (this.#alphaInput) {
|
|
937
|
+
this.#alphaInput.addEventListener(
|
|
938
|
+
"input",
|
|
939
|
+
this.handleAlphaInput.bind(this)
|
|
940
|
+
);
|
|
941
|
+
}
|
|
942
|
+
});
|
|
927
943
|
}
|
|
928
944
|
handleAlphaInput(event) {
|
|
929
945
|
//do not propagate to onInput handler for web component
|
|
@@ -1176,3 +1192,94 @@ class FigSwitch extends FigCheckbox {
|
|
|
1176
1192
|
}
|
|
1177
1193
|
}
|
|
1178
1194
|
window.customElements.define("fig-switch", FigSwitch);
|
|
1195
|
+
|
|
1196
|
+
/* Bell */
|
|
1197
|
+
class FigBell extends HTMLElement {
|
|
1198
|
+
constructor() {
|
|
1199
|
+
super();
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
window.customElements.define("fig-bell", FigBell);
|
|
1203
|
+
|
|
1204
|
+
/* Badge */
|
|
1205
|
+
class FigBadge extends HTMLElement {
|
|
1206
|
+
constructor() {
|
|
1207
|
+
super();
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
window.customElements.define("fig-badge", FigBadge);
|
|
1211
|
+
|
|
1212
|
+
/* Accordion */
|
|
1213
|
+
class FigAccordion extends HTMLElement {
|
|
1214
|
+
constructor() {
|
|
1215
|
+
super();
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
window.customElements.define("fig-accordion", FigAccordion);
|
|
1219
|
+
|
|
1220
|
+
/* Combo Input */
|
|
1221
|
+
class FigComboInput extends HTMLElement {
|
|
1222
|
+
constructor() {
|
|
1223
|
+
super();
|
|
1224
|
+
}
|
|
1225
|
+
getOptionsFromAttribute() {
|
|
1226
|
+
return (this.getAttribute("options") || "").split(",");
|
|
1227
|
+
}
|
|
1228
|
+
connectedCallback() {
|
|
1229
|
+
this.options = this.getOptionsFromAttribute();
|
|
1230
|
+
this.placeholder = this.getAttribute("placeholder") || "";
|
|
1231
|
+
this.value = this.getAttribute("value") || "";
|
|
1232
|
+
this.innerHTML = `<div class="input-combo">
|
|
1233
|
+
<fig-input-text placeholder="${this.placeholder}">
|
|
1234
|
+
</fig-input-text>
|
|
1235
|
+
<fig-button type="select" variant="input" icon>
|
|
1236
|
+
<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'/>
|
|
1238
|
+
</svg>
|
|
1239
|
+
<fig-dropdown type="dropdown">
|
|
1240
|
+
${this.options
|
|
1241
|
+
.map((option) => `<option>${option}</option>`)
|
|
1242
|
+
.join("")}
|
|
1243
|
+
</fig-dropdown>
|
|
1244
|
+
</fig-button>
|
|
1245
|
+
</div>`;
|
|
1246
|
+
requestAnimationFrame(() => {
|
|
1247
|
+
this.input = this.querySelector("fig-input-text");
|
|
1248
|
+
this.dropdown = this.querySelector("fig-dropdown");
|
|
1249
|
+
|
|
1250
|
+
this.dropdown.addEventListener(
|
|
1251
|
+
"input",
|
|
1252
|
+
this.handleDropdownChange.bind(this)
|
|
1253
|
+
);
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
handleDropdownChange(e) {
|
|
1257
|
+
console.log(e.target.value);
|
|
1258
|
+
this.value = e.target.value;
|
|
1259
|
+
this.setAttribute("value", this.value);
|
|
1260
|
+
}
|
|
1261
|
+
handleInput(e) {
|
|
1262
|
+
this.value = this.input.value;
|
|
1263
|
+
}
|
|
1264
|
+
static get observedAttributes() {
|
|
1265
|
+
return ["options", "placeholder", "value"];
|
|
1266
|
+
}
|
|
1267
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
1268
|
+
if (name === "options") {
|
|
1269
|
+
this.options = newValue.split(",");
|
|
1270
|
+
if (this.dropdown) {
|
|
1271
|
+
this.dropdown.innerHTML = this.options
|
|
1272
|
+
.map((option) => `<option>${option}</option>`)
|
|
1273
|
+
.join("");
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
if (name === "placeholder") {
|
|
1277
|
+
this.placeholder = newValue;
|
|
1278
|
+
}
|
|
1279
|
+
if (name === "value") {
|
|
1280
|
+
this.value = newValue;
|
|
1281
|
+
this.input.setAttribute("value", newValue);
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
window.customElements.define("fig-combo-input", FigComboInput);
|
package/package.json
CHANGED