@@ -2,14 +2,10 @@ import { MenuFoldOutlined } from '@ant-design/icons';
22import { css } from '@emotion/react' ;
33import type { MenuProps } from 'antd' ;
44import { Menu } from 'antd' ;
5- import { useLocale , useLocation , useNavData , useSiteData } from 'dumi' ;
6- import { ILocale , ILocalesConfig } from 'dumi/dist/client/theme-api/types' ;
7- import { useCallback } from 'react' ;
5+ import { useLocation , useNavData } from 'dumi' ;
86import ExternalLink from '../../common/ExternalLink' ;
97import useAdditionalThemeConfig from '../../hooks/useAdditionalThemeConfig' ;
108import useSiteToken from '../../hooks/useSiteToken' ;
11- import { ILocaleEnhance } from '../../types' ;
12- import { getTargetLocalePath } from '../../utils' ;
139import { getMoreLinksGroup } from './More' ;
1410import { type IResponsive } from './index' ;
1511
@@ -86,49 +82,10 @@ const useStyle = () => {
8682 } ;
8783} ;
8884
89- function getNextLang ( locale : ILocale , locales : ILocalesConfig , localesEnhance ?: ILocaleEnhance [ ] ) {
90- const changeLangByHostname = localesEnhance && localesEnhance . every ( ( item ) => item . hostname ) ;
91- if (
92- typeof window !== 'undefined' &&
93- changeLangByHostname &&
94- window . location . hostname !== 'localhost'
95- ) {
96- const nextLocaleEnhance = localesEnhance . find (
97- ( item ) => item . hostname !== window . location . hostname
98- ) ;
99- if ( nextLocaleEnhance ) {
100- const nextLang = locales . find ( ( item ) => item . id === nextLocaleEnhance . id ) ;
101- if ( nextLang ) {
102- return {
103- ...nextLang ,
104- nextPath : window . location . href . replace (
105- window . location . hostname ,
106- nextLocaleEnhance . hostname !
107- )
108- } ;
109- }
110- }
111- }
112-
113- const nextLang = locales . filter ( ( item ) => item . id !== locale . id ) [ 0 ] ;
114- const nextPath = getTargetLocalePath ( {
115- current : locale ,
116- target : nextLang
117- } ) ;
118- return {
119- ...nextLang ,
120- nextPath
121- } ;
122- }
123-
12485export default function Navigation ( { isMobile, responsive } : NavigationProps ) {
125- // 统一使用 themeConfig.nav,使用 useNavData,当存在自定义 pages 时,会导致 nav 混乱
12686 const navList = useNavData ( ) ;
127-
12887 const { pathname, search } = useLocation ( ) ;
129- const { locales } = useSiteData ( ) ;
130- const locale = useLocale ( ) ;
131- const { github, moreLinks = [ ] , localesEnhance } = useAdditionalThemeConfig ( ) ;
88+ const { github, moreLinks = [ ] } = useAdditionalThemeConfig ( ) ;
13289 const activeMenuItem = pathname . split ( '/' ) . slice ( 0 , 2 ) . join ( '/' ) ;
13390 // @ts -ignore
13491 const menuItems : MenuProps [ 'items' ] = ( navList ?? [ ] ) . map ( ( navItem ) => {
@@ -139,45 +96,6 @@ export default function Navigation({ isMobile, responsive }: NavigationProps) {
13996 } ;
14097 } ) ;
14198
142- // 获取小屏幕下多语言导航栏节点
143- const getLangNode = useCallback ( ( ) => {
144- if ( locales . length < 2 ) {
145- return null ;
146- }
147- if ( locales . length === 2 ) {
148- const nextLang = getNextLang ( locale , locales , localesEnhance ) ;
149- return {
150- label : (
151- < a rel = "noopener noreferrer" href = { nextLang . nextPath } >
152- { nextLang . name }
153- </ a >
154- ) ,
155- key : nextLang . id
156- } ;
157- }
158- return {
159- label : < span > { locale . name } </ span > ,
160- key : 'multi-lang' ,
161- children : locales
162- . filter ( ( item ) => item . id !== locale . id )
163- . map ( ( item ) => {
164- const nextPath = getTargetLocalePath ( {
165- current : locale ,
166- target : item
167- } ) ;
168- return {
169- label : (
170- < a rel = "noopener noreferrer" href = { nextPath } >
171- { item . name }
172- </ a >
173- ) ,
174- key : item . id
175- } ;
176- } )
177- } ;
178- } , [ locale , locales , localesEnhance ] ) ;
179-
180- let additional : MenuProps [ 'items' ] ;
18199 const additionalItems : MenuProps [ 'items' ] = [
182100 github
183101 ? {
@@ -189,13 +107,13 @@ export default function Navigation({ isMobile, responsive }: NavigationProps) {
189107 key : 'github'
190108 }
191109 : null ,
192- getLangNode ( ) ,
193110 ...( getMoreLinksGroup ( moreLinks ) || [ ] )
194111 ] ;
195112
113+ let additional : MenuProps [ 'items' ] ;
196114 if ( isMobile ) {
197115 additional = additionalItems ;
198- } else if ( responsive === 'crowded' ) {
116+ } else if ( responsive === 'crowded' || responsive === 'narrow' ) {
199117 additional = [
200118 {
201119 label : < MenuFoldOutlined /> ,
@@ -204,9 +122,11 @@ export default function Navigation({ isMobile, responsive }: NavigationProps) {
204122 }
205123 ] ;
206124 }
125+
207126 const items : MenuProps [ 'items' ] = [ ...( menuItems ?? [ ] ) , ...( additional ?? [ ] ) ] ;
208127 const menuMode = isMobile ? 'inline' : 'horizontal' ;
209128 const style = useStyle ( ) ;
129+
210130 return (
211131 < Menu
212132 items = { items }
0 commit comments