1- import { FC , useContext } from "react" ;
1+ import { FC , useContext , useState } from "react" ;
22import styles from "./styles.module.scss" ;
33import Image from "next/image" ;
44import logoIcon from "@/public/logo-icon.svg" ;
55import logoTextDark from "@/public/logo-text-dark.svg" ;
66import logoText from "@/public/logo-text.svg" ;
77import { ThemeContext } from "@/stores/theme" ;
8- import { Tooltip } from '@douyinfe/semi-ui' ;
9- import { IconGithubLogo , IconMoon , IconSun } from '@douyinfe/semi-icons' ;
8+ import { Github , Menu , Moon , Sun , X } from 'lucide-react' ;
109import { Themes } from "@/constants/enum" ;
1110
1211export interface INavBarProps {
@@ -18,39 +17,48 @@ const navLinks = [
1817 { label : "IoTEdge" , href : "https://iotsharp.net/IoTEdge/" } ,
1918 { label : "IoTEmBASIC" , href : "https://iotsharp.net/IoTEmBASIC/" } ,
2019 { label : "更多项目" , href : "#projects" } ,
21- { label : "商业服务" , href : "https://iotsharp.online " }
20+ { label : "商业服务" , href : "https://iotsharp.net/console " }
2221] ;
2322
2423const NavBar : FC < INavBarProps > = ( { } ) => {
2524 const { setTheme, theme} = useContext ( ThemeContext ) ;
25+ const [ menuOpen , setMenuOpen ] = useState ( false ) ;
2626 const icon = theme === Themes . light ? logoTextDark : logoText ;
27- const iconTheme = theme === Themes . light ? < IconMoon size = "extra-large" /> : < IconSun size = "extra-large" /> ;
27+ const themeLabel = theme === Themes . light ? '切换到暗色模式' : '切换到亮色模式' ;
28+ const iconTheme = theme === Themes . light ? < Moon size = { 24 } /> : < Sun size = { 24 } /> ;
2829 return (
2930 < div className = { styles . navBar } >
3031 < a href = "https://iotsharp.net/" >
3132 < Image src = { logoIcon } alt = "" width = { 35 } height = { 35 } />
3233 < Image src = { icon } alt = "" width = { 135 } height = { 40 } />
3334 </ a >
34- < nav className = { styles . links } aria-label = "主导航" >
35+ < nav
36+ id = "main-navigation"
37+ className = { `${ styles . links } ${ menuOpen ? styles . linksOpen : "" } ` }
38+ aria-label = "主导航"
39+ >
3540 { navLinks . map ( ( item ) => {
3641 if ( item . href . startsWith ( "http" ) ) {
3742 return (
38- < a href = { item . href } key = { item . href } target = "_blank" rel = "noreferrer" >
43+ < a href = { item . href } key = { item . href } target = "_blank" rel = "noreferrer" onClick = { ( ) => setMenuOpen ( false ) } >
3944 { item . label }
4045 </ a >
4146 ) ;
4247 }
4348
4449 return (
45- < a href = { item . href } key = { item . href } >
50+ < a href = { item . href } key = { item . href } onClick = { ( ) => setMenuOpen ( false ) } >
4651 { item . label }
4752 </ a >
4853 ) ;
4954 } ) }
5055 </ nav >
5156 < div className = { styles . themeArea } >
52- < div
53- className = { styles . icon }
57+ < button
58+ type = "button"
59+ className = { styles . iconButton }
60+ title = { themeLabel }
61+ aria-label = { themeLabel }
5462 onClick = { ( ) : void => {
5563 if ( localStorage . getItem ( "theme" ) === Themes . light ) {
5664 setTheme ( Themes . dark ) ;
@@ -59,21 +67,28 @@ const NavBar: FC<INavBarProps> = ({}) => {
5967 }
6068 } }
6169 >
62- < Tooltip position = "bottom" content = { Themes . light ? '切换到暗色模式' : '切换到亮色模式' } >
63- { iconTheme }
64- </ Tooltip >
65- </ div >
66- < div className = { styles . icon } onClick = { ( ) : void => {
70+ { iconTheme }
71+ </ button >
72+ < button type = "button" className = { styles . iconButton } title = "查看 GitHub" aria-label = "查看 GitHub" onClick = { ( ) : void => {
6773 window . open (
6874 "https://github.com/IoTSharp" ,
6975 "blank" ,
7076 "noopener=yes,noreferrer=yes"
7177 ) ;
7278 } } >
73- < Tooltip position = "bottom" content = "查看Github" >
74- < IconGithubLogo size = "extra-large" />
75- </ Tooltip >
76- </ div >
79+ < Github size = { 24 } />
80+ </ button >
81+ < button
82+ type = "button"
83+ className = { `${ styles . iconButton } ${ styles . menuButton } ` }
84+ title = { menuOpen ? "关闭导航" : "打开导航" }
85+ aria-label = { menuOpen ? "关闭导航" : "打开导航" }
86+ aria-expanded = { menuOpen }
87+ aria-controls = "main-navigation"
88+ onClick = { ( ) => setMenuOpen ( ( open ) => ! open ) }
89+ >
90+ { menuOpen ? < X size = { 24 } /> : < Menu size = { 24 } /> }
91+ </ button >
7792 </ div >
7893 </ div >
7994 ) ;
0 commit comments