@avakhula/ui 0.0.133 → 0.0.135
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/dist/index.js +793 -780
- package/dist/index.umd.cjs +17 -17
- package/package.json +1 -1
- package/src/App.vue +10 -0
- package/src/directives/tooltip/TooltipController.js +17 -1
- package/src/directives/tooltip/tooltip.js +19 -21
package/package.json
CHANGED
package/src/App.vue
CHANGED
|
@@ -9,6 +9,16 @@
|
|
|
9
9
|
v-tooltip="'Cannot be edited because user info were synchronized from another LMS.'"
|
|
10
10
|
readonly />
|
|
11
11
|
</ib-form-group>
|
|
12
|
+
|
|
13
|
+
<ib-form-group class="form-group">
|
|
14
|
+
<ib-label for="first_name" required>
|
|
15
|
+
test
|
|
16
|
+
</ib-label>
|
|
17
|
+
|
|
18
|
+
<ib-input id="first_name" name="first_name"
|
|
19
|
+
v-tooltip="'Cannot be edited because user info were synchronized from another LMS.'"
|
|
20
|
+
readonly />
|
|
21
|
+
</ib-form-group>
|
|
12
22
|
</div>
|
|
13
23
|
</template>
|
|
14
24
|
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { createApp } from "vue";
|
|
2
2
|
import IbTooltip from "../../components/Tooltip/Tooltip.vue";
|
|
3
|
+
import generateUID from "../../helpers/generateUID";
|
|
3
4
|
|
|
4
5
|
export default class Tooltip {
|
|
5
6
|
constructor() {
|
|
6
7
|
this.tooltipInstance = null;
|
|
7
8
|
this.tooltipContainer = null;
|
|
9
|
+
this.uuid = null;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
getTooltipInstance() {
|
|
@@ -15,11 +17,21 @@ export default class Tooltip {
|
|
|
15
17
|
return this.tooltipContainer;
|
|
16
18
|
}
|
|
17
19
|
|
|
20
|
+
getId() {
|
|
21
|
+
return this.uuid;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
generateUID() {
|
|
25
|
+
this.uuid = "tooltip_" + generateUID();
|
|
26
|
+
}
|
|
27
|
+
|
|
18
28
|
createTooltip(el, text) {
|
|
19
29
|
if (!text.length) {
|
|
20
30
|
return;
|
|
21
31
|
}
|
|
22
32
|
|
|
33
|
+
this.generateUID();
|
|
34
|
+
|
|
23
35
|
const tooltipContainerStyles = `
|
|
24
36
|
position: absolute;
|
|
25
37
|
top: 0px;
|
|
@@ -33,12 +45,14 @@ export default class Tooltip {
|
|
|
33
45
|
this.tooltipInstance = createApp(IbTooltip, {
|
|
34
46
|
text: text,
|
|
35
47
|
alwaysVisible: true,
|
|
48
|
+
for: this.uuid,
|
|
36
49
|
});
|
|
37
50
|
|
|
38
51
|
this.tooltipInstance.mount(this.tooltipContainer);
|
|
39
52
|
|
|
40
53
|
setTimeout(() => {
|
|
41
54
|
if (this.tooltipContainer?.firstChild) {
|
|
55
|
+
el.setAttribute("describedby", this.uuid);
|
|
42
56
|
const { top, left, width } = el.getBoundingClientRect();
|
|
43
57
|
const { width: tooltipWidth, height: tooltipHeight } =
|
|
44
58
|
this.tooltipContainer.firstChild.getBoundingClientRect();
|
|
@@ -57,7 +71,9 @@ export default class Tooltip {
|
|
|
57
71
|
}, 100);
|
|
58
72
|
}
|
|
59
73
|
|
|
60
|
-
destroyTooltip() {
|
|
74
|
+
destroyTooltip(el) {
|
|
75
|
+
el?.removeAttribute("describedby");
|
|
76
|
+
this.uuid = null;
|
|
61
77
|
this.tooltipInstance?.unmount();
|
|
62
78
|
this.tooltipInstance = null;
|
|
63
79
|
this.tooltipContainer?.remove();
|
|
@@ -7,36 +7,34 @@ const createTooltip = (el, binding) => {
|
|
|
7
7
|
}
|
|
8
8
|
};
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
10
|
+
const destroyTooltip = (event, el) => {
|
|
11
|
+
const uuid = tooltip.getId();
|
|
12
|
+
|
|
13
|
+
if (el.getAttribute("describedby") !== uuid) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const tooltipContainer = tooltip.getTooltipContainer();
|
|
18
|
+
|
|
19
|
+
const isMouseOverEl = el !== event.target && !el.contains(event.target);
|
|
20
|
+
const isMouseOverTooltip =
|
|
21
|
+
tooltipContainer !== event.target &&
|
|
22
|
+
!tooltipContainer?.contains(event.target);
|
|
23
|
+
|
|
24
|
+
if (isMouseOverEl && isMouseOverTooltip) {
|
|
25
|
+
tooltip.destroyTooltip(el);
|
|
26
|
+
}
|
|
26
27
|
};
|
|
27
28
|
|
|
28
29
|
export const TooltipDirective = {
|
|
29
30
|
mounted(el, binding) {
|
|
30
31
|
el.addEventListener("mouseenter", () => createTooltip(el, binding));
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// document.addEventListener("mousemove", (e) => destroyTooltip(e, el));
|
|
32
|
+
document.addEventListener("mousemove", (e) => destroyTooltip(e, el));
|
|
34
33
|
},
|
|
35
34
|
|
|
36
35
|
beforeUnmount(el, binding) {
|
|
37
36
|
tooltip.destroyTooltip();
|
|
38
37
|
el.removeEventListener("mouseenter", () => createTooltip(el, binding));
|
|
39
|
-
|
|
40
|
-
// document.removeEventListener("mousemove", (e) => destroyTooltip(e, el));
|
|
38
|
+
document.removeEventListener("mousemove", (e) => destroyTooltip(e, el));
|
|
41
39
|
},
|
|
42
40
|
};
|