@rogieking/figui3 1.0.11 → 1.0.13

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 (3) hide show
  1. package/fig.css +92 -117
  2. package/fig.js +26 -14
  3. package/package.json +1 -1
package/fig.css CHANGED
@@ -572,16 +572,16 @@ input[type=text][list] {
572
572
  }
573
573
  }
574
574
 
575
- input[list]:hover,
576
- input[list]:active,
577
- input[list]:focus,
575
+ input[type=text][list]:hover,
576
+ input[type=text][list]:active,
577
+ input[type=text][list]:focus,
578
578
  select {
579
579
  background-image: var(--icon-chevron);
580
580
  background-position: calc(100% - 0.25rem) center;
581
581
  background-repeat: no-repeat;
582
582
  }
583
583
 
584
- input[list],
584
+ input[type=text][list],
585
585
  select {
586
586
  padding-right: 1.5rem;
587
587
  }
@@ -1164,49 +1164,64 @@ details {
1164
1164
  */
1165
1165
 
1166
1166
 
1167
+ .fig-slider,
1168
+ fig-slider {
1169
+ --slider-height: 1rem;
1170
+ --slider-percent: calc(var(--slider-complete) * 100%);
1171
+ --slider-handle-shadow: inset 0 0 0 4px var(--figma-color-icon-onbrand),
1172
+ inset 0 0 0 5px rgba(0, 0, 0, 0.1),
1173
+ 0px 0 0 0.75px rgba(0, 0, 0, 0.1),
1174
+ 0px 1px 3px 0px rgba(0, 0, 0, 0.1),
1175
+ 0px 3px 8px 0px rgba(0, 0, 0, 0.1),
1176
+ 0px 0px 0.5px 0px rgba(0, 0, 0, 0.18);
1177
+ --slider-handle-shadow-focus: inset 0 0 0 4px var(--figma-color-icon-onbrand),
1178
+ inset 0 0 0 5px rgba(0, 0, 0, 0.1),
1179
+ 0px 0 0 0.75px rgba(0, 0, 0, 0.1),
1180
+ 0px 1px 3px 0px rgba(0, 0, 0, 0.1),
1181
+ 0px 3px 8px 0px rgba(0, 0, 0, 0.1),
1182
+ 0px 0px 0.5px 0px rgba(0, 0, 0, 0.18),
1183
+ 0 0 0 1px var(--border-selected);
1167
1184
 
1168
- @layer slider {
1185
+ display: inline-flex;
1186
+ align-items: center;
1187
+ position: relative;
1169
1188
 
1170
- .slider {
1171
- --start: 1;
1172
- display: block;
1189
+ .fig-slider-input-container {
1190
+ height: var(--slider-height);
1173
1191
  position: relative;
1174
- padding: 0.25rem 5px !important;
1175
- overflow: hidden;
1176
- margin: 0 -5px !important;
1177
- --slider-percent: calc(var(--slider-complete) * (100% - 5px));
1178
- --color-percent: calc(var(--slider-complete) * (100%));
1179
- --slider-handle-shadow: inset 0 0 0 4px var(--figma-color-icon-onbrand),
1180
- inset 0 0 0 5px rgba(0, 0, 0, 0.1),
1181
- 0px 0 0 0.75px rgba(0, 0, 0, 0.1),
1182
- 0px 1px 3px 0px rgba(0, 0, 0, 0.1),
1183
- 0px 3px 8px 0px rgba(0, 0, 0, 0.1),
1184
- 0px 0px 0.5px 0px rgba(0, 0, 0, 0.18);
1185
- --slider-handle-shadow-focus: inset 0 0 0 4px var(--figma-color-icon-onbrand),
1186
- inset 0 0 0 5px rgba(0, 0, 0, 0.1),
1187
- 0px 0 0 0.75px rgba(0, 0, 0, 0.1),
1188
- 0px 1px 3px 0px rgba(0, 0, 0, 0.1),
1189
- 0px 3px 8px 0px rgba(0, 0, 0, 0.1),
1190
- 0px 0px 0.5px 0px rgba(0, 0, 0, 0.18),
1191
- 0 0 0 1px var(--border-selected);
1192
+ display: block;
1193
+ width: 100%;
1192
1194
 
1193
- &.gradient {
1194
- padding-top: 2.5rem !important;
1195
+ /* Track */
1196
+ &::before {
1197
+ content: '';
1198
+ background: var(--figma-color-bg-brand);
1199
+ position: absolute;
1200
+ left: 0;
1201
+ top: 0;
1202
+ bottom: 0;
1203
+ border-radius: 0.5rem;
1204
+ min-width: var(--slider-height);
1205
+ width: calc(var(--slider-percent) + (1 - var(--slider-complete)) * var(--slider-height));
1206
+ max-width: 100%;
1195
1207
  }
1208
+ }
1196
1209
 
1197
- & input[type=color] {
1198
- position: absolute;
1199
- left: var(--color-percent);
1200
- transform: translate(-50%, calc(-100% - 0.5rem));
1210
+ &[type=hue],
1211
+ &[type=opacity] {
1212
+ .fig-slider-input-container {
1213
+ &::before {
1214
+ display: none;
1215
+ }
1201
1216
  }
1202
1217
  }
1203
1218
 
1204
1219
  /* Chromium */
1205
- .slider input[type=range] {
1206
- height: 1rem;
1220
+ input[type=range] {
1221
+ height: var(--slider-height);
1207
1222
  appearance: none;
1208
1223
  -webkit-appearance: none;
1209
- border-radius: 0.5rem;
1224
+ border-radius: calc(var(--slider-height)/2);
1210
1225
  display: block;
1211
1226
  width: 100%;
1212
1227
  cursor: grab;
@@ -1220,18 +1235,14 @@ details {
1220
1235
 
1221
1236
  &:focus {
1222
1237
  outline: none;
1223
-
1224
- &::-webkit-slider-thumb {
1225
- box-shadow: var(--slider-handle-shadow-focus);
1226
- }
1227
1238
  }
1228
1239
 
1229
1240
  &::-webkit-slider-thumb {
1230
1241
  appearance: none;
1231
1242
  -webkit-appearance: none;
1232
1243
  border-radius: 0.5rem;
1233
- height: 1rem;
1234
- width: 1rem;
1244
+ height: var(--slider-height);
1245
+ width: var(--slider-height);
1235
1246
  aspect-ratio: 1;
1236
1247
  border: none;
1237
1248
  position: relative;
@@ -1252,15 +1263,11 @@ details {
1252
1263
  }
1253
1264
 
1254
1265
  &::-webkit-slider-runnable-track {
1255
- height: 1rem;
1266
+ height: var(--slider-height);
1256
1267
  background-color: transparent;
1257
- border-radius: 0.5rem;
1268
+ border-radius: calc(var(--slider-height)/2);
1258
1269
  box-shadow: inset 0 0 0 1px var(--figma-color-bordertranslucent);
1259
- background: radial-gradient(.55rem .55rem at var(--slider-percent) 50%, var(--figma-color-bg-brand) 0%, var(--figma-color-bg-brand) .55rem, transparent .55rem, transparent 100%),
1260
- linear-gradient(to right, var(--figma-color-bg-brand) 0%, var(--figma-color-bg-brand) var(--slider-percent), var(--figma-color-bg-secondary) var(--slider-percent));
1261
- background-size: 100% 100%, 100% 100%;
1262
- background-position: 75% middle, left middle;
1263
- background-repeat: no-repeat;
1270
+ background: var(--figma-color-bg-secondary);
1264
1271
  }
1265
1272
 
1266
1273
  &.hue::-webkit-slider-runnable-track {
@@ -1270,51 +1277,34 @@ details {
1270
1277
  &.opacity::-webkit-slider-runnable-track {
1271
1278
  background: linear-gradient(to right, transparent, var(--color)), var(--checkerboard);
1272
1279
  }
1273
-
1274
- &.gradient {
1275
- border-radius: 0.125rem;
1276
-
1277
- &::-webkit-slider-thumb {
1278
- transform: scale(1.5) translateY(-1.25rem);
1279
- opacity: 0.5;
1280
- }
1281
- }
1282
-
1283
- &.gradient::-webkit-slider-runnable-track {
1284
- border-radius: 0.125rem;
1285
- background: var(--bg-hue);
1286
- }
1287
1280
  }
1288
1281
 
1289
1282
  /* Firefox */
1290
- .slider input[type=range] {
1291
- height: 1rem;
1283
+ input[type=range] {
1284
+ height: var(--slider-height);
1292
1285
  appearance: none;
1293
1286
  -webkit-appearance: none;
1294
- border-radius: 0.5rem;
1287
+ border-radius: calc(var(--slider-height)/2);
1295
1288
  display: block;
1296
1289
  width: 100%;
1290
+ cursor: grab;
1297
1291
  cursor: -moz-grab;
1298
1292
  background-color: transparent;
1299
1293
 
1300
1294
  &:active {
1295
+ cursor: grabbing;
1301
1296
  cursor: -moz-grabbing;
1302
1297
  }
1303
1298
 
1304
1299
  &:focus {
1305
1300
  outline: none;
1306
-
1307
- &::-moz-range-thumb {
1308
- box-shadow: var(--slider-handle-shadow-focus);
1309
- }
1310
1301
  }
1311
1302
 
1312
1303
  &::-moz-range-thumb {
1313
1304
  appearance: none;
1314
- -webkit-appearance: none;
1315
1305
  border-radius: 0.5rem;
1316
- height: 1rem;
1317
- width: 1rem;
1306
+ height: var(--slider-height);
1307
+ width: var(--slider-height);
1318
1308
  aspect-ratio: 1;
1319
1309
  border: none;
1320
1310
  position: relative;
@@ -1335,15 +1325,11 @@ details {
1335
1325
  }
1336
1326
 
1337
1327
  &::-moz-range-track {
1338
- height: 1rem;
1328
+ height: var(--slider-height);
1339
1329
  background-color: transparent;
1340
- border-radius: 0.5rem;
1330
+ border-radius: calc(var(--slider-height)/2);
1341
1331
  box-shadow: inset 0 0 0 1px var(--figma-color-bordertranslucent);
1342
- background: radial-gradient(.55rem .55rem at var(--slider-percent) 50%, var(--figma-color-bg-brand) 0%, var(--figma-color-bg-brand) .55rem, transparent .55rem, transparent 100%),
1343
- linear-gradient(to right, var(--figma-color-bg-brand) 0%, var(--figma-color-bg-brand) var(--slider-percent), var(--figma-color-bg-secondary) var(--slider-percent));
1344
- background-size: 100% 100%, 100% 100%;
1345
- background-position: 75% middle, left middle;
1346
- background-repeat: no-repeat;
1332
+ background: var(--figma-color-bg-secondary);
1347
1333
  }
1348
1334
 
1349
1335
  &.hue::-moz-range-track {
@@ -1353,49 +1339,38 @@ details {
1353
1339
  &.opacity::-moz-range-track {
1354
1340
  background: linear-gradient(to right, transparent, var(--color)), var(--checkerboard);
1355
1341
  }
1356
-
1357
- &.gradient {
1358
- border-radius: 0.125rem;
1359
-
1360
- &::-webkit-slider-thumb {
1361
- transform: scale(1.5) translateY(-1.25rem);
1362
- opacity: 0.5;
1363
- }
1364
- }
1365
-
1366
- &.gradient::-moz-range-track {
1367
- border-radius: 0.125rem;
1368
- background: var(--bg-hue);
1369
- }
1370
1342
  }
1371
1343
 
1372
- @supports (animation-timeline: scroll()) {
1373
- @property --slider-complete {
1374
- initial-value: 0;
1375
- syntax: '<number>';
1376
- inherits: true;
1377
- }
1378
-
1379
- @keyframes sync {
1380
- to {
1381
- --slider-complete: 1;
1382
- }
1383
- }
1384
-
1385
- .slider {
1386
- timeline-scope: --thumb;
1387
- animation: sync both linear reverse;
1388
- animation-timeline: --thumb;
1389
- animation-range: contain;
1390
- }
1344
+ datalist {
1345
+ --dot-size: calc(var(--slider-height)/4);
1346
+ position: absolute;
1347
+ inset: 0;
1348
+ display: flex;
1349
+ background: transparent;
1350
+ align-items: center;
1351
+ margin: 0;
1352
+ border: 0;
1353
+ appearance: none;
1354
+ padding: 0 calc((var(--slider-height)/2) - var(--dot-size)/2);
1355
+ height: var(--slider-height);
1356
+ pointer-events: none;
1357
+ justify-content: space-between;
1358
+ width: 100%;
1391
1359
 
1392
- .slider [type=range]::-webkit-slider-thumb {
1393
- view-timeline-name: --thumb;
1394
- view-timeline-axis: inline;
1360
+ & option {
1361
+ appearance: none;
1362
+ width: var(--dot-size);
1363
+ height: var(--dot-size);
1364
+ aspect-ratio: 1;
1365
+ margin: 0;
1366
+ padding: 0;
1367
+ border: 0;
1368
+ border-radius: 100%;
1369
+ font-size: 0;
1370
+ background: var(--figma-color-icon-tertiary);
1371
+ display: block;
1395
1372
  }
1396
1373
  }
1397
-
1398
-
1399
1374
  }
1400
1375
 
1401
1376
  /* Popovers/Dialogs */
package/fig.js CHANGED
@@ -512,7 +512,7 @@ class FigSlider extends HTMLElement {
512
512
  }
513
513
 
514
514
  let html = ''
515
- let slider = `<div class="slider">
515
+ let slider = `<div class="fig-slider-input-container">
516
516
  <input
517
517
  type="range"
518
518
  ${this.disabled ? "disabled" : ""}
@@ -521,6 +521,7 @@ class FigSlider extends HTMLElement {
521
521
  step="${this.step}"
522
522
  class="${this.type}"
523
523
  value="${this.value}">
524
+ ${this.innerHTML}
524
525
  </div>`
525
526
  if (this.getAttribute("text")) {
526
527
  html = `${slider}
@@ -535,16 +536,23 @@ class FigSlider extends HTMLElement {
535
536
  } else {
536
537
  html = slider
537
538
  }
539
+
538
540
  this.innerHTML = html
539
541
 
540
542
  this.textInput = this.querySelector("input[type=number]")
541
- this.slider = this.querySelector('.slider')
542
543
 
543
544
  this.input = this.querySelector('[type=range]')
544
- this.input.addEventListener("input", this.handleChange.bind(this))
545
+ this.input.addEventListener("input", this.handleInput.bind(this))
546
+ this.handleInput()
547
+
548
+ this.datalist = this.querySelector('datalist')
549
+ if (this.datalist) {
550
+ this.datalist.setAttribute("id", this.datalist.getAttribute("id") || uniqueId())
551
+ this.input.setAttribute('list', this.datalist.getAttribute("id"))
552
+ }
545
553
 
546
554
  if (this.textInput) {
547
- this.textInput.addEventListener("change", this.handleChange.bind(this))
555
+ this.textInput.addEventListener("input", this.handleTextInput.bind(this))
548
556
  }
549
557
  }
550
558
  static get observedAttributes() {
@@ -577,24 +585,28 @@ class FigSlider extends HTMLElement {
577
585
  if (this.textInput) {
578
586
  this.textInput[name] = newValue
579
587
  }
588
+ this.handleInput()
580
589
  break;
581
590
  }
582
591
  }
583
592
  }
584
-
585
- syncProps() {
586
- if (!CSS.supports('animation-timeline: scroll()')) {
587
- let complete = this.input.value / (this.input.max - this.input.min)
588
- this.slider.style.setProperty('--slider-percent', `${complete * 100}%`)
593
+ handleTextInput() {
594
+ if (this.textInput) {
595
+ this.input.value = Number(this.textInput.value)
596
+ this.handleInput()
589
597
  }
590
598
  }
591
- handleChange(event) {
592
- this.value = event.target.value
593
- this.input.value = this.value
599
+
600
+ handleInput() {
601
+ let min = Number(this.input.min)
602
+ let max = Number(this.input.max)
603
+ let val = Number(this.input.value)
604
+ this.value = val
605
+ let complete = (val - min) / (max - min)
606
+ this.style.setProperty("--slider-complete", complete)
594
607
  if (this.textInput) {
595
- this.textInput.value = this.value
608
+ this.textInput.value = val
596
609
  }
597
- this.syncProps()
598
610
  }
599
611
  }
600
612
  window.customElements.define('fig-slider', FigSlider);
package/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@rogieking/figui3",
3
- "version": "1.0.11"
3
+ "version": "1.0.13"
4
4
  }