feat(Sidebar): added backgroundcolor for active category and scroll-to logic for active tool (#309)

* Added color to component group when a tool inside that group is currently selected, and changed resistor-calculator icon from a hammer to the omega icon

* - Added scrollto functionality for active tool in sidebar
- Improved icon diversity and correctness for multiple tools

* - Changed scrollto behaviour to trigger on mount and on url path change
- Restored the IT-Tools banner to stick to the top of the screen while scrolling

* Swapped nextTick for setTimeout to fix a delay issue where it didn't scroll to the active tool

* Reduced bottom padding of sidebar to fix an issue where the sidebar was scrollable with all categories closed

Fix #298

---------

Co-authored-by: ShareVB <sharevb@gmail.com>
This commit is contained in:
Dark_Phoenix_andShareVB authored and GitHub committed 2026-02-14 10:04:32 +01:00
1 parent 1c9705764b
commit 64d06e5a1f
23 files changed
+120 -69

No files matched your search

+54 -4
View File
@@ -10,9 +10,9 @@ const props = withDefaults(defineProps<{ toolsByCategory?: ToolCategory[] }>(),
const { toolsByCategory } = toRefs(props);
const route = useRoute();
// Memoize component creation functions
const makeLabel = (tool: Tool) => () => h(MenuItemWithTooltip, { tool, key: tool.path });
const makeIcon = (tool: Tool) => () => h(MenuIconItem, { tool, key: tool.path });
// Memoize component creation functions - wrap in markRaw to prevent reactivity
const makeLabel = (tool: Tool) => () => markRaw(h(MenuItemWithTooltip, { tool, key: tool.path }));
const makeIcon = (tool: Tool) => () => markRaw(h(MenuIconItem, { tool, key: tool.path }));
const collapsedCategories = useStorage<Record<string, boolean>>(
'menu-tool-option:collapsed-categories',
@@ -45,6 +45,7 @@ watchEffect(() => {
});
const isToggling = ref(false);
const menuContainerRefs = ref<Record<string, HTMLElement>>({});
function toggleCategoryCollapse({ name }: { name: string }) {
collapsedCategories.value[name] = !collapsedCategories.value[name];
@@ -84,10 +85,16 @@ function getAnimationDuration(itemCount: number): number {
return baseDuration + (Math.min(itemCount, 30) * durationIncrement);
}
// Function to check if any tool in the category is active
function isCategoryActive(components: Tool[]): boolean {
return components.some(tool => tool.path === route.path);
}
const menuOptions = computed(() =>
toolsByCategory.value.map(({ name, components }) => ({
name,
isCollapsed: collapsedCategories.value[name],
isActive: isCategoryActive(components),
animationDuration: getAnimationDuration(components.length),
tools: components.map(tool => ({
label: makeLabel(tool),
@@ -97,6 +104,37 @@ const menuOptions = computed(() =>
})),
);
async function scrollToActiveItem() {
const activeCategory = toolsByCategory.value.find(({ components }) =>
isCategoryActive(components),
);
if (activeCategory) {
// Expand the active category
collapsedCategories.value[activeCategory.name] = false;
// Wait for the entire animation to complete
await new Promise(resolve => setTimeout(resolve, getAnimationDuration(activeCategory.components.length) + 50));
// Scroll to the active menu item
const menuContainer = menuContainerRefs.value[activeCategory.name];
if (menuContainer) {
const activeItem = menuContainer.querySelector('.router-link-exact-active, .router-link-active');
if (activeItem) {
activeItem.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
}
}
}
onMounted(() => {
scrollToActiveItem();
});
watch(() => route.path, () => {
scrollToActiveItem();
});
const themeVars = useThemeVars();
</script>
@@ -112,9 +150,10 @@ const themeVars = useThemeVars();
</c-button>
</div>
<div v-for="{ name, tools, isCollapsed, animationDuration } of menuOptions" :key="name" class="category-container">
<div v-for="{ name, tools, isCollapsed, isActive, animationDuration } of menuOptions" :key="name" class="category-container">
<button
class="category-button"
:class="{ 'category-active': isActive }"
flex cursor-pointer items-center op-60
@click="toggleCategoryCollapse({ name })"
>
@@ -128,6 +167,7 @@ const themeVars = useThemeVars();
</button>
<div
:ref="el => { if (el) menuContainerRefs[name] = el as HTMLElement }"
class="menu-container"
:class="{ collapsed: isCollapsed }"
:style="{ '--animation-duration': `${animationDuration}ms` }"
@@ -163,6 +203,16 @@ const themeVars = useThemeVars();
background-color: v-bind('themeVars.buttonColor2Hover');
opacity: 0.8;
}
&.category-active {
background-color: color-mix(in srgb, v-bind('themeVars.primaryColor') 40%, transparent);
opacity: 1;
color: white;
&:hover {
background-color: color-mix(in srgb, v-bind('themeVars.primaryColorHover') 50%, transparent);
}
}
}
.category-container {
.menu-container {
+4 -3
View File
@@ -169,17 +169,18 @@ const tools = computed<ToolCategory[]>(() => [
.sider-content {
padding-top: 20px;
padding-bottom: 200px;
padding-bottom: 50px;
}
.hero-wrapper {
position: sticky;
display: flex;
top: 0;
left: 0;
z-index: 10;
height: 150px;
height: 125px;
overflow: hidden;
position: relative;
width: inherit;
.gradient {
position: absolute;
+3 -3
View File
@@ -1,6 +1,6 @@
import { Folder } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { IconFolderSymlink } from '@tabler/icons-vue';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.folder-structure-diagram.title'),
@@ -8,7 +8,7 @@ export const tool = defineTool({
description: t('tools.folder-structure-diagram.description'),
keywords: ['folder', 'structure', 'diagram', 'tree', 'ascii'],
component: () => import('./folder-structure-diagram.vue'),
icon: Folder,
icon: IconFolderSymlink,
createdAt: new Date('2024-04-20'),
category: 'Text',
});
+3 -3
View File
@@ -1,6 +1,6 @@
import { Power } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { Barbell } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.force-converter.title'),
@@ -10,7 +10,7 @@ export const tool = defineTool({
'units', 'newton', 'dyne', 'pond', 'ton-force',
],
component: () => import('./force-converter.vue'),
icon: Power,
icon: Barbell,
createdAt: new Date('2024-08-15'),
category: 'Physics',
});
+3 -3
View File
@@ -1,6 +1,6 @@
import { ArrowsShuffle } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { IconWheel } from '@tabler/icons-vue';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.fortune-wheel.title'),
@@ -8,7 +8,7 @@ export const tool = defineTool({
description: t('tools.fortune-wheel.description'),
keywords: ['fortune', 'wheel'],
component: () => import('./fortune-wheel.vue'),
icon: ArrowsShuffle,
icon: IconWheel,
createdAt: new Date('2025-02-24'),
category: 'Gaming',
});
+3 -3
View File
@@ -1,6 +1,6 @@
import { World } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { IconWorldPin } from '@tabler/icons-vue';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.geo-coordinates-converter.title'),
@@ -8,7 +8,7 @@ export const tool = defineTool({
description: t('tools.geo-coordinates-converter.description'),
keywords: ['geo', 'latitude', 'longitude', 'coordinates', 'converter'],
component: () => import('./geo-coordinates-converter.vue'),
icon: World,
icon: IconWorldPin,
createdAt: new Date('2026-01-09'),
category: 'Converters',
});
+3 -3
View File
@@ -1,6 +1,6 @@
import { Brightness2 } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { Sun } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.illuminance-converter.title'),
@@ -13,7 +13,7 @@ export const tool = defineTool({
'foot', 'candles', 'fc', 'flame',
'nox', 'phot', 'units'],
component: () => import('./illuminance-converter.vue'),
icon: Brightness2,
icon: Sun,
createdAt: new Date('2025-02-09'),
category: 'Physics',
});
+3 -3
View File
@@ -1,6 +1,6 @@
import { Brackets } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { Braces } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.jq-memo.title'),
@@ -8,7 +8,7 @@ export const tool = defineTool({
description: t('tools.jq-memo.description'),
keywords: ['jq', 'cheatsheet', 'memo'],
component: () => import('./jq-memo.vue'),
icon: Brackets,
icon: Braces,
createdAt: new Date('2024-08-15'),
category: 'Cheatsheets',
});
+3 -3
View File
@@ -1,6 +1,6 @@
import { BrandJavascript } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { IconBrandTypescript } from '@tabler/icons-vue';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.json-to-typescript.title'),
@@ -8,7 +8,7 @@ export const tool = defineTool({
description: t('tools.json-to-typescript.description'),
keywords: ['json', 'typescript'],
component: () => import('./json-to-typescript.vue'),
icon: BrandJavascript,
icon: IconBrandTypescript,
createdAt: new Date('2025-05-01'),
category: 'Development',
});
+3 -3
View File
@@ -1,6 +1,6 @@
import { Brackets } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { Braces } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.jsonpath-memo.title'),
@@ -8,7 +8,7 @@ export const tool = defineTool({
description: t('tools.jsonpath-memo.description'),
keywords: ['jsonpath', 'cheatsheet', 'memo'],
component: () => import('./jsonpath-memo.vue'),
icon: Brackets,
icon: Braces,
createdAt: new Date('2024-08-15'),
category: 'Cheatsheets',
});
+3 -3
View File
@@ -1,6 +1,6 @@
import { SquareHalf } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { IconRuler3 } from '@tabler/icons-vue';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.length-converter.title'),
@@ -10,7 +10,7 @@ export const tool = defineTool({
'units', 'meter', 'foot', 'feet', 'inch', 'yard', 'mile', 'pica', 'parsec', 'light',
],
component: () => import('./length-converter.vue'),
icon: SquareHalf,
icon: IconRuler3,
createdAt: new Date('2024-08-15'),
category: 'Physics',
});
+3 -3
View File
@@ -1,6 +1,6 @@
import { Mail } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { IconMailCog } from '@tabler/icons-vue';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.mailto-generator.title'),
@@ -8,7 +8,7 @@ export const tool = defineTool({
description: t('tools.mailto-generator.description'),
keywords: ['mailto', 'generator', 'link'],
component: () => import('./mailto-generator.vue'),
icon: Mail,
icon: IconMailCog,
createdAt: new Date('2025-08-17'),
category: 'Development',
});
+3 -3
View File
@@ -1,6 +1,6 @@
import { Database } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { IconBrandMongodb } from '@tabler/icons-vue';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.mongo-objectid-converter.title'),
@@ -8,7 +8,7 @@ export const tool = defineTool({
description: t('tools.mongo-objectid-converter.description'),
keywords: ['mongo', 'objectid', 'converter', 'timestamp'],
component: () => import('./mongo-objectid-converter.vue'),
icon: Database,
icon: IconBrandMongodb,
createdAt: new Date('2024-08-15'),
category: 'Forensic',
});
+3 -3
View File
@@ -1,6 +1,6 @@
import { ArrowsShuffle } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { IconLockCog } from '@tabler/icons-vue';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.passphrase-generator.title'),
@@ -8,7 +8,7 @@ export const tool = defineTool({
description: t('tools.passphrase-generator.description'),
keywords: ['passphrase', 'random', 'password', 'generator'],
component: () => import('./passphrase-generator.vue'),
icon: ArrowsShuffle,
icon: IconLockCog,
createdAt: new Date('2024-08-15'),
category: 'Generators',
});
+3 -3
View File
@@ -1,6 +1,6 @@
import { Atom } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { Gauge } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.pressure-converter.title'),
@@ -10,7 +10,7 @@ export const tool = defineTool({
'units', 'pascal', 'bar', 'torr', 'atmosphere',
],
component: () => import('./pressure-converter.vue'),
icon: Atom,
icon: Gauge,
createdAt: new Date('2024-08-15'),
category: 'Physics',
});
+2 -2
View File
@@ -1,4 +1,4 @@
import { Hammer } from '@vicons/tabler';
import { Omega } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
@@ -8,7 +8,7 @@ export const tool = defineTool({
description: t('tools.resistor-calculator.description'),
keywords: ['resistor', 'ohm', 'calculator'],
component: () => import('./resistor-calculator.vue'),
icon: Hammer,
icon: Omega,
createdAt: new Date('2025-08-15'),
category: 'Forensic',
});
+3 -3
View File
@@ -1,6 +1,6 @@
import { Database } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { IconDatabaseMinus } from '@tabler/icons-vue';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.sql-minifier.title'),
@@ -8,7 +8,7 @@ export const tool = defineTool({
description: t('tools.sql-minifier.description'),
keywords: ['sql', 'query', 'minifier'],
component: () => import('./sql-minifier.vue'),
icon: Database,
icon: IconDatabaseMinus,
createdAt: new Date('2025-05-01'),
category: 'Development',
});
+3 -3
View File
@@ -1,6 +1,6 @@
import { Database } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { IconDatabaseCog } from '@tabler/icons-vue';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.sql-parameters.title'),
@@ -8,7 +8,7 @@ export const tool = defineTool({
description: t('tools.sql-parameters.description'),
keywords: ['sql', 'select', 'insert', 'parameters'],
component: () => import('./sql-parameters.vue'),
icon: Database,
icon: IconDatabaseCog,
createdAt: new Date('2025-08-15'),
category: 'Development',
});
+3 -3
View File
@@ -1,6 +1,6 @@
import { Database } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { IconDatabaseStar } from '@tabler/icons-vue';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.sql-prettify.title'),
@@ -23,7 +23,7 @@ export const tool = defineTool({
'SQL Server Transact-SQL',
],
component: () => import('./sql-prettify.vue'),
icon: Database,
icon: IconDatabaseStar,
npmPackages: ['sql-formatter'],
category: 'Development',
});
+3 -3
View File
@@ -1,6 +1,6 @@
import { ImageOutlined } from '@vicons/material';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { IconFileTypeSvg } from '@tabler/icons-vue';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.svg-placeholder-generator.title'),
@@ -8,6 +8,6 @@ export const tool = defineTool({
description: t('tools.svg-placeholder-generator.description'),
keywords: ['svg', 'placeholder', 'generator', 'image', 'size', 'mockup'],
component: () => import('./svg-placeholder-generator.vue'),
icon: ImageOutlined,
icon: IconFileTypeSvg,
category: 'Web',
});
+3 -3
View File
@@ -1,6 +1,6 @@
import { Language } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { LanguageHiragana } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.text-to-unicode-names.title'),
@@ -8,7 +8,7 @@ export const tool = defineTool({
description: t('tools.text-to-unicode-names.description'),
keywords: ['text', 'unicode', 'name', 'hexa', 'char', 'code'],
component: () => import('./text-to-unicode-names.vue'),
icon: Language,
icon: LanguageHiragana,
createdAt: new Date('2024-06-10'),
category: 'Text',
});
+3 -3
View File
@@ -1,6 +1,6 @@
import { ArrowsShuffle } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { Language } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.translator.title'),
@@ -8,7 +8,7 @@ export const tool = defineTool({
description: t('tools.translator.description'),
keywords: ['translate', 'language'],
component: () => import('./translator.vue'),
icon: ArrowsShuffle,
icon: Language,
createdAt: new Date('2025-08-15'),
category: 'Text',
externAccessDescription: t('tools.translator.externalAccess'),
+3 -3
View File
@@ -1,6 +1,6 @@
import { Gauge } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
import { IconMeterCube } from '@tabler/icons-vue';
import { defineTool } from '../tool';
export const tool = defineTool({
name: t('tools.volume-converter.title'),
@@ -10,7 +10,7 @@ export const tool = defineTool({
'units', 'meter', 'stere', 'cubic', 'liter', 'barrel', 'gallon', 'pint', 'ounce', 'quart', 'm3',
],
component: () => import('./volume-converter.vue'),
icon: Gauge,
icon: IconMeterCube,
createdAt: new Date('2024-08-15'),
category: 'Physics',
});