mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
feat: tooltip only shown when there are elipsis
This commit is contained in:
1 parent
c5719bb1ce
commit
223b50db9e
2 files changed
+41
-5
No files matched your search
@@ -13,6 +13,12 @@ export const tooltip: Action<HTMLElement, Partial<Props>> = (node, config) => {
|
||||
});
|
||||
}
|
||||
},
|
||||
enable() {
|
||||
instance.enable();
|
||||
},
|
||||
disable() {
|
||||
instance.disable();
|
||||
},
|
||||
destroy() {
|
||||
instance.destroy();
|
||||
}
|
||||
|
||||
@@ -1,14 +1,44 @@
|
||||
<script lang="ts">
|
||||
import { tooltip } from '$lib/actions/tooltip';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
let data: HTMLSpanElement;
|
||||
$: content = data?.innerText;
|
||||
|
||||
// TODO: enable tooltip only when there are elipsis
|
||||
// $: if (data?.offsetWidth < data?.scrollWidth) {
|
||||
// }
|
||||
onMount(() => {
|
||||
setTooltip();
|
||||
});
|
||||
|
||||
const setTooltip = () => {
|
||||
if (data.innerText) {
|
||||
const content = data.innerText;
|
||||
const tool = tooltip(data, { content });
|
||||
tool.disable();
|
||||
if (data.offsetWidth < data.scrollWidth) {
|
||||
tool.enable();
|
||||
} else {
|
||||
tool.disable();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const throttle = (fn: () => void, delay: number) => {
|
||||
let timeout = false;
|
||||
return () => {
|
||||
if (!timeout) {
|
||||
timeout = true;
|
||||
fn.apply(this);
|
||||
setTimeout(() => {
|
||||
timeout = false;
|
||||
}, delay);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
//TODO: disable tooltip when text is with elipsis
|
||||
</script>
|
||||
|
||||
<span bind:this={data} class="text u-trim" use:tooltip={{ content, hideOnClick: false }}>
|
||||
<svelte:window on:resize={throttle(setTooltip, 50)} />
|
||||
|
||||
<span bind:this={data} class="text u-trim">
|
||||
<slot />
|
||||
</span>
|
||||
Reference in new issue
Block a user