refactor(web): query tooltip

This commit is contained in:
Luke committed 2023-03-28 22:26:01 +02:00
1 parent abe50d59e7
commit 3d34282305
4 files changed
+91 -6

No files matched your search

@@ -13,6 +13,7 @@
import { meta } from 'tinro';
import { fetchNui } from '../../../utils/fetchNui';
import { debouncedTablePage } from '../../../store';
import QueryTooltip from './QueryTooltip.svelte';
const route = meta();
@@ -105,13 +106,24 @@
{#each $table.getRowModel().rows as row}
<tr>
{#each row.getVisibleCells() as cell}
<td
class={`${cell.column.id === 'executionTime' && 'text-center'} p-2 bg-dark-700 ${
row.original.slow && 'text-yellow-500'
}`}
<QueryTooltip
content={cell.getValue()}
let:floatingRef
let:displayTooltip
let:hideTooltip
disabled={cell.column.id !== 'query'}
>
<svelte:component this={flexRender(cell.column.columnDef.cell, cell.getContext())} />
</td>
<td
use:floatingRef
on:mouseenter={displayTooltip}
on:mouseleave={hideTooltip}
class={`${cell.column.id === 'executionTime' && 'text-center'} p-2 bg-dark-700 ${
row.original.slow && 'text-yellow-500'
}`}
>
<svelte:component this={flexRender(cell.column.columnDef.cell, cell.getContext())} />
</td>
</QueryTooltip>
{/each}
</tr>
{/each}
@@ -0,0 +1,46 @@
<script lang="ts">
import { offset, flip, shift } from 'svelte-floating-ui/dom';
import { createFloatingActions } from 'svelte-floating-ui';
import { fade } from 'svelte/transition';
import Portal from 'svelte-portal';
export let content: unknown;
export let disabled: boolean;
const [floatingRef, floatingContent] = createFloatingActions({
strategy: 'absolute',
placement: 'top',
middleware: [offset(6), flip(), shift()],
});
let display = false;
let timer: NodeJS.Timer;
const displayTooltip = () => {
if (disabled) return;
clearTimeout(timer);
timer = setTimeout(() => {
display = true;
}, 300);
};
const hideTooltip = () => {
if (disabled) return;
clearTimeout(timer);
display = false;
};
</script>
<slot {floatingRef} {displayTooltip} {hideTooltip} />
{#if display && !disabled}
<Portal target="body">
<div
transition:fade={{ duration: 150 }}
use:floatingContent
class="absolute p-2 text-sm bg-dark-50 text-dark-400 rounded-md max-w-xl font-main"
>
{content}
</div>
</Portal>
{/if}