summaryrefslogtreecommitdiff
path: root/packages/client/src/scripts/use-tooltip.ts
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2021-11-12 23:53:10 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2021-11-12 23:53:10 +0900
commit4b7b51d5ccdcdad5134edc0232c98e9e8ce2caf5 (patch)
treeefac7fb1f1206466f10923e44c3033564a3b361f /packages/client/src/scripts/use-tooltip.ts
parentenhance: show renoters (#7954) (diff)
downloadsharkey-4b7b51d5ccdcdad5134edc0232c98e9e8ce2caf5.tar.gz
sharkey-4b7b51d5ccdcdad5134edc0232c98e9e8ce2caf5.tar.bz2
sharkey-4b7b51d5ccdcdad5134edc0232c98e9e8ce2caf5.zip
refactor(client): use composition api for tooltip logic
Diffstat (limited to 'packages/client/src/scripts/use-tooltip.ts')
-rw-r--r--packages/client/src/scripts/use-tooltip.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/packages/client/src/scripts/use-tooltip.ts b/packages/client/src/scripts/use-tooltip.ts
new file mode 100644
index 0000000000..2c0c36400d
--- /dev/null
+++ b/packages/client/src/scripts/use-tooltip.ts
@@ -0,0 +1,44 @@
+import { Ref, ref } from 'vue';
+
+export function useTooltip(onShow: (showing: Ref<boolean>) => void) {
+ let isHovering = false;
+ let timeoutId: number;
+
+ let changeShowingState: (() => void) | null;
+
+ const open = () => {
+ close();
+ if (!isHovering) return;
+
+ const showing = ref(true);
+ onShow(showing);
+ changeShowingState = () => {
+ showing.value = false;
+ };
+ };
+
+ const close = () => {
+ if (changeShowingState != null) {
+ changeShowingState();
+ changeShowingState = null;
+ }
+ };
+
+ const onMouseover = () => {
+ if (isHovering) return;
+ isHovering = true;
+ timeoutId = window.setTimeout(open, 300);
+ };
+
+ const onMouseleave = () => {
+ if (!isHovering) return;
+ isHovering = false;
+ window.clearTimeout(timeoutId);
+ close();
+ };
+
+ return {
+ onMouseover,
+ onMouseleave,
+ };
+}