@rogieking/figui3 1.0.44 → 1.0.46

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 +14 -0
  2. package/fig.css +42 -1
  3. package/fig.js +61 -0
  4. package/package.json +1 -1
package/example.html CHANGED
@@ -31,10 +31,24 @@
31
31
  <fig-segment>Three</fig-segment>
32
32
  </fig-segmented-control>
33
33
  <br /><br />
34
+ <fig-image src="https://avatars.githubusercontent.com/u/12345678?v=4"
35
+ upload="true"></fig-image>
36
+ <fig-image src="https://avatars.githubusercontent.com/u/12345678?v=4"
37
+ upload="true"
38
+ size="medium"></fig-image>
39
+ <fig-image upload="true"
40
+ label="Upload image"
41
+ size="large"></fig-image>
42
+ <br /><br />
34
43
  <hstack>
35
44
  <fig-button>Primary</fig-button>
36
45
  <fig-button variant="secondary">Secondary</fig-button>
37
46
  <fig-button variant="ghost">Ghost</fig-button>
47
+ <fig-button variant="ghost"
48
+ type="upload">
49
+ Upload
50
+ <input type="file" />
51
+ </fig-button>
38
52
  <fig-button variant="ghost"
39
53
  type="toggle"
40
54
  icon="true">
package/fig.css CHANGED
@@ -976,7 +976,19 @@ fig-chit {
976
976
  box-shadow: inset 0 0 0 1px var(--figma-color-border-selected),
977
977
  inset 0 0 0 3px var(--figma-color-bg);
978
978
  }
979
+ input[type="color"]::-webkit-color-swatch-wrapper {
980
+ border-radius: var(--radius-medium);
981
+ }
982
+
983
+ input[type="color"]::-moz-color-swatch {
984
+ border-radius: var(--radius-medium);
985
+ }
986
+
987
+ input[type="color"]::-webkit-color-swatch {
988
+ border-radius: var(--radius-medium);
989
+ }
979
990
  }
991
+
980
992
  &[disabled="true"] {
981
993
  input {
982
994
  pointer-events: none;
@@ -1039,6 +1051,36 @@ fig-chit {
1039
1051
  }
1040
1052
  }
1041
1053
 
1054
+ /* Fig Image */
1055
+ fig-image {
1056
+ --image-size: 2rem;
1057
+ display: inline-grid;
1058
+ place-items: center;
1059
+ width: var(--image-size);
1060
+ height: var(--image-size);
1061
+ > * {
1062
+ grid-area: 1/1;
1063
+ }
1064
+ fig-chit {
1065
+ --size: var(--image-size) !important;
1066
+ }
1067
+ fig-button {
1068
+ opacity: 0;
1069
+ pointer-events: none;
1070
+ }
1071
+ &:not([src]):not([src=""]) fig-button,
1072
+ &:hover fig-button {
1073
+ opacity: 1;
1074
+ pointer-events: all;
1075
+ }
1076
+ &[size="medium"] {
1077
+ --image-size: 4rem;
1078
+ }
1079
+ &[size="large"] {
1080
+ --image-size: 8rem;
1081
+ }
1082
+ }
1083
+
1042
1084
  /* Combo input */
1043
1085
  .input-combo {
1044
1086
  display: inline-flex;
@@ -2041,7 +2083,6 @@ fig-segmented-control {
2041
2083
  justify-content: center;
2042
2084
  position: relative;
2043
2085
  appearance: none;
2044
- min-width: 1.5rem;
2045
2086
  padding: 0 var(--spacer-2);
2046
2087
 
2047
2088
  &[selected]:not([selected="false"]),
package/fig.js CHANGED
@@ -1326,3 +1326,64 @@ class FigChit extends HTMLElement {
1326
1326
  }
1327
1327
  }
1328
1328
  window.customElements.define("fig-chit", FigChit);
1329
+
1330
+ /* Upload */
1331
+ class FigImage extends HTMLElement {
1332
+ constructor() {
1333
+ super();
1334
+ }
1335
+ #getInnerHTML() {
1336
+ return `<fig-chit type="image" size="large" ${
1337
+ this.src ? `src="${this.src}"` : ""
1338
+ } disabled="true"></fig-chit>${
1339
+ this.upload
1340
+ ? `<fig-button variant="primary" type="upload">
1341
+ ${this.label}
1342
+ <input type="file" accept="image/*" />
1343
+ </fig-button>`
1344
+ : ""
1345
+ }`;
1346
+ }
1347
+ connectedCallback() {
1348
+ this.src = this.getAttribute("src") || "";
1349
+ this.upload = this.getAttribute("upload") === "true";
1350
+ this.label = this.getAttribute("label") || "Upload";
1351
+ this.size = this.getAttribute("size") || "small";
1352
+ this.innerHTML = this.#getInnerHTML();
1353
+ this.#updateRefs();
1354
+ }
1355
+ #updateRefs() {
1356
+ requestAnimationFrame(() => {
1357
+ this.chit = this.querySelector("fig-chit");
1358
+ this.uploadButton = this.querySelector("fig-button");
1359
+ this.fileInput = this.uploadButton?.querySelector("input");
1360
+
1361
+ this.fileInput.addEventListener(
1362
+ "change",
1363
+ this.handleFileInput.bind(this)
1364
+ );
1365
+ });
1366
+ }
1367
+ handleFileInput(e) {
1368
+ this.src = URL.createObjectURL(e.target.files[0]);
1369
+ this.setAttribute("src", this.src);
1370
+ this.chit.setAttribute("src", this.src);
1371
+ }
1372
+ static get observedAttributes() {
1373
+ return ["src", "upload"];
1374
+ }
1375
+ attributeChangedCallback(name, oldValue, newValue) {
1376
+ if (name === "src") {
1377
+ this.src = newValue;
1378
+ }
1379
+ if (name === "upload") {
1380
+ this.upload = newValue.toLowerCase() === "true";
1381
+ this.innerHTML = this.#getInnerHTML();
1382
+ this.#updateRefs();
1383
+ }
1384
+ if (name === "size") {
1385
+ this.size = newValue;
1386
+ }
1387
+ }
1388
+ }
1389
+ window.customElements.define("fig-image", FigImage);
package/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "1.0.44"
3
+ "version": "1.0.46"
4
4
  }