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 <sharevb@gmail.com>
This commit is contained in:
Dark_Phoenix_andsharevb authored and GitHub committed 2025-07-06 19:07:51 +02:00
1 parent 3b921e64ed
commit 7fd60b0356
2 files changed
+27 -22

No files matched your search

+2
View File
@@ -193,6 +193,7 @@ declare module '@vue/runtime-core' {
IcoConverter: typeof import('./src/tools/ico-converter/ico-converter.vue')['default'] IcoConverter: typeof import('./src/tools/ico-converter/ico-converter.vue')['default']
'IconMdi:brushVariant': typeof import('~icons/mdi/brush-variant')['default'] 'IconMdi:brushVariant': typeof import('~icons/mdi/brush-variant')['default']
'IconMdi:kettleSteamOutline': typeof import('~icons/mdi/kettle-steam-outline')['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'] IconMdiChevronDown: typeof import('~icons/mdi/chevron-down')['default']
IconMdiChevronRight: typeof import('~icons/mdi/chevron-right')['default'] IconMdiChevronRight: typeof import('~icons/mdi/chevron-right')['default']
IconMdiClose: typeof import('~icons/mdi/close')['default'] IconMdiClose: typeof import('~icons/mdi/close')['default']
@@ -321,6 +322,7 @@ declare module '@vue/runtime-core' {
NMenu: typeof import('naive-ui')['NMenu'] NMenu: typeof import('naive-ui')['NMenu']
NScrollbar: typeof import('naive-ui')['NScrollbar'] NScrollbar: typeof import('naive-ui')['NScrollbar']
NSpace: typeof import('naive-ui')['NSpace'] NSpace: typeof import('naive-ui')['NSpace']
NSpin: typeof import('naive-ui')['NSpin']
NSwitch: typeof import('naive-ui')['NSwitch'] NSwitch: typeof import('naive-ui')['NSwitch']
NTable: typeof import('naive-ui')['NTable'] NTable: typeof import('naive-ui')['NTable']
NumberInput: typeof import('./src/tools/pomodoro-timer/app/components/NumberInput.vue')['default'] NumberInput: typeof import('./src/tools/pomodoro-timer/app/components/NumberInput.vue')['default']
+25 -22
View File
@@ -55,10 +55,24 @@ async function toggleAllCategories() {
isToggling.value = false; 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(() => const menuOptions = computed(() =>
toolsByCategory.value.map(({ name, components }) => ({ toolsByCategory.value.map(({ name, components }) => ({
name, name,
isCollapsed: collapsedCategories.value[name] === undefined ? true : collapsedCategories.value[name], isCollapsed: collapsedCategories.value[name] === undefined ? true : collapsedCategories.value[name],
animationDuration: getAnimationDuration(components.length),
tools: components.map(tool => ({ tools: components.map(tool => ({
label: makeLabel(tool), label: makeLabel(tool),
icon: makeIcon(tool), icon: makeIcon(tool),
@@ -82,7 +96,7 @@ const themeVars = useThemeVars();
</c-button> </c-button>
</div> </div>
<div v-for="{ name, tools, isCollapsed } of menuOptions" :key="name" class="category-container"> <div v-for="{ name, tools, isCollapsed, animationDuration } of menuOptions" :key="name" class="category-container">
<div ml-6px mt-12px flex cursor-pointer items-center op-60 @click="toggleCategoryCollapse({ name })"> <div ml-6px mt-12px flex cursor-pointer items-center op-60 @click="toggleCategoryCollapse({ name })">
<span :class="{ 'rotate-0': isCollapsed, 'rotate-90': !isCollapsed }" text-16px lh-1 op-50 transition-transform> <span :class="{ 'rotate-0': isCollapsed, 'rotate-90': !isCollapsed }" text-16px lh-1 op-50 transition-transform>
<icon-mdi-chevron-right /> <icon-mdi-chevron-right />
@@ -93,7 +107,11 @@ const themeVars = useThemeVars();
</span> </span>
</div> </div>
<div class="menu-container" :class="{ collapsed: isCollapsed }"> <div
class="menu-container"
:class="{ collapsed: isCollapsed }"
:style="{ '--animation-duration': `${animationDuration}ms` }"
>
<div class="menu-wrapper"> <div class="menu-wrapper">
<div class="toggle-bar" @click="toggleCategoryCollapse({ name })" /> <div class="toggle-bar" @click="toggleCategoryCollapse({ name })" />
@@ -114,33 +132,18 @@ const themeVars = useThemeVars();
<style scoped lang="less"> <style scoped lang="less">
.category-container { .category-container {
.menu-container { .menu-container {
overflow: hidden; display: grid;
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1); grid-template-rows: 1fr;
transition: grid-template-rows var(--animation-duration, 350ms) ease-in-out;
&:not(.collapsed) {
max-height: 1000px;
opacity: 1;
transform: translateY(0);
}
&.collapsed { &.collapsed {
max-height: 0; grid-template-rows: 0fr;
opacity: 0;
transform: translateY(-10px);
} }
.menu-wrapper { .menu-wrapper {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
transition: transform 0.4s cubic-bezier(0.2, 0.9, 0.3, 1); overflow: hidden;
.menu-container:not(.collapsed) & {
transform: translateY(0);
}
.menu-container.collapsed & {
transform: translateY(-20px);
}
.menu { .menu {
flex: 1; flex: 1;