@@ -2,43 +2,45 @@ import styled from 'styled-components'
22import { NavLink , useLocation } from 'react-router-dom'
33import { useState , useEffect } from 'react' ;
44
5- const SidebarContainer = styled . div < { $isExpanded : boolean } > `
6- width: ${ props => props . $isExpanded ? '180px' : '30px' } ;
7- padding: ${ props => props . $isExpanded ? '16px' : '1px' } ;
5+ const SidebarContainer = styled . div `
6+ width: 100%;
7+ height: 30px;
8+ padding: 8px 16px;
89 border-radius: 2px;
910 border: 1px solid #0050a1;
10- margin-right: 5px;
11- transition: width 0.2s ease;
11+ margin-bottom: 5px;
12+ display: flex;
13+ flex-direction: row;
14+ align-items: center;
15+ gap: 16px;
1216
1317 &:focus {outline:0;}
1418`
1519
16- const NavItem = styled ( NavLink ) < { $isExpanded : boolean } > `
17- display: block;
18- padding: ${ props => props . $isExpanded ? '8px' : '1px' } ;
19- margin: 4px 0;
20+ const NavItem = styled ( NavLink ) `
21+ //padding: 8px 16px;
2022 color: #e04bff;
2123 white-space: nowrap;
22- overflow: hidden;
23- text-overflow: ellipsis;
24+ // overflow: hidden;
25+ // text-overflow: ellipsis;
2426
25- &:hover {
26- translate: ${ props => ! props . $isExpanded ? "''" : " -8px" } ;
27- text-decoration: none;
28- }
29-
30- &:hover:after {
31- color: #535bf2;
32- content: ']';
33- }
34-
35- &:hover:before {
36- color: #535bf2;
37- content: ${ props => ! props . $isExpanded ? "''" : "'['" } ;
38- }
27+ // &:hover {
28+ // transform: translateX( -8px) ;
29+ // text-decoration: none;
30+ // }
31+ //
32+ // &:hover:after {
33+ // color: #535bf2;
34+ // content: ']';
35+ // }
36+ //
37+ // &:hover:before {
38+ // color: #535bf2;
39+ // content: '[' ;
40+ // }
3941
4042 &.hovered {
41- translate: -8px ;
43+ transform: translateX(-2px) ;
4244 }
4345
4446 &.hovered:after {
@@ -59,9 +61,8 @@ interface NavItemType {
5961
6062export const Sidebar = ( ) => {
6163 const [ focusedIndex , setFocusedIndex ] = useState ( - 1 ) ;
62- const [ isExpanded , setIsExpanded ] = useState ( false ) ;
63- const [ isMobile , setIsMobile ] = useState ( window . innerWidth < 768 ) ;
6464 const location = useLocation ( ) ;
65+ const [ isMobile , setIsMobile ] = useState ( window . innerWidth < 768 ) ;
6566
6667 // Helper function to determine shortcut keys
6768 const determineShortcutKeys = ( items : { to : string ; label : string } [ ] ) : NavItemType [ ] => {
@@ -99,20 +100,9 @@ export const Sidebar = () => {
99100
100101 const navItems = determineShortcutKeys ( baseNavItems ) ;
101102
102- // Add mobile detection
103103 useEffect ( ( ) => {
104104 setFocusedIndex ( baseNavItems . findIndex ( item => item . to === location . pathname ) ) ;
105-
106- const handleResize = ( ) => {
107- setIsMobile ( window . innerWidth < 768 ) ;
108- if ( window . innerWidth >= 768 ) {
109- setIsExpanded ( true ) ;
110- }
111- } ;
112-
113- window . addEventListener ( 'resize' , handleResize ) ;
114- return ( ) => window . removeEventListener ( 'resize' , handleResize ) ;
115- } , [ ] ) ;
105+ } , [ location . pathname ] ) ;
116106
117107 // Global keyboard shortcuts
118108 useEffect ( ( ) => {
@@ -122,35 +112,33 @@ export const Sidebar = () => {
122112 return ;
123113 }
124114
125- if ( ! isMobile ) {
126- const pressedKey = e . key . toLowerCase ( ) ;
127- const matchingItem = navItems . find ( item => item . shortcutKey === pressedKey ) ;
128- if ( matchingItem ) {
129- setFocusedIndex ( navItems . indexOf ( matchingItem ) ) ;
130- const link = document . querySelector ( `a[href="${ matchingItem . to } "]` ) as HTMLElement ;
131- link ?. click ( ) ;
132- }
115+ const pressedKey = e . key . toLowerCase ( ) ;
116+ const matchingItem = navItems . find ( item => item . shortcutKey === pressedKey ) ;
117+ if ( matchingItem ) {
118+ setFocusedIndex ( navItems . indexOf ( matchingItem ) ) ;
119+ const link = document . querySelector ( `a[href="${ matchingItem . to } "]` ) as HTMLElement ;
120+ link ?. click ( ) ;
133121 }
134122 } ;
135123
136124 document . addEventListener ( 'keydown' , handleGlobalKeyDown ) ;
137125 return ( ) => document . removeEventListener ( 'keydown' , handleGlobalKeyDown ) ;
138- } , [ navItems , isMobile ] ) ;
139- //
140- // const handleKeyDown = (e: React.KeyboardEvent) => {
141- // if (e.key === 'ArrowDown') {
142- // setFocusedIndex(prev => (prev + 1) % navItems.length);
143- // } else if (e.key === 'ArrowUp') {
144- // setFocusedIndex(prev => (prev - 1 + navItems.length) % navItems.length);
145- // } else if (e.key === 'Enter') {
146- // const link = document.getElementById(`nav-item-${focusedIndex}`);
147- // link?.click();
148- // }
149- // };
126+ } , [ navItems ] ) ;
127+
128+ useEffect ( ( ) => {
129+ const handleResize = ( ) => {
130+ setIsMobile ( window . innerWidth < 768 ) ;
131+ } ;
132+
133+ window . addEventListener ( 'resize' , handleResize ) ;
134+ return ( ) => window . removeEventListener ( 'resize' , handleResize ) ;
135+ } , [ ] ) ;
150136
151137 const renderLabel = ( label : string , shortcutKey : string ) => {
138+ if ( isMobile ) return label ;
139+
152140 const index = label . toLowerCase ( ) . indexOf ( shortcutKey ) ;
153- if ( index === - 1 || isMobile ) return label ;
141+ if ( index === - 1 ) return label ;
154142
155143 return (
156144 < >
@@ -162,26 +150,16 @@ export const Sidebar = () => {
162150 } ;
163151
164152 return (
165- < SidebarContainer
166- tabIndex = { 0 }
167- $isExpanded = { isExpanded || ! isMobile }
168- onClick = { ( ) => isMobile && setIsExpanded ( ! isExpanded ) }
169- >
153+ < SidebarContainer tabIndex = { 0 } className = { 'flex justify-between' } >
170154 { navItems . map ( ( item , index ) => (
171155 < NavItem
172156 key = { item . to }
173- onClick = { ( e ) => {
174- if ( ! isExpanded && isMobile ) {
175- e . preventDefault ( )
176- }
177- setFocusedIndex ( index ) ;
178- } }
157+ onClick = { ( ) => setFocusedIndex ( index ) }
179158 to = { item . to }
180159 id = { `nav-item-${ index } ` }
181- className = { focusedIndex === index && ( ( isMobile && isExpanded ) || ! isMobile ) ? `hovered` : '' }
182- $isExpanded = { isExpanded || ! isMobile }
160+ className = { `${ focusedIndex === index ? 'hovered' : '' } flex-1 text-center` }
183161 >
184- { isMobile && ! isExpanded ? item . label : renderLabel ( item . label , item . shortcutKey ) }
162+ { renderLabel ( item . label , item . shortcutKey ) }
185163 </ NavItem >
186164 ) ) }
187165 </ SidebarContainer >
0 commit comments