@marianmeres/stuic 2.20.0 → 2.21.1
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.
|
@@ -24,8 +24,11 @@ export declare function isPopoverSupported(): boolean;
|
|
|
24
24
|
export type PopoverPosition = "top" | "top-left" | "top-right" | "top-span-left" | "top-span-right" | "bottom" | "bottom-left" | "bottom-right" | "bottom-span-left" | "bottom-span-right" | "left" | "right";
|
|
25
25
|
/**
|
|
26
26
|
* Trigger mode for the popover.
|
|
27
|
+
* - "click": Opens/closes on click (default)
|
|
28
|
+
* - "hover": Opens on hover/focus, closes on leave/blur
|
|
29
|
+
* - "hover-or-click": Hover primary, click as fallback (for touch devices)
|
|
27
30
|
*/
|
|
28
|
-
export type PopoverTrigger = "click" | "hover";
|
|
31
|
+
export type PopoverTrigger = "click" | "hover" | "hover-or-click";
|
|
29
32
|
/**
|
|
30
33
|
* Options for the popover action.
|
|
31
34
|
*/
|
|
@@ -36,7 +39,7 @@ export interface PopoverOptions {
|
|
|
36
39
|
content?: THC | null;
|
|
37
40
|
/** Preferred position relative to anchor */
|
|
38
41
|
position?: PopoverPosition;
|
|
39
|
-
/** Trigger mode: "click" (default) or "hover" */
|
|
42
|
+
/** Trigger mode: "click" (default), "hover", or "hover-or-click" (both, click as touch fallback) */
|
|
40
43
|
trigger?: PopoverTrigger;
|
|
41
44
|
/** Delay before showing (ms), mainly for hover mode */
|
|
42
45
|
showDelay?: number;
|
|
@@ -95,6 +98,18 @@ export interface PopoverOptions {
|
|
|
95
98
|
*
|
|
96
99
|
* @example
|
|
97
100
|
* ```svelte
|
|
101
|
+
* <!-- Hover with click fallback (for touch devices) -->
|
|
102
|
+
* <button use:popover={() => ({
|
|
103
|
+
* content: "Works on hover and touch!",
|
|
104
|
+
* trigger: "hover-or-click",
|
|
105
|
+
* position: "top"
|
|
106
|
+
* })}>
|
|
107
|
+
* Hover or Tap
|
|
108
|
+
* </button>
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```svelte
|
|
98
113
|
* <!-- With component content -->
|
|
99
114
|
* <button use:popover={() => ({
|
|
100
115
|
* content: { component: MyComponent, props: { foo: "bar" } }
|
|
@@ -117,6 +117,18 @@ function getStringContent(content) {
|
|
|
117
117
|
*
|
|
118
118
|
* @example
|
|
119
119
|
* ```svelte
|
|
120
|
+
* <!-- Hover with click fallback (for touch devices) -->
|
|
121
|
+
* <button use:popover={() => ({
|
|
122
|
+
* content: "Works on hover and touch!",
|
|
123
|
+
* trigger: "hover-or-click",
|
|
124
|
+
* position: "top"
|
|
125
|
+
* })}>
|
|
126
|
+
* Hover or Tap
|
|
127
|
+
* </button>
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```svelte
|
|
120
132
|
* <!-- With component content -->
|
|
121
133
|
* <button use:popover={() => ({
|
|
122
134
|
* content: { component: MyComponent, props: { foo: "bar" } }
|
|
@@ -191,12 +203,10 @@ export function popover(anchorEl, fn) {
|
|
|
191
203
|
}
|
|
192
204
|
function onClickTrigger(e) {
|
|
193
205
|
e.stopPropagation();
|
|
194
|
-
if (isVisible)
|
|
206
|
+
if (isVisible)
|
|
195
207
|
hide();
|
|
196
|
-
|
|
197
|
-
else {
|
|
208
|
+
else
|
|
198
209
|
show();
|
|
199
|
-
}
|
|
200
210
|
}
|
|
201
211
|
// Render content into popover element
|
|
202
212
|
function renderContent() {
|
|
@@ -416,13 +426,20 @@ export function popover(anchorEl, fn) {
|
|
|
416
426
|
if (trigger === "click") {
|
|
417
427
|
anchorEl.addEventListener("click", onClickTrigger);
|
|
418
428
|
}
|
|
419
|
-
else {
|
|
420
|
-
// hover mode
|
|
429
|
+
else if (trigger === "hover") {
|
|
421
430
|
anchorEl.addEventListener("mouseenter", scheduleShow);
|
|
422
431
|
anchorEl.addEventListener("mouseleave", scheduleHide);
|
|
423
432
|
anchorEl.addEventListener("focus", scheduleShow);
|
|
424
433
|
anchorEl.addEventListener("blur", scheduleHide);
|
|
425
434
|
}
|
|
435
|
+
else if (trigger === "hover-or-click") {
|
|
436
|
+
// Both: hover primary, click fallback for touch
|
|
437
|
+
anchorEl.addEventListener("mouseenter", scheduleShow);
|
|
438
|
+
anchorEl.addEventListener("mouseleave", scheduleHide);
|
|
439
|
+
anchorEl.addEventListener("focus", scheduleShow);
|
|
440
|
+
anchorEl.addEventListener("blur", scheduleHide);
|
|
441
|
+
anchorEl.addEventListener("click", onClickTrigger);
|
|
442
|
+
}
|
|
426
443
|
return () => {
|
|
427
444
|
anchorEl.removeEventListener("click", onClickTrigger);
|
|
428
445
|
anchorEl.removeEventListener("mouseenter", scheduleShow);
|