Skip to content

Commit

Permalink
feat(theme-classic): allow className as option for type: "search"
Browse files Browse the repository at this point in the history
  • Loading branch information
KuerbiskernJan committed May 6, 2022
1 parent 1a34883 commit 54e97d6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/docusaurus-theme-classic/src/theme-classic.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ declare module '@theme/Navbar/Search' {

export interface Props {
readonly children: ReactNode;
readonly className?: string;
}

export default function NavbarSearch(props: Props): JSX.Element;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export default function NavbarContent(): JSX.Element {
const items = useNavbarItems();
const [leftItems, rightItems] = splitNavbarItems(items);

const autoAddSearchBar = !items.some((item) => item.type === 'search');
const searchBarItem = items.find((item) => item.type === 'search');
const autoAddSearchBar = !!searchBarItem;

return (
<NavbarContentLayout
Expand All @@ -75,7 +76,7 @@ export default function NavbarContent(): JSX.Element {
<NavbarItems items={rightItems} />
<NavbarColorModeToggle className={styles.colorModeToggle} />
{autoAddSearchBar && (
<NavbarSearch>
<NavbarSearch className={searchBarItem.className}>
<SearchBar />
</NavbarSearch>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
*/

import React from 'react';
import clsx from 'clsx';
import type {Props} from '@theme/Navbar/Search';

import styles from './styles.module.css';

export default function NavbarSearch({children}: Props): JSX.Element {
return <div className={styles.searchBox}>{children}</div>;
export default function NavbarSearch({
children,
className,
}: Props): JSX.Element {
return <div className={clsx(className, styles.searchBox)}>{children}</div>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ const LocaleDropdownNavbarItemSchema = NavbarItemBaseSchema.append({

const SearchItemSchema = Joi.object({
type: Joi.string().equal('search').required(),
className: Joi.string().default(''),
});

const NavbarItemSchema = Joi.object({
Expand Down
1 change: 1 addition & 0 deletions website/docs/api/themes/theme-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,7 @@ However, with this special navbar item type, you can change the default location
| --- | --- | --- | --- |
| `type` | `'search'` | **Required** | Sets the type of this item to a search bar. |
| `position` | <code>'left' \| 'right'</code> | `'left'` | The side of the navbar this item should appear on. |
| `className` | `string` | `''` | Custom CSS class for this navbar item. |

</APITable>

Expand Down

0 comments on commit 54e97d6

Please sign in to comment.