Skip to content

Commit

Permalink
Tariff chart: price info on long touch (#16707)
Browse files Browse the repository at this point in the history
  • Loading branch information
naltatis authored Oct 17, 2024
1 parent 8aab01f commit b313e3c
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions assets/js/components/TariffChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
'cursor-pointer': slot.selectable,
faded: activeIndex !== null && activeIndex !== index,
}"
@touchstart="hoverSlot(index)"
@touchstart="startLongPress(index)"
@touchend="cancelLongPress"
@touchmove="cancelLongPress"
@mouseenter="hoverSlot(index)"
@touchend="hoverSlot(null)"
@mouseleave="hoverSlot(null)"
@mouseup="hoverSlot(null)"
@click="selectSlot(index)"
Expand Down Expand Up @@ -44,7 +45,12 @@ export default {
},
emits: ["slot-hovered", "slot-selected"],
data() {
return { activeIndex: null, startTime: new Date() };
return {
activeIndex: null,
startTime: new Date(),
longPressTimer: null,
isLongPress: false,
};
},
computed: {
priceInfo() {
Expand Down Expand Up @@ -83,6 +89,10 @@ export default {
this.$emit("slot-hovered", index);
},
selectSlot(index) {
if (this.isLongPress) {
this.isLongPress = false;
return;
}
if (this.slots[index]?.selectable) {
this.$emit("slot-selected", index);
}
Expand All @@ -95,6 +105,16 @@ export default {
: "75%";
return { height };
},
startLongPress(index) {
this.longPressTimer = setTimeout(() => {
this.isLongPress = true;
this.hoverSlot(index);
}, 300);
},
cancelLongPress() {
clearTimeout(this.longPressTimer);
this.hoverSlot(null);
},
},
};
</script>
Expand Down

0 comments on commit b313e3c

Please sign in to comment.