From 7fd60b0356e9ecaa8e36ae3b0985d274ab29b1b2 Mon Sep 17 00:00:00 2001 From: Dark_Phoenix_ <92178883+0DarkPhoenix@users.noreply.github.com> Date: Sun, 6 Jul 2025 19:07:51 +0200 Subject: [PATCH] Feature: Improve menu bar animation smoothness (#109) Improved the smoothness of the opening an closing animation of the menu items by switching from an overflow: hidden to a display: grid approach Added a function which adds a small amount of extra animation time per tools under a menu item to prevent large menu items (like 'Network') to feel too snappy compared to the other menu items --------- Co-authored-by: sharevb --- components.d.ts | 2 ++ src/components/CollapsibleToolMenu.vue | 47 ++++++++++++++------------ 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/components.d.ts b/components.d.ts index ee6068d1..229d4a08 100644 --- a/components.d.ts +++ b/components.d.ts @@ -193,6 +193,7 @@ declare module '@vue/runtime-core' { IcoConverter: typeof import('./src/tools/ico-converter/ico-converter.vue')['default'] 'IconMdi:brushVariant': typeof import('~icons/mdi/brush-variant')['default'] 'IconMdi:kettleSteamOutline': typeof import('~icons/mdi/kettle-steam-outline')['default'] + IconMdiArrowRightBottom: typeof import('~icons/mdi/arrow-right-bottom')['default'] IconMdiChevronDown: typeof import('~icons/mdi/chevron-down')['default'] IconMdiChevronRight: typeof import('~icons/mdi/chevron-right')['default'] IconMdiClose: typeof import('~icons/mdi/close')['default'] @@ -321,6 +322,7 @@ declare module '@vue/runtime-core' { NMenu: typeof import('naive-ui')['NMenu'] NScrollbar: typeof import('naive-ui')['NScrollbar'] NSpace: typeof import('naive-ui')['NSpace'] + NSpin: typeof import('naive-ui')['NSpin'] NSwitch: typeof import('naive-ui')['NSwitch'] NTable: typeof import('naive-ui')['NTable'] NumberInput: typeof import('./src/tools/pomodoro-timer/app/components/NumberInput.vue')['default'] diff --git a/src/components/CollapsibleToolMenu.vue b/src/components/CollapsibleToolMenu.vue index cf653daa..ee363468 100644 --- a/src/components/CollapsibleToolMenu.vue +++ b/src/components/CollapsibleToolMenu.vue @@ -55,10 +55,24 @@ async function toggleAllCategories() { isToggling.value = false; } +// Function to calculate animation duration based on number of items +function getAnimationDuration(itemCount: number): number { + const baseDuration = 325; + const baseItemCount = 10; + const durationIncrement = 5; + + const additionalDuration = (itemCount - baseItemCount) * durationIncrement; + + // Ensure the duration doesn't go below the base duration + // This means that only if the item count is higher than the base item count, each extra element will add `durationIncrement` milliseconds to the animation + return Math.max(baseDuration + additionalDuration, baseDuration); +} + const menuOptions = computed(() => toolsByCategory.value.map(({ name, components }) => ({ name, isCollapsed: collapsedCategories.value[name] === undefined ? true : collapsedCategories.value[name], + animationDuration: getAnimationDuration(components.length), tools: components.map(tool => ({ label: makeLabel(tool), icon: makeIcon(tool), @@ -82,7 +96,7 @@ const themeVars = useThemeVars(); -
+
@@ -93,7 +107,11 @@ const themeVars = useThemeVars();
-