@onsvisual/svelte-components 1.1.40 → 1.1.42
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.
|
@@ -13,47 +13,27 @@
|
|
|
13
13
|
* Set a maximum width for the tooltip (beyond this width text will wrap)
|
|
14
14
|
* @type {number|null}
|
|
15
15
|
*/
|
|
16
|
-
export let
|
|
16
|
+
export let width = null;
|
|
17
|
+
/**
|
|
18
|
+
* Set z-index of tooltip, to ensure it appears in front of other elements
|
|
19
|
+
* @type {number}
|
|
20
|
+
*/
|
|
21
|
+
export let zIndex = 1;
|
|
17
22
|
|
|
18
23
|
let isHovered = false;
|
|
19
|
-
let currentPos = {};
|
|
20
24
|
|
|
21
|
-
function mouseOver(
|
|
22
|
-
const bboxEl = event.target.getBoundingClientRect();
|
|
23
|
-
const bboxPt = event?.target?.offsetParent?.getBoundingClientRect?.() || { top: 0, left: 0 };
|
|
24
|
-
const x = window.pageXOffset;
|
|
25
|
-
const y = window.pageYOffset;
|
|
26
|
-
const bbox = {
|
|
27
|
-
top: bboxEl.top - bboxPt.top - y,
|
|
28
|
-
bottom: bboxEl.bottom - bboxPt.top - y,
|
|
29
|
-
left: bboxEl.left - bboxPt.left - x,
|
|
30
|
-
right: bboxEl.right - bboxPt.left - x
|
|
31
|
-
};
|
|
32
|
-
currentPos = {
|
|
33
|
-
top:
|
|
34
|
-
(position === "bottom"
|
|
35
|
-
? bbox.bottom
|
|
36
|
-
: position === "top"
|
|
37
|
-
? bbox.top
|
|
38
|
-
: (bbox.top + bbox.bottom) / 2) + window.pageYOffset,
|
|
39
|
-
left:
|
|
40
|
-
(position === "right"
|
|
41
|
-
? bbox.right
|
|
42
|
-
: position === "left"
|
|
43
|
-
? bbox.left
|
|
44
|
-
: (bbox.left + bbox.right) / 2) + window.pageXOffset
|
|
45
|
-
};
|
|
25
|
+
function mouseOver() {
|
|
46
26
|
isHovered = true;
|
|
27
|
+
console.log("hovered");
|
|
47
28
|
}
|
|
48
29
|
function mouseLeave() {
|
|
49
30
|
isHovered = false;
|
|
50
|
-
|
|
51
|
-
function renderDim(dim) {
|
|
52
|
-
return dim ? `${dim}px` : null;
|
|
31
|
+
console.log("unhovered");
|
|
53
32
|
}
|
|
54
33
|
</script>
|
|
55
34
|
|
|
56
35
|
<div
|
|
36
|
+
role="tooltip"
|
|
57
37
|
class="tooltip-wrapper"
|
|
58
38
|
on:mouseenter={mouseOver}
|
|
59
39
|
on:mouseleave={mouseLeave}
|
|
@@ -61,23 +41,22 @@
|
|
|
61
41
|
on:focusout={mouseLeave}
|
|
62
42
|
>
|
|
63
43
|
<slot />
|
|
44
|
+
{#if isHovered}
|
|
45
|
+
<div
|
|
46
|
+
class="tooltip tooltip-{position}"
|
|
47
|
+
style:z-index={zIndex}
|
|
48
|
+
style:width={width != null ? `${width}px` : null}
|
|
49
|
+
style:white-space={width == null ? "nowrap" : "wrap"}
|
|
50
|
+
>
|
|
51
|
+
{text}
|
|
52
|
+
</div>
|
|
53
|
+
{/if}
|
|
64
54
|
</div>
|
|
65
|
-
{#if isHovered}
|
|
66
|
-
<div
|
|
67
|
-
class="tooltip tooltip-{position}"
|
|
68
|
-
style:left={renderDim(currentPos.left)}
|
|
69
|
-
style:right={renderDim(currentPos.right)}
|
|
70
|
-
style:top={renderDim(currentPos.top)}
|
|
71
|
-
style:bottom={renderDim(currentPos.bottom)}
|
|
72
|
-
style:max-width={renderDim(maxWidth)}
|
|
73
|
-
>
|
|
74
|
-
{text}
|
|
75
|
-
</div>
|
|
76
|
-
{/if}
|
|
77
55
|
|
|
78
56
|
<style>
|
|
79
57
|
.tooltip-wrapper {
|
|
80
58
|
display: inline-block;
|
|
59
|
+
position: relative;
|
|
81
60
|
}
|
|
82
61
|
.tooltip {
|
|
83
62
|
position: absolute;
|
|
@@ -89,21 +68,32 @@
|
|
|
89
68
|
padding: 4px 6px;
|
|
90
69
|
border-radius: 4px;
|
|
91
70
|
box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.25);
|
|
71
|
+
word-break: keep-all;
|
|
92
72
|
}
|
|
93
73
|
.tooltip-top {
|
|
94
|
-
|
|
74
|
+
bottom: calc(100% + 8px);
|
|
75
|
+
left: 50%;
|
|
76
|
+
transform: translateX(-50%);
|
|
95
77
|
}
|
|
96
78
|
.tooltip-bottom {
|
|
97
|
-
|
|
79
|
+
top: calc(100% + 8px);
|
|
80
|
+
left: 50%;
|
|
81
|
+
transform: translateX(-50%);
|
|
98
82
|
}
|
|
99
83
|
.tooltip-left {
|
|
100
|
-
|
|
84
|
+
top: 50%;
|
|
85
|
+
right: calc(100% + 8px);
|
|
86
|
+
transform: translateY(-50%);
|
|
101
87
|
}
|
|
102
88
|
.tooltip-right {
|
|
103
|
-
|
|
89
|
+
top: 50%;
|
|
90
|
+
left: calc(100% + 8px);
|
|
91
|
+
transform: translateY(-50%);
|
|
104
92
|
}
|
|
105
93
|
.tooltip-middle {
|
|
106
|
-
|
|
94
|
+
top: calc(50% + 8px);
|
|
95
|
+
left: 50%;
|
|
96
|
+
transform: translateX(-50%);
|
|
107
97
|
}
|
|
108
98
|
.tooltip::before {
|
|
109
99
|
content: " ";
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
/** @typedef {typeof __propDef.events} TooltipEvents */
|
|
3
3
|
/** @typedef {typeof __propDef.slots} TooltipSlots */
|
|
4
4
|
export default class Tooltip extends SvelteComponentTyped<{
|
|
5
|
+
width?: number | null | undefined;
|
|
5
6
|
text?: string | undefined;
|
|
6
7
|
position?: "top" | "bottom" | "left" | "right" | "middle" | undefined;
|
|
7
|
-
|
|
8
|
+
zIndex?: number | undefined;
|
|
8
9
|
}, {
|
|
9
10
|
[evt: string]: CustomEvent<any>;
|
|
10
11
|
}, {
|
|
@@ -17,9 +18,10 @@ export type TooltipSlots = typeof __propDef.slots;
|
|
|
17
18
|
import { SvelteComponentTyped } from "svelte";
|
|
18
19
|
declare const __propDef: {
|
|
19
20
|
props: {
|
|
21
|
+
width?: number | null | undefined;
|
|
20
22
|
text?: string | undefined;
|
|
21
23
|
position?: "top" | "bottom" | "left" | "right" | "middle" | undefined;
|
|
22
|
-
|
|
24
|
+
zIndex?: number | undefined;
|
|
23
25
|
};
|
|
24
26
|
events: {
|
|
25
27
|
[evt: string]: CustomEvent<any>;
|