5
5
* LICENSE file in the root directory of this source tree.
6
6
*/
7
7
8
- import React , { useCallback , useState , useEffect } from 'react' ;
8
+ import React , { useCallback , useState , useEffect } from 'react' ;
9
9
import classnames from 'classnames' ;
10
10
import Link from '@docusaurus/Link' ;
11
11
import useDocusaurusContext from '@docusaurus/useDocusaurusContext' ;
12
12
import useBaseUrl from '@docusaurus/useBaseUrl' ;
13
13
import isInternalUrl from '@docusaurus/isInternalUrl' ;
14
+ import { useLocation } from '@docusaurus/router' ;
14
15
15
16
import SearchBar from '@theme/SearchBar' ;
16
17
import Toggle from '@theme/Toggle' ;
@@ -20,18 +21,18 @@ import useLogo from '@theme/hooks/useLogo';
20
21
21
22
import styles from './styles.module.css' ;
22
23
23
- function noop ( ) { }
24
+ function noop ( ) { }
24
25
25
26
const useLinkLogo = ( logo = { } ) => {
26
27
const {
27
- siteConfig : { baseUrl} = { } ,
28
+ siteConfig : { baseUrl } = { } ,
28
29
} = useDocusaurusContext ( ) ;
29
- const { isDarkTheme} = useThemeContext ( ) ;
30
+ const { isDarkTheme } = useThemeContext ( ) ;
30
31
const logoLink = logo . href || baseUrl ;
31
32
let logoLinkProps = { } ;
32
33
33
34
if ( logo . target ) {
34
- logoLinkProps = { target : logo . target } ;
35
+ logoLinkProps = { target : logo . target } ;
35
36
} else if ( ! isInternalUrl ( logoLink ) ) {
36
37
logoLinkProps = {
37
38
rel : 'noopener noreferrer' ,
@@ -48,10 +49,10 @@ const useLinkLogo = (logo = {}) => {
48
49
} ;
49
50
} ;
50
51
51
- function NavLink ( { activeBasePath, to, href, logo, label, position, ...props } ) {
52
+ function NavLink ( { activeBasePath, to, href, logo, label, position, ...props } ) {
52
53
const toUrl = useBaseUrl ( to ) ;
53
54
const activeBaseUrl = useBaseUrl ( activeBasePath ) ;
54
- const { logoImageUrl, logoAlt} = useLinkLogo ( logo ) ;
55
+ const { logoImageUrl, logoAlt } = useLinkLogo ( logo ) ;
55
56
56
57
const content = logoImageUrl != null ? < img
57
58
className = { classnames ( styles . navbarIcon ) }
@@ -62,27 +63,27 @@ function NavLink({activeBasePath, to, href, logo, label, position, ...props}) {
62
63
< Link
63
64
{ ...( href
64
65
? {
65
- target : '_blank' ,
66
- rel : 'noopener noreferrer' ,
67
- href,
68
- }
66
+ target : '_blank' ,
67
+ rel : 'noopener noreferrer' ,
68
+ href,
69
+ }
69
70
: {
70
- activeClassName : 'navbar__link--active' ,
71
- to : toUrl ,
72
- ...( activeBasePath
73
- ? {
74
- isActive : ( _match , location ) =>
75
- location . pathname . startsWith ( activeBaseUrl ) ,
76
- }
77
- : null ) ,
78
- } ) }
71
+ activeClassName : 'navbar__link--active' ,
72
+ to : toUrl ,
73
+ ...( activeBasePath
74
+ ? {
75
+ isActive : ( _match , location ) =>
76
+ location . pathname . startsWith ( activeBaseUrl ) ,
77
+ }
78
+ : null ) ,
79
+ } ) }
79
80
{ ...props } >
80
81
{ content }
81
82
</ Link >
82
83
) ;
83
84
}
84
85
85
- function NavItem ( { items, emphasis, position, ...props } ) {
86
+ function NavItem ( { items, emphasis, position, ...props } ) {
86
87
if ( ! items ) {
87
88
return < NavLink className = { classnames ( 'navbar__item' , 'navbar__link' , {
88
89
'navbar__link--icon' : props . logo ,
@@ -111,25 +112,29 @@ function NavItem({items, emphasis, position, ...props}) {
111
112
) ;
112
113
}
113
114
115
+ function notPluginPage ( pathname ) {
116
+ return pathname !== '/plugins' && pathname !== '/plugins/' ;
117
+ }
114
118
115
119
function Navbar ( ) {
116
120
const {
117
121
siteConfig : {
118
122
themeConfig : {
119
- navbar : { title, links = [ ] , hideOnScroll = false } = { } ,
123
+ navbar : { title, links = [ ] , hideOnScroll = false } = { } ,
120
124
disableDarkMode = false ,
121
125
} ,
122
126
} ,
123
127
isClient,
124
128
} = useDocusaurusContext ( ) ;
125
129
126
- const [ disableSearchBarPlugIns , setDisableSearchBarPlugIns ] = useState ( location . pathname == "/plugins" ) ;
130
+ const location = useLocation ( ) ;
131
+ const [ enableSearch , setEnableSearch ] = useState ( notPluginPage ( location . pathname ) ) ;
127
132
useEffect ( ( ) => {
128
- setDisableSearchBarPlugIns ( location . pathname == "/plugins" ) ;
129
- } , [ location . pathname ] ) ;
130
- const { isDarkTheme, setLightTheme, setDarkTheme} = useThemeContext ( ) ;
131
- const { navbarRef, isNavbarVisible} = useHideableNavbar ( hideOnScroll ) ;
132
- const { logoLink, logoLinkProps, logoImageUrl, logoAlt} = useLogo ( ) ;
133
+ setEnableSearch ( notPluginPage ( location . pathname ) ) ;
134
+ } , [ location ] ) ;
135
+ const { isDarkTheme, setLightTheme, setDarkTheme } = useThemeContext ( ) ;
136
+ const { navbarRef, isNavbarVisible } = useHideableNavbar ( hideOnScroll ) ;
137
+ const { logoLink, logoLinkProps, logoImageUrl, logoAlt } = useLogo ( ) ;
133
138
const onToggleChange = useCallback (
134
139
e => ( e . target . checked ? setDarkTheme ( ) : setLightTheme ( ) ) ,
135
140
[ setLightTheme , setDarkTheme ] ,
@@ -174,7 +179,7 @@ function Navbar() {
174
179
onChange = { onToggleChange }
175
180
/>
176
181
) }
177
- { ! disableSearchBarPlugIns && (
182
+ { enableSearch && (
178
183
< SearchBar
179
184
handleSearchBarToggle = { noop }
180
185
isSearchBarExpanded = { true }
0 commit comments