mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
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:
1 parent
3b921e64ed
commit
7fd60b0356
2 files changed
+27
-22
No files matched your search
Vendored
+2
@@ -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']
|
||||
|
||||
@@ -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();
|
||||
</c-button>
|
||||
</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 })">
|
||||
<span :class="{ 'rotate-0': isCollapsed, 'rotate-90': !isCollapsed }" text-16px lh-1 op-50 transition-transform>
|
||||
<icon-mdi-chevron-right />
|
||||
@@ -93,7 +107,11 @@ const themeVars = useThemeVars();
|
||||
</span>
|
||||
</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="toggle-bar" @click="toggleCategoryCollapse({ name })" />
|
||||
|
||||
@@ -114,33 +132,18 @@ const themeVars = useThemeVars();
|
||||
<style scoped lang="less">
|
||||
.category-container {
|
||||
.menu-container {
|
||||
overflow: hidden;
|
||||
transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
|
||||
&:not(.collapsed) {
|
||||
max-height: 1000px;
|
||||
opacity: 1;
|
||||
transform: translateY(0);
|
||||
}
|
||||
display: grid;
|
||||
grid-template-rows: 1fr;
|
||||
transition: grid-template-rows var(--animation-duration, 350ms) ease-in-out;
|
||||
|
||||
&.collapsed {
|
||||
max-height: 0;
|
||||
opacity: 0;
|
||||
transform: translateY(-10px);
|
||||
grid-template-rows: 0fr;
|
||||
}
|
||||
|
||||
.menu-wrapper {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
transition: transform 0.4s cubic-bezier(0.2, 0.9, 0.3, 1);
|
||||
|
||||
.menu-container:not(.collapsed) & {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
.menu-container.collapsed & {
|
||||
transform: translateY(-20px);
|
||||
}
|
||||
overflow: hidden;
|
||||
|
||||
.menu {
|
||||
flex: 1;
|
||||
|
||||
Reference in new issue
Block a user