Skip to content
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

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

Merged
merged 6 commits into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 && (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if no algolia, no searchbar -.-

<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