Skip to content

Commit 1d5bb86

Browse files
authored
Merge pull request #163 from add-eus/APP-1561-retour-recette-design-mise-a-jour-interface-versioning
2 parents aa8c7f4 + f6f6f9d commit 1d5bb86

1 file changed

Lines changed: 61 additions & 42 deletions

File tree

components/ATooltip.vue

Lines changed: 61 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,100 @@
11
<script setup lang="ts">
2-
import { ref } from "vue";
2+
import { computed, ref } from "vue";
33
44
interface ATooltipProps {
55
content: string;
66
position?: "top" | "right" | "bottom" | "left";
77
color?: "default" | "danger";
8+
noWrap?: boolean;
89
}
910
1011
const props = withDefaults(defineProps<ATooltipProps>(), {
1112
position: "top",
1213
color: "default",
14+
noWrap: false,
1315
});
1416
1517
const tooltipVisible = ref(false);
18+
const tooltipTarget = ref<HTMLElement | null>(null);
19+
const tooltipStyle = computed(() => {
20+
if (!tooltipTarget.value || !tooltipVisible.value) return {};
21+
22+
const targetRect = tooltipTarget.value.getBoundingClientRect();
23+
const style: any = { zIndex: 99999 };
24+
25+
switch (props.position) {
26+
case "top":
27+
style.bottom = `${window.innerHeight - targetRect.top + 5}px`;
28+
style.left = `${targetRect.left + targetRect.width / 2}px`;
29+
style.transform = 'translateX(-50%)';
30+
break;
31+
case "bottom":
32+
style.top = `${targetRect.bottom + 5}px`;
33+
style.left = `${targetRect.left + targetRect.width / 2}px`;
34+
style.transform = 'translateX(-50%)';
35+
break;
36+
case "left":
37+
style.top = `${targetRect.top + targetRect.height / 2}px`;
38+
style.right = `${window.innerWidth - targetRect.left + 5}px`;
39+
style.transform = 'translateY(-50%)';
40+
break;
41+
case "right":
42+
style.top = `${targetRect.top + targetRect.height / 2}px`;
43+
style.left = `${targetRect.right + 5}px`;
44+
style.transform = 'translateY(-50%)';
45+
break;
46+
}
47+
return style;
48+
});
49+
1650
</script>
1751

1852
<template>
1953
<div class="a-tooltip-container">
2054
<div
55+
ref="tooltipTarget"
2156
class="tooltip-target"
2257
@mouseenter="tooltipVisible = true"
2358
@mouseleave="tooltipVisible = false"
2459
>
2560
<slot></slot>
2661
</div>
27-
<transition name="fade-fast">
28-
<div v-if="tooltipVisible" class="tooltip" :class="position, color">
29-
{{ content }}
30-
</div>
31-
</transition>
62+
<teleport to="body">
63+
<transition name="fade-fast">
64+
<div v-if="tooltipVisible" class="tooltip" :class="{ 'no-wrap': noWrap, 'danger': color === 'danger' }" :style="tooltipStyle">
65+
{{ content }}
66+
</div>
67+
</transition>
68+
</teleport>
3269
</div>
3370
</template>
3471

3572
<style scoped lang="scss">
3673
.a-tooltip-container {
3774
position: relative;
3875
width: fit-content;
76+
display: inline-block;
77+
}
3978
40-
.tooltip {
41-
position: absolute;
42-
z-index: 1000;
43-
background-color: var(--a-black);
44-
color: var(--a-white);
45-
padding: 10px;
46-
border-radius: 5px;
47-
font-size: 14px;
48-
pointer-events: none;
49-
50-
&.top {
51-
bottom: calc(100% + 5px);
52-
left: 50%;
53-
transform: translateX(-50%);
54-
}
55-
56-
&.right {
57-
top: 50%;
58-
left: calc(100% + 5px);
59-
transform: translateY(-50%);
60-
}
79+
.tooltip {
80+
position: fixed;
81+
z-index: 99999;
82+
background-color: var(--a-black);
83+
color: var(--a-white);
84+
padding: 10px;
85+
border-radius: 5px;
86+
font-size: 14px;
87+
pointer-events: none;
6188
62-
&.bottom {
63-
top: calc(100% + 5px);
64-
left: 50%;
65-
transform: translateX(-50%);
66-
}
89+
&.danger {
90+
border: 0.5px solid var(--a-danger);
91+
background: var(--a-danger-lightest);
92+
color: var(--a-danger);
93+
}
6794
68-
&.left {
69-
top: 50%;
70-
right: calc(100% + 5px);
71-
transform: translateY(-50%);
72-
}
95+
&.no-wrap {
96+
white-space: nowrap;
7397
}
74-
.danger {
75-
border: 0.5px solid var(--a-danger);
76-
background: var(--a-danger-lightest);
77-
color: var(--a-danger);
78-
}
7998
}
8099
81100
</style>

0 commit comments

Comments
 (0)