Files
luos/resources/assets/js/components/utils/CustomTooltip.vue

104 lines
2.7 KiB
Vue
Raw Normal View History

<template>
<span
:id="`label-${data.id}`"
@mouseover="hoverHandler"
@mouseleave="unhoverHandler"
v-bind:class="{highlightText: isHighlight, loadingTooltip: isLoading}"
>
2021-08-20 03:50:06 +00:00
{{ data.title }}
2021-08-27 19:15:18 +00:00
<b-tooltip
:target="`label-${data.id}`"
:show.sync="showTooltip"
v-if="showTooltip"
2021-08-27 19:15:18 +00:00
>
2021-08-20 03:50:06 +00:00
{{ labelTooltip }}
<p v-if="labelDescription !== ''">
{{ labelDescription }}
</p>
2021-08-20 03:50:06 +00:00
</b-tooltip>
</span>
</template>
<script>
import api from "./../../api/index";
export default {
name: "CustomTooltip",
props: {
data: Object
},
data() {
return {
labelTooltip: "",
labelDescription: "",
hovering: "",
show: false,
menuMap: {
CASES_INBOX: "inbox",
CASES_DRAFT: "draft",
CASES_PAUSED: "paused",
CASES_SELFSERVICE: "unassigned"
2021-08-20 03:50:06 +00:00
},
isHighlight: false,
showTooltip: false,
isLoading: false,
loading: ""
2021-08-20 03:50:06 +00:00
};
},
methods: {
/**
* Delay the hover event
*/
hoverHandler() {
this.isLoading = true;
this.hovering = setTimeout(() => { this.setTooltip() }, 3000);
},
/**
* Reset the delay and hide the tooltip
*/
unhoverHandler() {
this.labelTooltip = "";
this.labelDescription = "";
this.showTooltip = false;
this.isLoading = false;
clearTimeout(this.hovering);
},
/**
* Set the label to show in the tooltip
2021-08-20 03:50:06 +00:00
*/
setTooltip() {
let that = this;
if (this.menuMap[this.data.id]) {
api.menu.getTooltip(that.data.page).then((response) => {
that.showTooltip = true;
that.isLoading = false;
that.labelTooltip = response.data.label;
});
} else {
api.menu.getTooltipCaseList(that.data)
.then((response) => {
that.showTooltip = true;
that.isLoading = false;
that.labelTooltip = response.data.label;
that.labelDescription = response.data.description;
});
}
},
/**
* Set bold the label
*/
setHighlight() {
this.isHighlight = true;
}
2021-08-20 03:50:06 +00:00
},
};
</script>
<style>
.highlightText {
font-weight: 900;
}
.loadingTooltip {
cursor: wait;
}
</style>