11<template >
2- <div :style =" { width: sidebarWidth + 'px', backgroundColor : colors.sideBar }" class =" sidebar" >
2+ <div :style =" { width: sidebarWidth + 'px', 'background-color' : colors.sideBar }" class =" sidebar" >
33 <div @click =" toggleWidth" class =" collapse-icon" :class =" { 'rotate-180': !toggleBar }" >></div >
44 <nav class =" needPadding" >
55 <router-link v-if =" !toggleBar" to =" /Dashboard" class =" sidebarItem"
6- :class =" { 'active': $route.path === '/Dashboard' }" @click =" setActiveItem('/Dashboard')" >
7- Dashboard
6+ :class =" { 'active': $route.path === '/Dashboard' }" @click =" setActiveItem('/Dashboard')" > Dashboard
87 </router-link >
98 <router-link v-if =" !toggleBar" to =" /Lists" class =" sidebarItem" :class =" { 'active': $route.path === '/Lists' }"
10- @click =" setActiveItem('/Lists')" >
11- Lists
12- </router-link >
9+ @click =" setActiveItem('/Lists')" > Lists </router-link >
1310 <router-link v-if =" !toggleBar" to =" /Learn" class =" sidebarItem" :class =" { 'active': $route.path === '/Learn' }"
14- @click =" setActiveItem('/Learn')" >
15- Learn
16- </router-link >
11+ @click =" setActiveItem('/Learn')" > Learn </router-link >
1712 <router-link v-if =" !toggleBar" to =" /Type" class =" sidebarItem" :class =" { 'active': $route.path === '/Type' }"
18- @click =" setActiveItem('/Type')" >
19- Type
13+ @click =" setActiveItem('/Type')" > Type
2014 </router-link >
2115 <router-link v-if =" !toggleBar" to =" /" class =" sidebarItem" :class =" { 'active': $route.path === '/' }"
22- @click =" setActiveItem('/')" >
23- About Me
24- </router-link >
16+ @click =" setActiveItem('/')" > About Me </router-link >
2517 <router-link v-if =" !toggleBar" to =" /Settings" class =" sidebarItem"
26- :class =" { 'active': $route.path === '/Settings' }" @click =" setActiveItem('/Settings')" >
27- Settings
28- </router-link >
18+ :class =" { 'active': $route.path === '/Settings' }" @click =" setActiveItem('/Settings')" > Settings </router-link >
2919 <router-link v-if =" !toggleBar" to =" /Login" class =" sidebarItem" :class =" { 'active': $route.path === '/Login' }"
30- @click =" setActiveItem('/Login')" >
31- Login
20+ @click =" setActiveItem('/Login')" > Login
3221 </router-link >
3322 </nav >
34- </div >
23+ </div > < router-view :class = " { 'paddingWithSidebar': !toggleBar, 'paddingWithoutSidebar': toggleBar } " > </ router-view >
3524</template >
36-
37- <script >
38- import { ref , onMounted , onUnmounted , computed , inject } from ' vue' ;
39-
40- export default {
41- name: ' SideBar' ,
42- setup () {
25+ <script >import { ref , onMounted , onUnmounted , inject } from ' vue' ;
26+ import colors from ' @/assets/colors.json' ; export default {
27+ name: ' SideBar' , setup () {
4328 const colors = inject (' colors' );
4429 const toggleBar = ref (false );
4530 const sidebarWidth = ref (180 );
4631 const activeItem = ref (null );
47-
4832 const toggleWidth = () => {
4933 toggleBar .value = ! toggleBar .value ;
5034 sidebarWidth .value = toggleBar .value ? 30 : 180 ;
5135 };
52-
53- const setActiveItem = (item ) => {
54- activeItem .value = item;
55- };
56-
57- const handleEscapeKey = (event ) => {
58- if (event .key === ' Escape' ) {
59- toggleWidth ();
60- }
61- };
62-
63- onMounted (() => {
64- // Add event listener when the component is mounted
65- document .addEventListener (' keyup' , handleEscapeKey);
66- });
67-
36+ const setActiveItem = (item ) => { activeItem .value = item; };
37+ const handleEscapeKey = (event ) => { if (event .key === ' Escape' ) { toggleWidth (); } };
38+ onMounted (() => { document .addEventListener (' keyup' , handleEscapeKey);
39+ });
40+
6841 onUnmounted (() => {
69- // Remove event listener when the component is unmounted
42+ // Remove event listener when the component is unmounted
7043 document .removeEventListener (' keyup' , handleEscapeKey);
71- });
72-
73- return {
74- toggleBar,
75- sidebarWidth,
76- toggleWidth,
77- activeItem,
78- setActiveItem,
79- colors
44+ }); return {
45+ toggleBar,
46+ sidebarWidth,
47+ toggleWidth,
48+ activeItem,
49+ setActiveItem,
50+ colors: colors,
8051 };
52+ }, beforeRouteUpdate (to , from , next ) {
53+ // Update the activeItem when the route changes
54+ this .setActiveItem (to .path ); next ();
8155 },
82-
83- beforeRouteUpdate (to , from , next ) {
84- // Update the activeItem when the route changes
85- this .setActiveItem (to .path );
86- next ();
87- },
88- };
89- </script >
90-
56+ }; </script >
9157<style >
9258.sidebar {
9359 height : 100% ;
@@ -153,4 +119,4 @@ export default {
153119.rotate-180 {
154120 transform : rotate (180deg );
155121}
156- </style >
122+ </style >
0 commit comments