11import type { AppTheme } from '../../App' ;
2+ import type { DDropdownItem } from '@react-devui/ui/components/dropdown' ;
23import type { DLang } from '@react-devui/ui/utils/types' ;
34
45import { useTranslation } from 'react-i18next' ;
56import { Link , useLocation } from 'react-router-dom' ;
67
78import { useStorage } from '@react-devui/hooks' ;
89import { DCustomIcon , GithubOutlined } from '@react-devui/icons' ;
9- import { DMenu } from '@react-devui/ui' ;
10+ import { DDropdown , DMenu , DSeparator } from '@react-devui/ui' ;
1011import { getClassName } from '@react-devui/utils' ;
1112
1213export interface AppHeaderProps {
@@ -24,17 +25,6 @@ export function AppHeader(props: AppHeaderProps): JSX.Element | null {
2425 const location = useLocation ( ) ;
2526 const activeId = location . pathname . startsWith ( '/docs' ) ? 'docs' : location . pathname . startsWith ( '/components' ) ? 'components' : null ;
2627
27- const switchLang =
28- languageStorage . value === 'en-US'
29- ? {
30- label : '切换语言为中文' ,
31- text : '中 文' ,
32- }
33- : {
34- label : 'Switch language to English' ,
35- text : 'English' ,
36- } ;
37-
3828 return (
3929 < header className = "app-layout-header" >
4030 < Link className = "d-none d-md-inline-flex app-layout-header__logo-container" to = "/" >
@@ -81,18 +71,44 @@ export function AppHeader(props: AppHeaderProps): JSX.Element | null {
8171 dMode = "horizontal"
8272 dActive = { activeId }
8373 > </ DMenu >
74+ < DSeparator className = "d-none d-md-inline-flex" style = { { margin : '16px 12px' } } dVertical />
8475 < div className = "app-layout-header__button-container" >
85- < button
86- className = "app-layout-header__button app-layout-header__button--text"
87- aria-label = { switchLang . label }
88- onClick = { ( ) => {
89- const val = languageStorage . value === 'en-US' ? 'zh-CN' : 'en-US' ;
90- languageStorage . set ( val ) ;
91- i18n . changeLanguage ( val ) ;
76+ < DDropdown
77+ dList = { (
78+ [
79+ [ '🇨🇳' , '简体中文' , 'zh-CN' ] ,
80+ [ '🇺🇸' , 'English' , 'en-US' ] ,
81+ ] as [ string , string , DLang ] [ ]
82+ ) . map < DDropdownItem < DLang > > ( ( item ) => ( {
83+ id : item [ 2 ] ,
84+ label : (
85+ < >
86+ < div className = "app-layout-header__language-item-region" > { item [ 0 ] } </ div >
87+ < span className = "app-layout-header__language-item-lng" > { item [ 1 ] } </ span >
88+ </ >
89+ ) ,
90+ type : 'item' ,
91+ } ) ) }
92+ onItemClick = { ( id ) => {
93+ languageStorage . set ( id ) ;
94+ i18n . changeLanguage ( id ) ;
9295 } }
9396 >
94- { switchLang . text }
95- </ button >
97+ < button
98+ className = "app-layout-header__button"
99+ aria-label = { t ( 'Change language' ) }
100+ onClick = { ( ) => {
101+ const val = languageStorage . value === 'en-US' ? 'zh-CN' : 'en-US' ;
102+ languageStorage . set ( val ) ;
103+ i18n . changeLanguage ( val ) ;
104+ } }
105+ >
106+ < DCustomIcon viewBox = "0 0 24 24" >
107+ < path d = "M0 0h24v24H0z" fill = "none" > </ path >
108+ < path d = "M12.87 15.07l-2.54-2.51.03-.03c1.74-1.94 2.98-4.17 3.71-6.53H17V4h-7V2H8v2H1v1.99h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04zM18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12zm-2.62 7l1.62-4.33L19.12 17h-3.24z " > </ path >
109+ </ DCustomIcon >
110+ </ button >
111+ </ DDropdown >
96112 < button
97113 className = "app-layout-header__button"
98114 aria-label = { t ( themeStorage . value === 'light' ? 'Dark theme' : 'Light theme' ) }
0 commit comments