@rogieking/figui3 1.3.8 → 1.4.0
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 +21 -0
- package/fig.css +6 -13
- package/fig.js +158 -2
- package/package.json +1 -1
package/example.html
CHANGED
|
@@ -23,6 +23,27 @@
|
|
|
23
23
|
<h2>UI3 Components</h2>
|
|
24
24
|
</fig-header>
|
|
25
25
|
<fig-content>
|
|
26
|
+
<fig-field>
|
|
27
|
+
<fig-tooltip text="Options">
|
|
28
|
+
<fig-dropdown>
|
|
29
|
+
<option>One</option>
|
|
30
|
+
<option>Two</option>
|
|
31
|
+
</fig-dropdown>
|
|
32
|
+
</fig-tooltip>
|
|
33
|
+
|
|
34
|
+
</fig-field>
|
|
35
|
+
<fig-field>
|
|
36
|
+
<fig-tooltip text="Delta slider">
|
|
37
|
+
<fig-slider type="delta"
|
|
38
|
+
value=".25"
|
|
39
|
+
default="2"
|
|
40
|
+
step="0.1"
|
|
41
|
+
max="5"
|
|
42
|
+
min="-5">
|
|
43
|
+
</fig-slider>
|
|
44
|
+
</fig-tooltip>
|
|
45
|
+
</fig-field>
|
|
46
|
+
|
|
26
47
|
<br /><br />
|
|
27
48
|
<fig-input-angle value="45"
|
|
28
49
|
text="true"></fig-input-angle>
|
package/fig.css
CHANGED
|
@@ -1514,6 +1514,12 @@ fig-slider {
|
|
|
1514
1514
|
}
|
|
1515
1515
|
|
|
1516
1516
|
&[type="delta"] {
|
|
1517
|
+
datalist option {
|
|
1518
|
+
position: absolute;
|
|
1519
|
+
margin: 0;
|
|
1520
|
+
left: calc(var(--start-percent) - var(--slider-tick-size) / 2);
|
|
1521
|
+
top: calc(50% - var(--slider-tick-size) / 2);
|
|
1522
|
+
}
|
|
1517
1523
|
.fig-slider-input-container {
|
|
1518
1524
|
&::before {
|
|
1519
1525
|
--left-start: calc(var(--start-percent) - var(--slider-height) / 2);
|
|
@@ -1535,19 +1541,6 @@ fig-slider {
|
|
|
1535
1541
|
--abs-delta: max(var(--delta), -1 * var(--delta));
|
|
1536
1542
|
opacity: calc(var(--abs-delta) * 100);
|
|
1537
1543
|
}
|
|
1538
|
-
|
|
1539
|
-
&::after {
|
|
1540
|
-
content: "";
|
|
1541
|
-
width: var(--slider-tick-size);
|
|
1542
|
-
height: var(--slider-tick-size);
|
|
1543
|
-
aspect-ratio: 1;
|
|
1544
|
-
border-radius: 100%;
|
|
1545
|
-
font-size: 0;
|
|
1546
|
-
position: absolute;
|
|
1547
|
-
left: calc(var(--start-percent) - var(--slider-tick-size) / 2);
|
|
1548
|
-
top: calc(50% - var(--slider-tick-size) / 2);
|
|
1549
|
-
background: var(--figma-color-icon-onbrand);
|
|
1550
|
-
}
|
|
1551
1544
|
}
|
|
1552
1545
|
}
|
|
1553
1546
|
|
package/fig.js
CHANGED
|
@@ -6,7 +6,12 @@ function figSupportsPopover() {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
if (window.customElements && !window.customElements.get("fig-button")) {
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* A custom button element that supports different types and states.
|
|
11
|
+
* @attr {string} type - The button type: "button" (default), "toggle", or "submit"
|
|
12
|
+
* @attr {boolean} selected - Whether the button is in a selected state
|
|
13
|
+
* @attr {boolean} disabled - Whether the button is disabled
|
|
14
|
+
*/
|
|
10
15
|
class FigButton extends HTMLElement {
|
|
11
16
|
type;
|
|
12
17
|
#selected;
|
|
@@ -100,7 +105,11 @@ if (window.customElements && !window.customElements.get("fig-button")) {
|
|
|
100
105
|
}
|
|
101
106
|
|
|
102
107
|
if (window.customElements && !window.customElements.get("fig-dropdown")) {
|
|
103
|
-
|
|
108
|
+
/**
|
|
109
|
+
* A custom dropdown/select element.
|
|
110
|
+
* @attr {string} type - The dropdown type: "select" (default) or "dropdown"
|
|
111
|
+
* @attr {string} value - The currently selected value
|
|
112
|
+
*/
|
|
104
113
|
class FigDropdown extends HTMLElement {
|
|
105
114
|
constructor() {
|
|
106
115
|
super();
|
|
@@ -200,13 +209,26 @@ if (window.customElements && !window.customElements.get("fig-dropdown")) {
|
|
|
200
209
|
}
|
|
201
210
|
|
|
202
211
|
/* Tooltip */
|
|
212
|
+
/**
|
|
213
|
+
* A custom tooltip element that displays on hover or click.
|
|
214
|
+
* @attr {string} action - The trigger action: "hover" (default) or "click"
|
|
215
|
+
* @attr {number} delay - Delay in milliseconds before showing tooltip (default: 500)
|
|
216
|
+
* @attr {string} text - The tooltip text content
|
|
217
|
+
* @attr {string} offset - Comma-separated offset values: left,top,right,bottom
|
|
218
|
+
*/
|
|
203
219
|
class FigTooltip extends HTMLElement {
|
|
220
|
+
#boundHideOnChromeOpen;
|
|
221
|
+
#boundHideOnDragStart;
|
|
204
222
|
constructor() {
|
|
205
223
|
super();
|
|
206
224
|
this.action = this.getAttribute("action") || "hover";
|
|
207
225
|
let delay = parseInt(this.getAttribute("delay"));
|
|
208
226
|
this.delay = !isNaN(delay) ? delay : 500;
|
|
209
227
|
this.isOpen = false;
|
|
228
|
+
|
|
229
|
+
// Bind methods that will be used as event listeners
|
|
230
|
+
this.#boundHideOnChromeOpen = this.#hideOnChromeOpen.bind(this);
|
|
231
|
+
this.#boundHideOnDragStart = this.hidePopup.bind(this);
|
|
210
232
|
}
|
|
211
233
|
connectedCallback() {
|
|
212
234
|
this.setup();
|
|
@@ -215,6 +237,14 @@ class FigTooltip extends HTMLElement {
|
|
|
215
237
|
|
|
216
238
|
disconnectedCallback() {
|
|
217
239
|
this.destroy();
|
|
240
|
+
// Remove global listeners
|
|
241
|
+
document.removeEventListener(
|
|
242
|
+
"mousedown",
|
|
243
|
+
this.#boundHideOnChromeOpen,
|
|
244
|
+
true
|
|
245
|
+
);
|
|
246
|
+
// Remove mousedown listener
|
|
247
|
+
this.removeEventListener("mousedown", this.#boundHideOnDragStart);
|
|
218
248
|
}
|
|
219
249
|
|
|
220
250
|
setup() {
|
|
@@ -244,6 +274,8 @@ class FigTooltip extends HTMLElement {
|
|
|
244
274
|
if (this.action === "hover") {
|
|
245
275
|
this.addEventListener("pointerenter", this.showDelayedPopup.bind(this));
|
|
246
276
|
this.addEventListener("pointerleave", this.hidePopup.bind(this));
|
|
277
|
+
// Add mousedown listener instead of dragstart
|
|
278
|
+
this.addEventListener("mousedown", this.#boundHideOnDragStart);
|
|
247
279
|
} else if (this.action === "click") {
|
|
248
280
|
this.addEventListener("click", this.showDelayedPopup.bind(this));
|
|
249
281
|
document.body.addEventListener(
|
|
@@ -251,6 +283,9 @@ class FigTooltip extends HTMLElement {
|
|
|
251
283
|
this.hidePopupOutsideClick.bind(this)
|
|
252
284
|
);
|
|
253
285
|
}
|
|
286
|
+
|
|
287
|
+
// Add listener for chrome interactions
|
|
288
|
+
document.addEventListener("mousedown", this.#boundHideOnChromeOpen, true);
|
|
254
289
|
}
|
|
255
290
|
|
|
256
291
|
getOffset() {
|
|
@@ -331,11 +366,31 @@ class FigTooltip extends HTMLElement {
|
|
|
331
366
|
this.delay = !isNaN(delay) ? delay : 500;
|
|
332
367
|
}
|
|
333
368
|
}
|
|
369
|
+
|
|
370
|
+
#hideOnChromeOpen(e) {
|
|
371
|
+
if (!this.isOpen) return;
|
|
372
|
+
|
|
373
|
+
// Check if the clicked element is a select or opens a dialog
|
|
374
|
+
const target = e.target;
|
|
375
|
+
if (
|
|
376
|
+
target.tagName === "SELECT" ||
|
|
377
|
+
target.hasAttribute("popover") ||
|
|
378
|
+
target.closest("dialog") ||
|
|
379
|
+
target.onclick?.toString().includes("alert")
|
|
380
|
+
) {
|
|
381
|
+
this.hidePopup();
|
|
382
|
+
}
|
|
383
|
+
}
|
|
334
384
|
}
|
|
335
385
|
|
|
336
386
|
customElements.define("fig-tooltip", FigTooltip);
|
|
337
387
|
|
|
338
388
|
/* Popover */
|
|
389
|
+
/**
|
|
390
|
+
* A custom popover element extending FigTooltip.
|
|
391
|
+
* @attr {string} action - The trigger action: "click" (default) or "hover"
|
|
392
|
+
* @attr {string} size - The size of the popover
|
|
393
|
+
*/
|
|
339
394
|
class FigPopover extends FigTooltip {
|
|
340
395
|
static observedAttributes = ["action", "size"];
|
|
341
396
|
|
|
@@ -361,6 +416,11 @@ class FigPopover extends FigTooltip {
|
|
|
361
416
|
customElements.define("fig-popover", FigPopover);
|
|
362
417
|
|
|
363
418
|
/* Dialog */
|
|
419
|
+
/**
|
|
420
|
+
* A custom dialog element for modal and non-modal dialogs.
|
|
421
|
+
* @attr {boolean} open - Whether the dialog is visible
|
|
422
|
+
* @attr {boolean} modal - Whether the dialog should be modal
|
|
423
|
+
*/
|
|
364
424
|
class FigDialog extends HTMLElement {
|
|
365
425
|
constructor() {
|
|
366
426
|
super();
|
|
@@ -545,6 +605,11 @@ class FigPopover2 extends HTMLElement {
|
|
|
545
605
|
window.customElements.define("fig-popover-2", FigPopover2);
|
|
546
606
|
|
|
547
607
|
/* Tabs */
|
|
608
|
+
/**
|
|
609
|
+
* A custom tab element for use within FigTabs.
|
|
610
|
+
* @attr {string} label - The text label of the tab
|
|
611
|
+
* @attr {boolean} selected - Whether the tab is currently selected
|
|
612
|
+
*/
|
|
548
613
|
class FigTab extends HTMLElement {
|
|
549
614
|
constructor() {
|
|
550
615
|
super();
|
|
@@ -562,6 +627,10 @@ class FigTab extends HTMLElement {
|
|
|
562
627
|
}
|
|
563
628
|
window.customElements.define("fig-tab", FigTab);
|
|
564
629
|
|
|
630
|
+
/**
|
|
631
|
+
* A custom tabs container element.
|
|
632
|
+
* @attr {string} name - Identifier for the tabs group
|
|
633
|
+
*/
|
|
565
634
|
class FigTabs extends HTMLElement {
|
|
566
635
|
constructor() {
|
|
567
636
|
super();
|
|
@@ -590,6 +659,11 @@ class FigTabs extends HTMLElement {
|
|
|
590
659
|
window.customElements.define("fig-tabs", FigTabs);
|
|
591
660
|
|
|
592
661
|
/* Segmented Control */
|
|
662
|
+
/**
|
|
663
|
+
* A custom segment element for use within FigSegmentedControl.
|
|
664
|
+
* @attr {string} value - The value associated with this segment
|
|
665
|
+
* @attr {boolean} selected - Whether the segment is currently selected
|
|
666
|
+
*/
|
|
593
667
|
class FigSegment extends HTMLElement {
|
|
594
668
|
#value;
|
|
595
669
|
#selected;
|
|
@@ -635,6 +709,10 @@ class FigSegment extends HTMLElement {
|
|
|
635
709
|
}
|
|
636
710
|
window.customElements.define("fig-segment", FigSegment);
|
|
637
711
|
|
|
712
|
+
/**
|
|
713
|
+
* A custom segmented control container element.
|
|
714
|
+
* @attr {string} name - Identifier for the segmented control group
|
|
715
|
+
*/
|
|
638
716
|
class FigSegmentedControl extends HTMLElement {
|
|
639
717
|
constructor() {
|
|
640
718
|
super();
|
|
@@ -660,6 +738,19 @@ class FigSegmentedControl extends HTMLElement {
|
|
|
660
738
|
window.customElements.define("fig-segmented-control", FigSegmentedControl);
|
|
661
739
|
|
|
662
740
|
/* Slider */
|
|
741
|
+
/**
|
|
742
|
+
* A custom slider input element.
|
|
743
|
+
* @attr {string} type - The slider type: "range", "hue", "delta", "stepper", or "opacity"
|
|
744
|
+
* @attr {number} value - The current value of the slider
|
|
745
|
+
* @attr {number} min - The minimum value
|
|
746
|
+
* @attr {number} max - The maximum value
|
|
747
|
+
* @attr {number} step - The step increment
|
|
748
|
+
* @attr {boolean} text - Whether to show a text input alongside the slider
|
|
749
|
+
* @attr {string} units - The units to display after the value
|
|
750
|
+
* @attr {number} transform - A multiplier for the displayed value
|
|
751
|
+
* @attr {boolean} disabled - Whether the slider is disabled
|
|
752
|
+
* @attr {string} color - The color for the slider track (for opacity type)
|
|
753
|
+
*/
|
|
663
754
|
class FigSlider extends HTMLElement {
|
|
664
755
|
#typeDefaults = {
|
|
665
756
|
range: { min: 0, max: 100, step: 1 },
|
|
@@ -757,6 +848,14 @@ class FigSlider extends HTMLElement {
|
|
|
757
848
|
}
|
|
758
849
|
this.inputContainer.append(this.datalist);
|
|
759
850
|
this.input.setAttribute("list", this.datalist.getAttribute("id"));
|
|
851
|
+
} else if (this.type === "delta") {
|
|
852
|
+
this.datalist = document.createElement("datalist");
|
|
853
|
+
this.datalist.setAttribute("id", figUniqueId());
|
|
854
|
+
let option = document.createElement("option");
|
|
855
|
+
option.setAttribute("value", this.default);
|
|
856
|
+
this.datalist.append(option);
|
|
857
|
+
this.inputContainer.append(this.datalist);
|
|
858
|
+
this.input.setAttribute("list", this.datalist.getAttribute("id"));
|
|
760
859
|
}
|
|
761
860
|
if (this.datalist) {
|
|
762
861
|
let defaultOption = this.datalist.querySelector(
|
|
@@ -874,6 +973,18 @@ class FigSlider extends HTMLElement {
|
|
|
874
973
|
}
|
|
875
974
|
window.customElements.define("fig-slider", FigSlider);
|
|
876
975
|
|
|
976
|
+
/**
|
|
977
|
+
* A custom text input element.
|
|
978
|
+
* @attr {string} type - Input type: "text" (default) or "number"
|
|
979
|
+
* @attr {string} value - The current input value
|
|
980
|
+
* @attr {string} placeholder - Placeholder text
|
|
981
|
+
* @attr {boolean} disabled - Whether the input is disabled
|
|
982
|
+
* @attr {boolean} multiline - Whether to use a textarea instead of input
|
|
983
|
+
* @attr {number} min - Minimum value (for number type)
|
|
984
|
+
* @attr {number} max - Maximum value (for number type)
|
|
985
|
+
* @attr {number} step - Step increment (for number type)
|
|
986
|
+
* @attr {number} transform - A multiplier for displayed number values
|
|
987
|
+
*/
|
|
877
988
|
class FigInputText extends HTMLElement {
|
|
878
989
|
#boundMouseMove;
|
|
879
990
|
#boundMouseUp;
|
|
@@ -1429,6 +1540,14 @@ class FigInputColor extends HTMLElement {
|
|
|
1429
1540
|
window.customElements.define("fig-input-color", FigInputColor);
|
|
1430
1541
|
|
|
1431
1542
|
/* Checkbox */
|
|
1543
|
+
/**
|
|
1544
|
+
* A custom checkbox input element.
|
|
1545
|
+
* @attr {boolean} checked - Whether the checkbox is checked
|
|
1546
|
+
* @attr {boolean} disabled - Whether the checkbox is disabled
|
|
1547
|
+
* @attr {string} label - The label text
|
|
1548
|
+
* @attr {string} name - The form field name
|
|
1549
|
+
* @attr {string} value - The value when checked
|
|
1550
|
+
*/
|
|
1432
1551
|
class FigCheckbox extends HTMLElement {
|
|
1433
1552
|
constructor() {
|
|
1434
1553
|
super();
|
|
@@ -1500,6 +1619,14 @@ class FigCheckbox extends HTMLElement {
|
|
|
1500
1619
|
window.customElements.define("fig-checkbox", FigCheckbox);
|
|
1501
1620
|
|
|
1502
1621
|
/* Radio */
|
|
1622
|
+
/**
|
|
1623
|
+
* A custom radio input element extending FigCheckbox.
|
|
1624
|
+
* @attr {boolean} checked - Whether the radio is selected
|
|
1625
|
+
* @attr {boolean} disabled - Whether the radio is disabled
|
|
1626
|
+
* @attr {string} label - The label text
|
|
1627
|
+
* @attr {string} name - The radio group name
|
|
1628
|
+
* @attr {string} value - The value when selected
|
|
1629
|
+
*/
|
|
1503
1630
|
class FigRadio extends FigCheckbox {
|
|
1504
1631
|
constructor() {
|
|
1505
1632
|
super();
|
|
@@ -1510,6 +1637,14 @@ class FigRadio extends FigCheckbox {
|
|
|
1510
1637
|
window.customElements.define("fig-radio", FigRadio);
|
|
1511
1638
|
|
|
1512
1639
|
/* Switch */
|
|
1640
|
+
/**
|
|
1641
|
+
* A custom switch/toggle input element extending FigCheckbox.
|
|
1642
|
+
* @attr {boolean} checked - Whether the switch is on
|
|
1643
|
+
* @attr {boolean} disabled - Whether the switch is disabled
|
|
1644
|
+
* @attr {string} label - The label text
|
|
1645
|
+
* @attr {string} name - The form field name
|
|
1646
|
+
* @attr {string} value - The value when on
|
|
1647
|
+
*/
|
|
1513
1648
|
class FigSwitch extends FigCheckbox {
|
|
1514
1649
|
render() {
|
|
1515
1650
|
this.input.setAttribute("class", "switch");
|
|
@@ -1542,6 +1677,12 @@ class FigAccordion extends HTMLElement {
|
|
|
1542
1677
|
window.customElements.define("fig-accordion", FigAccordion);
|
|
1543
1678
|
|
|
1544
1679
|
/* Combo Input */
|
|
1680
|
+
/**
|
|
1681
|
+
* A custom combo input with text and dropdown.
|
|
1682
|
+
* @attr {string} options - Comma-separated list of dropdown options
|
|
1683
|
+
* @attr {string} placeholder - Placeholder text for the input
|
|
1684
|
+
* @attr {string} value - The current input value
|
|
1685
|
+
*/
|
|
1545
1686
|
class FigComboInput extends HTMLElement {
|
|
1546
1687
|
constructor() {
|
|
1547
1688
|
super();
|
|
@@ -1610,6 +1751,14 @@ class FigComboInput extends HTMLElement {
|
|
|
1610
1751
|
window.customElements.define("fig-combo-input", FigComboInput);
|
|
1611
1752
|
|
|
1612
1753
|
/* Chit */
|
|
1754
|
+
/**
|
|
1755
|
+
* A custom color/image chip element.
|
|
1756
|
+
* @attr {string} type - The chip type: "color" or "image"
|
|
1757
|
+
* @attr {string} src - Image source URL (for image type)
|
|
1758
|
+
* @attr {string} value - Color value (for color type)
|
|
1759
|
+
* @attr {string} size - Size of the chip: "small" (default) or "large"
|
|
1760
|
+
* @attr {boolean} disabled - Whether the chip is disabled
|
|
1761
|
+
*/
|
|
1613
1762
|
class FigChit extends HTMLElement {
|
|
1614
1763
|
constructor() {
|
|
1615
1764
|
super();
|
|
@@ -1658,6 +1807,13 @@ class FigChit extends HTMLElement {
|
|
|
1658
1807
|
window.customElements.define("fig-chit", FigChit);
|
|
1659
1808
|
|
|
1660
1809
|
/* Upload */
|
|
1810
|
+
/**
|
|
1811
|
+
* A custom image upload element.
|
|
1812
|
+
* @attr {string} src - The current image source URL
|
|
1813
|
+
* @attr {boolean} upload - Whether to show the upload button
|
|
1814
|
+
* @attr {string} label - The upload button label
|
|
1815
|
+
* @attr {string} size - Size of the image preview
|
|
1816
|
+
*/
|
|
1661
1817
|
class FigImage extends HTMLElement {
|
|
1662
1818
|
constructor() {
|
|
1663
1819
|
super();
|