Skip to content

Commit 98f1313

Browse files
committed
feat: add slow-cascade-drop animation for sidebar dropdown menu
1 parent 4179041 commit 98f1313

1 file changed

Lines changed: 49 additions & 5 deletions

File tree

adminforth/spa/src/components/Sidebar.vue

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,14 @@
9090
</svg>
9191
</button>
9292

93-
<ul :id="`dropdown-example${i}`" role="none" class="af-sidebar-dropdown pt-1 space-y-1" :class="{ 'hidden': !opened.includes(i) }">
94-
<template v-for="(child, j) in item.children" :key="`menu-${i}-${j}`">
93+
<transition name="slow-drop">
94+
<ul v-show="opened.includes(i)" :id="`dropdown-example${i}`" role="none" class="af-sidebar-dropdown pt-1 space-y-1 overflow-hidden"> <template v-for="(child, j) in item.children" :key="`menu-${i}-${j}`">
9595
<li class="af-sidebar-menu-link">
9696
<MenuLink :item="child" isChild="true" @click="$emit('hideSidebar')"/>
97-
</li>
98-
</template>
99-
</ul>
97+
</li>
98+
</template>
99+
</ul>
100+
</transition>
100101
</li>
101102
<li v-else class="af-sidebar-menu-link">
102103
<MenuLink :item="item" @click="$emit('hideSidebar')"/>
@@ -292,6 +293,49 @@
292293
background-color: rgba(75, 85, 99, 0.4);
293294
}
294295
296+
/* Custom animation for dropdown */
297+
.slow-drop-enter-active {
298+
transition: grid-template-rows 0.3s ease-out, opacity 0.2s ease-out;
299+
display: grid;
300+
grid-template-rows: 1fr;
301+
}
302+
303+
.slow-drop-leave-active {
304+
transition: grid-template-rows 0.2s ease-in, opacity 0.2s ease-in;
305+
display: grid;
306+
grid-template-rows: 0fr;
307+
}
308+
309+
.slow-drop-enter-from,
310+
.slow-drop-leave-to {
311+
grid-template-rows: 0fr;
312+
opacity: 0;
313+
}
314+
315+
.slow-drop-enter-active li {
316+
opacity: 0;
317+
transform: translateY(-8px);
318+
transition: opacity 0.2s ease-out, transform 0.2s ease-out;
319+
320+
@for $i from 1 through 10 {
321+
&:nth-child(#{$i}) {
322+
transition-delay: #{0.03 + ($i * 0.03)}s;
323+
}
324+
}
325+
}
326+
327+
.slow-drop-enter-to li {
328+
opacity: 1;
329+
transform: translateY(0);
330+
}
331+
332+
.slow-drop-leave-active li {
333+
transition: opacity 0.1s ease-in;
334+
opacity: 0;
335+
transition-delay: 0s !important;
336+
}
337+
338+
295339
/* For browsers that support overlay scrollbars natively */
296340
@supports (overflow: overlay) {
297341
.sidebar-scroll {

0 commit comments

Comments
 (0)