-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(v2): allow to change location of search bar #4199
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,10 +44,7 @@ function Navbar(): JSX.Element { | |
navbar: {items, hideOnScroll, style}, | ||
colorMode: {disableSwitch: disableColorModeSwitch}, | ||
} = useThemeConfig(); | ||
|
||
const [sidebarShown, setSidebarShown] = useState(false); | ||
const [isSearchBarExpanded, setIsSearchBarExpanded] = useState(false); | ||
|
||
const {isDarkTheme, setLightTheme, setDarkTheme} = useThemeContext(); | ||
const {navbarRef, isNavbarVisible} = useHideableNavbar(hideOnScroll); | ||
|
||
|
@@ -73,6 +70,7 @@ function Navbar(): JSX.Element { | |
} | ||
}, [windowSize]); | ||
|
||
const hasSearchNavbarItem = items.some((item) => item.type === 'search'); | ||
const {leftItems, rightItems} = splitNavItemsByPosition(items); | ||
|
||
return ( | ||
|
@@ -101,9 +99,7 @@ function Navbar(): JSX.Element { | |
<Logo | ||
className="navbar__brand" | ||
imageClassName="navbar__logo" | ||
titleClassName={clsx('navbar__title', { | ||
[styles.hideLogoText]: isSearchBarExpanded, | ||
})} | ||
titleClassName={clsx('navbar__title')} | ||
/> | ||
{leftItems.map((item, i) => ( | ||
<NavbarItem {...item} key={i} /> | ||
|
@@ -121,10 +117,7 @@ function Navbar(): JSX.Element { | |
onChange={onToggleChange} | ||
/> | ||
)} | ||
<SearchBar | ||
handleSearchBarToggle={setIsSearchBarExpanded} | ||
isSearchBarExpanded={isSearchBarExpanded} | ||
Comment on lines
-125
to
-126
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's dead code, although it may be used by third party plugins implementing local search (not Algolia). It doesn't make sense to support it anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agree, and it's not documented afaik |
||
/> | ||
{!hasSearchNavbarItem && <SearchBar />} | ||
</div> | ||
</div> | ||
<div | ||
|
@@ -152,7 +145,12 @@ function Navbar(): JSX.Element { | |
<div className="menu"> | ||
<ul className="menu__list"> | ||
{items.map((item, i) => ( | ||
<NavbarItem mobile {...item} onClick={hideSidebar} key={i} /> | ||
<NavbarItem | ||
mobile | ||
{...(item as any)} // TODO fix typing | ||
onClick={hideSidebar} | ||
key={i} | ||
/> | ||
))} | ||
</ul> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import React from 'react'; | ||
import type {Props} from '@theme/NavbarItem/SearchNavbarItem'; | ||
import SearchBar from '@theme/SearchBar'; | ||
import styles from './styles.module.css'; | ||
|
||
export default function SearchNavbarItem({mobile}: Props): JSX.Element | null { | ||
if (mobile) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className={styles.searchWrapper}> | ||
<SearchBar /> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
@media (max-width: 996px) { | ||
.searchWrapper { | ||
position: absolute; | ||
right: var(--ifm-navbar-padding-horizontal); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need help with proper typing this 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just added something to fix it
it's not the ideal type but we'll improve that later, as there are many things that are not typed correctly currently