@rogieking/figui3 1.0.11 → 1.0.12

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 +91 -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,63 @@ 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;
1169
1187
 
1170
- .slider {
1171
- --start: 1;
1172
- display: block;
1188
+ .fig-slider-input-container {
1189
+ height: var(--slider-height);
1173
1190
  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);
1191
+ display: block;
1192
+ width: 100%;
1192
1193
 
1193
- &.gradient {
1194
- padding-top: 2.5rem !important;
1194
+ /* Track */
1195
+ &::before {
1196
+ content: '';
1197
+ background: var(--figma-color-bg-brand);
1198
+ position: absolute;
1199
+ left: 0;
1200
+ top: 0;
1201
+ bottom: 0;
1202
+ border-radius: 0.5rem;
1203
+ min-width: var(--slider-height);
1204
+ width: calc(var(--slider-percent) + (1 - var(--slider-complete)) * var(--slider-height));
1205
+ max-width: 100%;
1195
1206
  }
1207
+ }
1196
1208
 
1197
- & input[type=color] {
1198
- position: absolute;
1199
- left: var(--color-percent);
1200
- transform: translate(-50%, calc(-100% - 0.5rem));
1209
+ &[type=hue],
1210
+ &[type=opacity] {
1211
+ .fig-slider-input-container {
1212
+ &::before {
1213
+ display: none;
1214
+ }
1201
1215
  }
1202
1216
  }
1203
1217
 
1204
1218
  /* Chromium */
1205
- .slider input[type=range] {
1206
- height: 1rem;
1219
+ input[type=range] {
1220
+ height: var(--slider-height);
1207
1221
  appearance: none;
1208
1222
  -webkit-appearance: none;
1209
- border-radius: 0.5rem;
1223
+ border-radius: calc(var(--slider-height)/2);
1210
1224
  display: block;
1211
1225
  width: 100%;
1212
1226
  cursor: grab;
@@ -1220,18 +1234,14 @@ details {
1220
1234
 
1221
1235
  &:focus {
1222
1236
  outline: none;
1223
-
1224
- &::-webkit-slider-thumb {
1225
- box-shadow: var(--slider-handle-shadow-focus);
1226
- }
1227
1237
  }
1228
1238
 
1229
1239
  &::-webkit-slider-thumb {
1230
1240
  appearance: none;
1231
1241
  -webkit-appearance: none;
1232
1242
  border-radius: 0.5rem;
1233
- height: 1rem;
1234
- width: 1rem;
1243
+ height: var(--slider-height);
1244
+ width: var(--slider-height);
1235
1245
  aspect-ratio: 1;
1236
1246
  border: none;
1237
1247
  position: relative;
@@ -1252,15 +1262,11 @@ details {
1252
1262
  }
1253
1263
 
1254
1264
  &::-webkit-slider-runnable-track {
1255
- height: 1rem;
1265
+ height: var(--slider-height);
1256
1266
  background-color: transparent;
1257
- border-radius: 0.5rem;
1267
+ border-radius: calc(var(--slider-height)/2);
1258
1268
  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;
1269
+ background: var(--figma-color-bg-secondary);
1264
1270
  }
1265
1271
 
1266
1272
  &.hue::-webkit-slider-runnable-track {
@@ -1270,51 +1276,34 @@ details {
1270
1276
  &.opacity::-webkit-slider-runnable-track {
1271
1277
  background: linear-gradient(to right, transparent, var(--color)), var(--checkerboard);
1272
1278
  }
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
1279
  }
1288
1280
 
1289
1281
  /* Firefox */
1290
- .slider input[type=range] {
1291
- height: 1rem;
1282
+ input[type=range] {
1283
+ height: var(--slider-height);
1292
1284
  appearance: none;
1293
1285
  -webkit-appearance: none;
1294
- border-radius: 0.5rem;
1286
+ border-radius: calc(var(--slider-height)/2);
1295
1287
  display: block;
1296
1288
  width: 100%;
1289
+ cursor: grab;
1297
1290
  cursor: -moz-grab;
1298
1291
  background-color: transparent;
1299
1292
 
1300
1293
  &:active {
1294
+ cursor: grabbing;
1301
1295
  cursor: -moz-grabbing;
1302
1296
  }
1303
1297
 
1304
1298
  &:focus {
1305
1299
  outline: none;
1306
-
1307
- &::-moz-range-thumb {
1308
- box-shadow: var(--slider-handle-shadow-focus);
1309
- }
1310
1300
  }
1311
1301
 
1312
1302
  &::-moz-range-thumb {
1313
1303
  appearance: none;
1314
- -webkit-appearance: none;
1315
1304
  border-radius: 0.5rem;
1316
- height: 1rem;
1317
- width: 1rem;
1305
+ height: var(--slider-height);
1306
+ width: var(--slider-height);
1318
1307
  aspect-ratio: 1;
1319
1308
  border: none;
1320
1309
  position: relative;
@@ -1335,15 +1324,11 @@ details {
1335
1324
  }
1336
1325
 
1337
1326
  &::-moz-range-track {
1338
- height: 1rem;
1327
+ height: var(--slider-height);
1339
1328
  background-color: transparent;
1340
- border-radius: 0.5rem;
1329
+ border-radius: calc(var(--slider-height)/2);
1341
1330
  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;
1331
+ background: var(--figma-color-bg-secondary);
1347
1332
  }
1348
1333
 
1349
1334
  &.hue::-moz-range-track {
@@ -1353,49 +1338,38 @@ details {
1353
1338
  &.opacity::-moz-range-track {
1354
1339
  background: linear-gradient(to right, transparent, var(--color)), var(--checkerboard);
1355
1340
  }
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
1341
  }
1371
1342
 
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
- }
1343
+ datalist {
1344
+ --dot-size: calc(var(--slider-height)/4);
1345
+ position: absolute;
1346
+ inset: 0;
1347
+ display: flex;
1348
+ background: transparent;
1349
+ align-items: center;
1350
+ margin: 0;
1351
+ border: 0;
1352
+ appearance: none;
1353
+ padding: 0 calc((var(--slider-height)/2) - var(--dot-size)/2);
1354
+ height: var(--slider-height);
1355
+ pointer-events: none;
1356
+ justify-content: space-between;
1357
+ width: 100%;
1391
1358
 
1392
- .slider [type=range]::-webkit-slider-thumb {
1393
- view-timeline-name: --thumb;
1394
- view-timeline-axis: inline;
1359
+ & option {
1360
+ appearance: none;
1361
+ width: var(--dot-size);
1362
+ height: var(--dot-size);
1363
+ aspect-ratio: 1;
1364
+ margin: 0;
1365
+ padding: 0;
1366
+ border: 0;
1367
+ border-radius: 100%;
1368
+ font-size: 0;
1369
+ background: var(--figma-color-icon-tertiary);
1370
+ display: block;
1395
1371
  }
1396
1372
  }
1397
-
1398
-
1399
1373
  }
1400
1374
 
1401
1375
  /* 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.12"
4
4
  }