mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-26 23:50:15 +03:00
* - Made the sidebar responsive - Edited the hero-gradient svg to fix an issue where it would never scale to the full width of the sidebar - Fixed a bug on Chrome where you'd need to click twice on a category element in the sidebar to see its tools * - Added hover effect for category button - Disabled transition built into the n-menu element to display the hover effect for tools items directly instead of after a slight delay * - Added a tooltip which shows when the title of the tool is truncated * - Increased sidebar width from 10% to 12.5% - Changed check truncation calculation for container width to a more accurate variant to fix a bug where a tooltip was shown without the text being truncated * fixed merge conflicts * Fixed merge conflict in pnpm lock file * Another fix for merge conflixt pnpm lock file --------- Co-authored-by: sharevb <sharevb@gmail.com>
95 lines
2.3 KiB
Vue
95 lines
2.3 KiB
Vue
<script setup lang="ts">
|
|
import { RouterLink } from 'vue-router';
|
|
import { nextTick, onMounted, onUnmounted, ref } from 'vue';
|
|
import type { Tool } from '@/tools/tools.types';
|
|
|
|
defineProps<{
|
|
tool: Tool
|
|
}>();
|
|
|
|
const textRef = ref<HTMLElement>();
|
|
const showTooltip = ref(false);
|
|
let resizeTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
|
|
async function checkTruncation() {
|
|
await nextTick();
|
|
if (textRef.value) {
|
|
const text = textRef.value.textContent || '';
|
|
const computedStyle = window.getComputedStyle(textRef.value);
|
|
|
|
// Create canvas context for precise text measurement
|
|
const canvas = document.createElement('canvas');
|
|
const context = canvas.getContext('2d')!;
|
|
context.font = `${computedStyle.fontWeight} ${computedStyle.fontSize} ${computedStyle.fontFamily}`;
|
|
|
|
const textWidth = context.measureText(text).width;
|
|
|
|
// Calculate precise container width by accounting for padding
|
|
const containerWidth = textRef.value.clientWidth
|
|
- Number.parseFloat(computedStyle.paddingLeft)
|
|
- Number.parseFloat(computedStyle.paddingRight);
|
|
|
|
showTooltip.value = textWidth > containerWidth;
|
|
}
|
|
}
|
|
|
|
function debouncedCheckTruncation() {
|
|
if (resizeTimeout) {
|
|
clearTimeout(resizeTimeout);
|
|
}
|
|
// Prevent the truncation check from running too frequently when the window is resized
|
|
resizeTimeout = setTimeout(checkTruncation, 500);
|
|
}
|
|
|
|
onMounted(() => {
|
|
checkTruncation();
|
|
window.addEventListener('resize', debouncedCheckTruncation);
|
|
});
|
|
|
|
onUnmounted(() => {
|
|
if (resizeTimeout) {
|
|
clearTimeout(resizeTimeout);
|
|
}
|
|
window.removeEventListener('resize', debouncedCheckTruncation);
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<n-tooltip
|
|
placement="right"
|
|
:delay="500"
|
|
:show-arrow="true"
|
|
:disabled="!showTooltip"
|
|
>
|
|
<template #trigger>
|
|
<RouterLink :to="tool.path" class="menu-link">
|
|
<span
|
|
ref="textRef"
|
|
class="menu-text"
|
|
@mouseenter="checkTruncation"
|
|
>
|
|
{{ tool.name }}
|
|
</span>
|
|
</RouterLink>
|
|
</template>
|
|
{{ tool.name }}
|
|
</n-tooltip>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.menu-link {
|
|
display: block;
|
|
width: 100%;
|
|
text-decoration: none;
|
|
color: inherit;
|
|
}
|
|
|
|
.menu-text {
|
|
display: block;
|
|
width: 100%;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
</style>
|