Skip to content

Commit

Permalink
tooltip component
Browse files Browse the repository at this point in the history
  • Loading branch information
Kr0nox committed Jul 28, 2023
1 parent 2ffb05d commit 1b55191
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions report-viewer/src/components/ToolTipComponent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<template>
<div class="relative inline-block group">
<slot></slot>
<div
class="absolute hidden group-hover:block bg-black bg-opacity-60 px-1 text-sm rounded-md text-white text-center"
:style="tooltipPosition"
>
<slot name="tooltip"></slot>
<div class="border-4 border-solid absolute" :style="arrowStyle"><!-- Arrow --></div>
</div>
</div>
</template>

<script setup lang="ts">
import { computed, type PropType, type StyleValue } from 'vue'
const props = defineProps({
direction: {
type: String as PropType<'top' | 'bottom' | 'left' | 'right'>,
required: false,
default: 'top'
}
})
const tooltipPosition = computed(() => {
const style: StyleValue = {}
if (props.direction == 'left' || props.direction == 'right') {
style.top = '50%'
style.transform = 'translateY(-50%)'
if (props.direction == 'left') {
style.right = '120%'
} else {
style.left = '120%'
}
} else {
style.left = '50%'
style.transform = 'translateX(-50%)'
}
return style
})
const arrowStyle = computed(() => {
const style: StyleValue = {}
style.content = ' '
function getBorderColor(current: String, other: String) {
return other == current ? 'rgba(0,0,0,0.6)' : 'transparent'
}
style.borderColor = ''
for (const dir of ['top', 'right', 'bottom', 'left']) {
style.borderColor += getBorderColor(dir, props.direction) + ' '
}
if (props.direction == 'left' || props.direction == 'right') {
style.top = '50%'
style.marginTop = '-4px'
} else {
style.left = '50%'
style.marginLeft = '-4px'
}
style[props.direction] = '100%'
return style
})
</script>

0 comments on commit 1b55191

Please sign in to comment.