1
1
import type { AppTheme } from '../../App' ;
2
+ import type { DDropdownItem } from '@react-devui/ui/components/dropdown' ;
2
3
import type { DLang } from '@react-devui/ui/utils/types' ;
3
4
4
5
import { useTranslation } from 'react-i18next' ;
5
6
import { Link , useLocation } from 'react-router-dom' ;
6
7
7
8
import { useStorage } from '@react-devui/hooks' ;
8
9
import { DCustomIcon , GithubOutlined } from '@react-devui/icons' ;
9
- import { DMenu } from '@react-devui/ui' ;
10
+ import { DDropdown , DMenu , DSeparator } from '@react-devui/ui' ;
10
11
import { getClassName } from '@react-devui/utils' ;
11
12
12
13
export interface AppHeaderProps {
@@ -24,17 +25,6 @@ export function AppHeader(props: AppHeaderProps): JSX.Element | null {
24
25
const location = useLocation ( ) ;
25
26
const activeId = location . pathname . startsWith ( '/docs' ) ? 'docs' : location . pathname . startsWith ( '/components' ) ? 'components' : null ;
26
27
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
-
38
28
return (
39
29
< header className = "app-layout-header" >
40
30
< 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 {
81
71
dMode = "horizontal"
82
72
dActive = { activeId }
83
73
> </ DMenu >
74
+ < DSeparator className = "d-none d-md-inline-flex" style = { { margin : '16px 12px' } } dVertical />
84
75
< 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 ) ;
92
95
} }
93
96
>
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 >
96
112
< button
97
113
className = "app-layout-header__button"
98
114
aria-label = { t ( themeStorage . value === 'light' ? 'Dark theme' : 'Light theme' ) }
0 commit comments