mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-20 08:46:44 +02:00
Chore update tooltip
This commit is contained in:
@@ -11,32 +11,48 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, onUnmounted } from 'vue';
|
import { onMounted, onUnmounted, ref } from 'vue';
|
||||||
|
|
||||||
const isVisible = ref(false);
|
const isVisible = ref(false);
|
||||||
const currentTarget = ref<HTMLElement | null>(null);
|
const currentTarget = ref<HTMLElement | null>(null);
|
||||||
const tooltipStyle = ref({});
|
const tooltipStyle = ref({});
|
||||||
|
let showTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
let hideTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
|
|
||||||
const showTooltip = (target: HTMLElement) => {
|
const showTooltip = (target: HTMLElement) => {
|
||||||
|
if (hideTimer) {
|
||||||
|
clearTimeout(hideTimer);
|
||||||
|
hideTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
showTimer = setTimeout(() => {
|
||||||
currentTarget.value = target;
|
currentTarget.value = target;
|
||||||
const rect = target.getBoundingClientRect();
|
const rect = target.getBoundingClientRect();
|
||||||
tooltipStyle.value = {
|
tooltipStyle.value = {
|
||||||
left: `${rect.left + rect.width / 2}px`,
|
left: `${rect.left + rect.width / 2}px`,
|
||||||
top: `${rect.top}px`,
|
top: `${rect.bottom}px`,
|
||||||
};
|
};
|
||||||
isVisible.value = true;
|
isVisible.value = true;
|
||||||
|
}, 400);
|
||||||
};
|
};
|
||||||
|
|
||||||
const hideTooltip = () => {
|
const hideTooltip = () => {
|
||||||
|
if (showTimer) {
|
||||||
|
clearTimeout(showTimer);
|
||||||
|
showTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
hideTimer = setTimeout(() => {
|
||||||
currentTarget.value = null;
|
currentTarget.value = null;
|
||||||
isVisible.value = false;
|
isVisible.value = false;
|
||||||
|
}, 100);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMouseOver = (e: MouseEvent) => {
|
const handleMouseOver = (e: MouseEvent) => {
|
||||||
const target = e.target as HTMLElement;
|
const target = e.target as HTMLElement;
|
||||||
if (
|
if (
|
||||||
target.matches('a[href*="mermaidchart.com"]') ||
|
target.matches('a[href*="try_playground"]') ||
|
||||||
target.matches('button[onclick*="mermaidchart.com"]')
|
target.matches('button[onclick*="try_playground"]')
|
||||||
) {
|
) {
|
||||||
showTooltip(target);
|
showTooltip(target);
|
||||||
}
|
}
|
||||||
@@ -64,9 +80,10 @@ onUnmounted(() => {
|
|||||||
position: fixed;
|
position: fixed;
|
||||||
background: black;
|
background: black;
|
||||||
color: white;
|
color: white;
|
||||||
padding: 0.3rem 0.6rem;
|
padding: 0.25rem 0.5rem;
|
||||||
border-radius: 0.5rem;
|
border-radius: 0.5rem;
|
||||||
font-size: 1rem;
|
font-size: 0.65rem;
|
||||||
|
font-weight: 400;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
z-index: 1000;
|
z-index: 1000;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
@@ -74,7 +91,7 @@ onUnmounted(() => {
|
|||||||
transition:
|
transition:
|
||||||
opacity 0.3s ease,
|
opacity 0.3s ease,
|
||||||
transform 0.3s ease;
|
transform 0.3s ease;
|
||||||
transform: translate(-50%, -90%);
|
transform: translate(-50%, 0);
|
||||||
margin-top: -0.5rem;
|
margin-top: -0.5rem;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -83,6 +100,6 @@ onUnmounted(() => {
|
|||||||
|
|
||||||
.mermaid-chart-tooltip.visible {
|
.mermaid-chart-tooltip.visible {
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
transform: translate(-50%, -100%);
|
transform: translate(-50%, 30%);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@@ -17,7 +17,7 @@ hero:
|
|||||||
actions:
|
actions:
|
||||||
- theme: brand
|
- theme: brand
|
||||||
text: Try Playground
|
text: Try Playground
|
||||||
link: https://www.mermaidchart.com/play
|
link: https://www.mermaidchart.com/play?utm_source=mermaid_js&utm_medium=button&utm_campaign=try_playground
|
||||||
target: _blank
|
target: _blank
|
||||||
rel: external
|
rel: external
|
||||||
- theme: alt
|
- theme: alt
|
||||||
|
Reference in New Issue
Block a user