@farm-investimentos/front-mfe-components 15.14.1 → 15.14.3
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/front-mfe-components.common.js +239 -135
- package/dist/front-mfe-components.common.js.map +1 -1
- package/dist/front-mfe-components.css +1 -1
- package/dist/front-mfe-components.umd.js +239 -135
- package/dist/front-mfe-components.umd.js.map +1 -1
- package/dist/front-mfe-components.umd.min.js +1 -1
- package/dist/front-mfe-components.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Tooltip/Tooltip.scss +2 -2
- package/src/components/Tooltip/Tooltip.vue +146 -40
package/package.json
CHANGED
|
@@ -70,7 +70,7 @@ $arrow-margin: 12px;
|
|
|
70
70
|
&--top-right .farm-tooltip__arrow {
|
|
71
71
|
border-width: $arrow-size $arrow-size 0 $arrow-size;
|
|
72
72
|
border-color: $tooltip-color transparent transparent transparent;
|
|
73
|
-
bottom: -$arrow-size;
|
|
73
|
+
bottom: -$arrow-size + 1px;
|
|
74
74
|
z-index: 99999;
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -80,7 +80,7 @@ $arrow-margin: 12px;
|
|
|
80
80
|
&--bottom-right .farm-tooltip__arrow {
|
|
81
81
|
border-width: 0 $arrow-size $arrow-size $arrow-size;
|
|
82
82
|
border-color: transparent transparent $tooltip-color transparent;
|
|
83
|
-
top: -$arrow-size;
|
|
83
|
+
top: -$arrow-size + 1px;
|
|
84
84
|
z-index: 99999;
|
|
85
85
|
}
|
|
86
86
|
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<span :class="{ 'farm-tooltip': true }" ref="parent">
|
|
3
|
-
<span
|
|
3
|
+
<span
|
|
4
|
+
class="farm-tooltip__activator"
|
|
5
|
+
ref="activator"
|
|
6
|
+
@mouseover="onOver"
|
|
7
|
+
@mouseout="onOut"
|
|
8
|
+
@mouseleave="onOut"
|
|
9
|
+
>
|
|
4
10
|
<slot name="activator" />
|
|
5
11
|
</span>
|
|
6
12
|
|
|
@@ -16,6 +22,7 @@
|
|
|
16
22
|
}"
|
|
17
23
|
:style="styles"
|
|
18
24
|
@mouseout="onOut"
|
|
25
|
+
@mouseleave="onOut"
|
|
19
26
|
>
|
|
20
27
|
<div v-if="hasTitle" class="farm-tooltip__header">
|
|
21
28
|
<div class="farm-tooltip__title">
|
|
@@ -88,6 +95,7 @@ export default defineComponent({
|
|
|
88
95
|
zIndex: 1,
|
|
89
96
|
});
|
|
90
97
|
const slots = useSlots();
|
|
98
|
+
let hideTimeout: number | null = null;
|
|
91
99
|
|
|
92
100
|
const toggleComponent = computed(() => props.value);
|
|
93
101
|
const externalControl = computed(() => props.value !== undefined);
|
|
@@ -95,6 +103,8 @@ export default defineComponent({
|
|
|
95
103
|
const hasTitle = computed(() => !!slots.title);
|
|
96
104
|
|
|
97
105
|
let hasBeenBoostrapped = false;
|
|
106
|
+
let scrollListener = null;
|
|
107
|
+
let isInsideModal = false;
|
|
98
108
|
|
|
99
109
|
const calculatePosition = () => {
|
|
100
110
|
const parentBoundingClientRect = parent.value.getBoundingClientRect();
|
|
@@ -109,62 +119,123 @@ export default defineComponent({
|
|
|
109
119
|
let left = 0;
|
|
110
120
|
let top = 0;
|
|
111
121
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
122
|
+
// Se estiver dentro de um modal, usar coordenadas da viewport (position fixed)
|
|
123
|
+
if (isInsideModal) {
|
|
124
|
+
if (!props.position) {
|
|
125
|
+
left = activatorBoundingClientRect.left + activatorWidth / 2 - popupWidth / 2;
|
|
126
|
+
top = activatorBoundingClientRect.top - popupHeight - 8;
|
|
127
|
+
} else {
|
|
128
|
+
const [verticalPosition, horizontalAlignment] = props.position.split('-');
|
|
118
129
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
left =
|
|
138
|
-
parentBoundingClientRect.left +
|
|
139
|
-
window.scrollX +
|
|
140
|
-
activatorWidth / 2 -
|
|
141
|
-
popupWidth / 2;
|
|
142
|
-
break;
|
|
130
|
+
switch (horizontalAlignment) {
|
|
131
|
+
case 'left':
|
|
132
|
+
left = activatorBoundingClientRect.left - 8;
|
|
133
|
+
break;
|
|
134
|
+
case 'right':
|
|
135
|
+
left = activatorBoundingClientRect.left + activatorWidth - popupWidth + 8;
|
|
136
|
+
break;
|
|
137
|
+
case 'center':
|
|
138
|
+
default:
|
|
139
|
+
left = activatorBoundingClientRect.left + activatorWidth / 2 - popupWidth / 2;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (verticalPosition === 'top') {
|
|
144
|
+
top = activatorBoundingClientRect.top - popupHeight - 8;
|
|
145
|
+
} else {
|
|
146
|
+
top = activatorBoundingClientRect.top + activatorHeight + 8;
|
|
147
|
+
}
|
|
143
148
|
}
|
|
144
149
|
|
|
145
|
-
|
|
150
|
+
// Ajustar para não sair da viewport
|
|
151
|
+
if (left < 5) {
|
|
152
|
+
left = 5;
|
|
153
|
+
} else if (left + popupWidth > window.innerWidth - 5) {
|
|
154
|
+
left = window.innerWidth - popupWidth - 5;
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
// Comportamento original para tooltips fora de modais
|
|
158
|
+
if (!props.position) {
|
|
159
|
+
left =
|
|
160
|
+
parentBoundingClientRect.left +
|
|
161
|
+
window.scrollX +
|
|
162
|
+
activatorWidth / 2 -
|
|
163
|
+
popupWidth / 2;
|
|
164
|
+
|
|
146
165
|
top = parentBoundingClientRect.top + window.scrollY - popupHeight - 8;
|
|
147
166
|
} else {
|
|
148
|
-
|
|
167
|
+
const [verticalPosition, horizontalAlignment] = props.position.split('-');
|
|
168
|
+
|
|
169
|
+
switch (horizontalAlignment) {
|
|
170
|
+
case 'left':
|
|
171
|
+
left = parentBoundingClientRect.left + window.scrollX - 8;
|
|
172
|
+
break;
|
|
173
|
+
case 'right':
|
|
174
|
+
left =
|
|
175
|
+
parentBoundingClientRect.left +
|
|
176
|
+
window.scrollX +
|
|
177
|
+
activatorWidth -
|
|
178
|
+
popupWidth +
|
|
179
|
+
8;
|
|
180
|
+
break;
|
|
181
|
+
case 'center':
|
|
182
|
+
default:
|
|
183
|
+
left =
|
|
184
|
+
parentBoundingClientRect.left +
|
|
185
|
+
window.scrollX +
|
|
186
|
+
activatorWidth / 2 -
|
|
187
|
+
popupWidth / 2;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (verticalPosition === 'top') {
|
|
192
|
+
top = parentBoundingClientRect.top + window.scrollY - popupHeight - 8;
|
|
193
|
+
} else {
|
|
194
|
+
top = parentBoundingClientRect.top + window.scrollY + activatorHeight + 8;
|
|
195
|
+
}
|
|
149
196
|
}
|
|
150
|
-
}
|
|
151
197
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
198
|
+
if (left < window.scrollX) {
|
|
199
|
+
left = window.scrollX + 5;
|
|
200
|
+
} else if (left + popupWidth > window.innerWidth + window.scrollX) {
|
|
201
|
+
left = window.innerWidth + window.scrollX - popupWidth - 5;
|
|
202
|
+
}
|
|
156
203
|
}
|
|
157
204
|
|
|
158
205
|
return { left, top };
|
|
159
206
|
};
|
|
160
207
|
|
|
161
208
|
const onOver = () => {
|
|
209
|
+
// Limpa qualquer timeout de hide
|
|
210
|
+
if (hideTimeout) {
|
|
211
|
+
clearTimeout(hideTimeout);
|
|
212
|
+
hideTimeout = null;
|
|
213
|
+
}
|
|
214
|
+
|
|
162
215
|
showOver.value = true;
|
|
163
216
|
|
|
164
217
|
if (!hasBeenBoostrapped) {
|
|
165
218
|
document.querySelector('body').appendChild(popup.value);
|
|
219
|
+
|
|
220
|
+
// Detectar se está dentro de um modal
|
|
221
|
+
isInsideModal = !!parent.value.closest('.farm-modal');
|
|
222
|
+
|
|
223
|
+
if (isInsideModal) {
|
|
224
|
+
// Usar position fixed para tooltips dentro de modais
|
|
225
|
+
popup.value.style.position = 'fixed';
|
|
226
|
+
// Adicionar listener de scroll para recalcular posição
|
|
227
|
+
scrollListener = () => {
|
|
228
|
+
const { left, top } = calculatePosition();
|
|
229
|
+
styles.left = `${left}px`;
|
|
230
|
+
styles.top = `${top}px`;
|
|
231
|
+
};
|
|
232
|
+
window.addEventListener('scroll', scrollListener, true);
|
|
233
|
+
} else {
|
|
234
|
+
// Comportamento original para tooltips fora de modais
|
|
235
|
+
popup.value.style.position = 'absolute';
|
|
236
|
+
}
|
|
237
|
+
|
|
166
238
|
const { left, top } = calculatePosition();
|
|
167
|
-
|
|
168
239
|
styles.left = `${left}px`;
|
|
169
240
|
styles.top = `${top}px`;
|
|
170
241
|
styles.zIndex = calculateMainZindex();
|
|
@@ -174,7 +245,30 @@ export default defineComponent({
|
|
|
174
245
|
};
|
|
175
246
|
|
|
176
247
|
const onOut = (event: MouseEvent) => {
|
|
177
|
-
|
|
248
|
+
// Limpa qualquer timeout anterior
|
|
249
|
+
if (hideTimeout) {
|
|
250
|
+
clearTimeout(hideTimeout);
|
|
251
|
+
hideTimeout = null;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Verifica se o relatedTarget está contido no parent
|
|
255
|
+
const isRelatedTargetInParent =
|
|
256
|
+
event.relatedTarget && parent.value.contains(event.relatedTarget);
|
|
257
|
+
|
|
258
|
+
if (!isRelatedTargetInParent) {
|
|
259
|
+
// Se não está no parent, agenda o hide com um pequeno delay para evitar flickering
|
|
260
|
+
hideTimeout = window.setTimeout(() => {
|
|
261
|
+
showOver.value = false;
|
|
262
|
+
|
|
263
|
+
// Remover listener de scroll quando tooltip for escondido
|
|
264
|
+
if (scrollListener) {
|
|
265
|
+
window.removeEventListener('scroll', scrollListener, true);
|
|
266
|
+
scrollListener = null;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
hideTimeout = null;
|
|
270
|
+
}, 50);
|
|
271
|
+
}
|
|
178
272
|
};
|
|
179
273
|
|
|
180
274
|
const onClose = () => {
|
|
@@ -185,6 +279,18 @@ export default defineComponent({
|
|
|
185
279
|
};
|
|
186
280
|
|
|
187
281
|
onBeforeUnmount(() => {
|
|
282
|
+
// Limpa o timeout se existir
|
|
283
|
+
if (hideTimeout) {
|
|
284
|
+
clearTimeout(hideTimeout);
|
|
285
|
+
hideTimeout = null;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Limpar listener de scroll se existir
|
|
289
|
+
if (scrollListener) {
|
|
290
|
+
window.removeEventListener('scroll', scrollListener, true);
|
|
291
|
+
scrollListener = null;
|
|
292
|
+
}
|
|
293
|
+
|
|
188
294
|
if (hasBeenBoostrapped) {
|
|
189
295
|
document.querySelector('body').removeChild(popup.value);
|
|
190
296
|
}
|