Skip to content

Commit

Permalink
fix(v2): custom searchbar should appear even if themeconfig.algolia i…
Browse files Browse the repository at this point in the history
…s undefined (#1909)

* fix(v2): custom searchbar should appear even if themeconfig.algolia is undefined

* nits

* Docs docs

* inaccuracy

* changelog

* nits
  • Loading branch information
endiliey authored and yangshun committed Oct 30, 2019
1 parent f853171 commit 64871b7
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG-2.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Unreleased

- Fixed a bug in which if `themeConfig.algolia` is not defined, the custom searchbar won't appear.
If you've swizzled Algolia `SearchBar` component before, please update your source code otherwise CSS might break. See [#1909](https://github.com/facebook/docusaurus/pull/1909/files) for reference.
```js
- <Fragment>
+ <div className="navbar__search" key="search-box">
```
- Reduce memory usage consumption.
- Slightly adjust search icon position to be more aligned on small width device.
- Convert sitemap plugin to TypeScript.
Expand Down
14 changes: 5 additions & 9 deletions packages/docusaurus-theme-classic/src/theme/Navbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function Navbar() {
const [theme, setTheme] = useTheme();
const {siteConfig = {}} = context;
const {baseUrl, themeConfig = {}} = siteConfig;
const {algolia, navbar = {}} = themeConfig;
const {navbar = {}} = themeConfig;
const {title, logo = {}, links = []} = navbar;

const showSidebar = useCallback(() => {
Expand Down Expand Up @@ -137,14 +137,10 @@ function Navbar() {
unchecked: <Sun />,
}}
/>
{algolia && (
<div className="navbar__search" key="search-box">
<SearchBar
handleSearchBarToggle={setIsSearchBarExpanded}
isSearchBarExpanded={isSearchBarExpanded}
/>
</div>
)}
<SearchBar
handleSearchBarToggle={setIsSearchBarExpanded}
isSearchBarExpanded={isSearchBarExpanded}
/>
</div>
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import React, {
useState,
useEffect,
Fragment,
useContext,
useRef,
useCallback,
Expand Down Expand Up @@ -60,7 +59,7 @@ const Search = props => {
);

return isEnabled ? (
<Fragment>
<div className="navbar__search" key="search-box">
<span
role="button"
className={classnames('search-icon', {
Expand All @@ -84,7 +83,7 @@ const Search = props => {
onBlur={toggleSearchIconClick}
ref={searchBarRef}
/>
</Fragment>
</div>
) : null;
};

Expand Down
2 changes: 2 additions & 0 deletions website/docs/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ yarn swizzle @docusaurus/theme-classic SearchBar
```

This will create a `src/themes/SearchBar` file in your project folder. Restart your dev server and edit the component, you will see that Docusaurus uses your own `SearchBar` component now.

**Notes**: You can alternatively [swizzle from Algolia SearchBar](#customizing-the-algolia-search-bar) and create your own search component from there.
51 changes: 51 additions & 0 deletions website/docs/theme-classic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
id: theme-classic
title: Classic Theme Configuration
---

_This section is a work in progress._

## Navbar

### Navbar Title & Logo

You can add a logo and title to the navbar via `themeConfig.navbar`. Logo can be placed in [static folder](static-assets.md).

```js
// docusaurus.config.js
module.exports = {
themeConfig: {
navbar: {
title: 'Site Title',
logo: {
alt: 'Site Logo',
src: 'img/logo.svg',
},
}
}
```
### Navbar Links
You can add links to the navbar via `themeConfig.navbar.links`:
```js
// docusaurus/config.js
module.exports = {
themeConfig: {
navbar: {
links: [
{
to: 'docs/docusaurus.config.js',
label: 'docusaurus.config.js',
position: 'left',
},
// ... other links
],
}
}
```
Outbound links automatically get `target="_blank" rel="noopener noreferrer"`.
## Footer
2 changes: 1 addition & 1 deletion website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
{
type: 'category',
label: 'Themes',
items: ['using-themes', 'advanced-themes'],
items: ['using-themes', 'advanced-themes', 'theme-classic'],
},
'presets',
],
Expand Down

0 comments on commit 64871b7

Please sign in to comment.