Skip to content

Commit b248d41

Browse files
committed
FIX search position
1 parent a92ec0a commit b248d41

11 files changed

Lines changed: 312 additions & 1 deletion

File tree

docs-src/docusaurus-lunr-search-main/src/theme/SearchBar/index.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const Search = props => {
107107
'Search ⌘+K' : 'Search Ctrl+K'
108108
}
109109

110-
if(!isDocsPage){
110+
if (!isDocsPage) {
111111
return;
112112
}
113113

@@ -139,6 +139,11 @@ const Search = props => {
139139
onBlur={toggleSearchIconClick}
140140
ref={searchBarRef}
141141
disabled={!indexReady}
142+
style={{
143+
marginLeft: 'auto',
144+
marginRight: 'auto',
145+
display: 'block'
146+
}}
142147
/>
143148
<HighlightSearchResults />
144149
</div>

docs-src/src/css/custom.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pre code {
9393

9494
.navbar__search-input {
9595
font-size: var(--fontSizes-s);
96+
width: 90%;
9697
}
9798

9899
.container .col article {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import React, {type ReactNode} from 'react';
2+
import clsx from 'clsx';
3+
import {translate} from '@docusaurus/Translate';
4+
import IconArrow from '@theme/Icon/Arrow';
5+
import type {Props} from '@theme/DocSidebar/Desktop/CollapseButton';
6+
7+
import styles from './styles.module.css';
8+
9+
export default function CollapseButton({onClick}: Props): ReactNode {
10+
return (
11+
<button
12+
type="button"
13+
title={translate({
14+
id: 'theme.docs.sidebar.collapseButtonTitle',
15+
message: 'Collapse sidebar',
16+
description: 'The title attribute for collapse button of doc sidebar',
17+
})}
18+
aria-label={translate({
19+
id: 'theme.docs.sidebar.collapseButtonAriaLabel',
20+
message: 'Collapse sidebar',
21+
description: 'The title attribute for collapse button of doc sidebar',
22+
})}
23+
className={clsx(
24+
'button button--secondary button--outline',
25+
styles.collapseSidebarButton,
26+
)}
27+
onClick={onClick}>
28+
<IconArrow className={styles.collapseSidebarButtonIcon} />
29+
</button>
30+
);
31+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
:root {
2+
--docusaurus-collapse-button-bg: transparent;
3+
--docusaurus-collapse-button-bg-hover: rgb(0 0 0 / 10%);
4+
}
5+
6+
[data-theme='dark']:root {
7+
--docusaurus-collapse-button-bg: rgb(255 255 255 / 5%);
8+
--docusaurus-collapse-button-bg-hover: rgb(255 255 255 / 10%);
9+
}
10+
11+
@media (min-width: 997px) {
12+
.collapseSidebarButton {
13+
display: block !important;
14+
background-color: var(--docusaurus-collapse-button-bg);
15+
height: 40px;
16+
position: sticky;
17+
bottom: 0;
18+
border-radius: 0;
19+
border: 1px solid var(--ifm-toc-border-color);
20+
}
21+
22+
.collapseSidebarButtonIcon {
23+
transform: rotate(180deg);
24+
margin-top: 4px;
25+
}
26+
27+
[dir='rtl'] .collapseSidebarButtonIcon {
28+
transform: rotate(0);
29+
}
30+
31+
.collapseSidebarButton:hover,
32+
.collapseSidebarButton:focus {
33+
background-color: var(--docusaurus-collapse-button-bg-hover);
34+
}
35+
}
36+
37+
.collapseSidebarButton {
38+
display: none;
39+
margin: 0;
40+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import React, {type ReactNode, useState} from 'react';
2+
import clsx from 'clsx';
3+
import {ThemeClassNames} from '@docusaurus/theme-common';
4+
import {
5+
useAnnouncementBar,
6+
useScrollPosition,
7+
} from '@docusaurus/theme-common/internal';
8+
import {translate} from '@docusaurus/Translate';
9+
import DocSidebarItems from '@theme/DocSidebarItems';
10+
import type {Props} from '@theme/DocSidebar/Desktop/Content';
11+
12+
import styles from './styles.module.css';
13+
import SearchBar from '@site/docusaurus-lunr-search-main/src/theme/SearchBar';
14+
15+
function useShowAnnouncementBar() {
16+
const {isActive} = useAnnouncementBar();
17+
const [showAnnouncementBar, setShowAnnouncementBar] = useState(isActive);
18+
19+
useScrollPosition(
20+
({scrollY}) => {
21+
if (isActive) {
22+
setShowAnnouncementBar(scrollY === 0);
23+
}
24+
},
25+
[isActive],
26+
);
27+
return isActive && showAnnouncementBar;
28+
}
29+
30+
export default function DocSidebarDesktopContent({
31+
path,
32+
sidebar,
33+
className,
34+
}: Props): ReactNode {
35+
const showAnnouncementBar = useShowAnnouncementBar();
36+
37+
return (
38+
<nav
39+
aria-label={translate({
40+
id: 'theme.docs.sidebar.navAriaLabel',
41+
message: 'Docs sidebar',
42+
description: 'The ARIA label for the sidebar navigation',
43+
})}
44+
className={clsx(
45+
'menu thin-scrollbar',
46+
styles.menu,
47+
showAnnouncementBar && styles.menuWithAnnouncementBar,
48+
className,
49+
)}>
50+
<div style={{
51+
padding: 10,
52+
paddingTop: 30,
53+
marginLeft: 'auto',
54+
marginRight: 'auto'
55+
}}>
56+
<SearchBar />
57+
</div>
58+
<ul className={clsx(ThemeClassNames.docs.docSidebarMenu, 'menu__list')}>
59+
<DocSidebarItems items={sidebar} activePath={path} level={1} />
60+
</ul>
61+
</nav>
62+
);
63+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@media (min-width: 997px) {
2+
.menu {
3+
flex-grow: 1;
4+
padding: 0.5rem;
5+
}
6+
@supports (scrollbar-gutter: stable) {
7+
.menu {
8+
padding: 0.5rem 0 0.5rem 0.5rem;
9+
scrollbar-gutter: stable;
10+
}
11+
}
12+
13+
.menuWithAnnouncementBar {
14+
margin-bottom: var(--docusaurus-announcement-bar-height);
15+
}
16+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
import clsx from 'clsx';
3+
import { useThemeConfig } from '@docusaurus/theme-common';
4+
import Logo from '@theme/Logo';
5+
import CollapseButton from '@theme/DocSidebar/Desktop/CollapseButton';
6+
import Content from '@theme/DocSidebar/Desktop/Content';
7+
import type { Props } from '@theme/DocSidebar/Desktop';
8+
9+
import styles from './styles.module.css';
10+
import SearchBar from '@site/docusaurus-lunr-search-main/src/theme/SearchBar';
11+
12+
function DocSidebarDesktop({ path, sidebar, onCollapse, isHidden }: Props) {
13+
const {
14+
navbar: { hideOnScroll },
15+
docs: {
16+
sidebar: { hideable },
17+
},
18+
} = useThemeConfig();
19+
20+
return (
21+
<div
22+
className={clsx(
23+
styles.sidebar,
24+
hideOnScroll && styles.sidebarWithHideableNavbar,
25+
isHidden && styles.sidebarHidden,
26+
)}>
27+
{hideOnScroll && <Logo tabIndex={-1} className={styles.sidebarLogo} />}
28+
<Content path={path} sidebar={sidebar} />
29+
{hideable && <CollapseButton onClick={onCollapse} />}
30+
</div>
31+
);
32+
}
33+
34+
export default React.memo(DocSidebarDesktop);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
@media (min-width: 997px) {
2+
.sidebar {
3+
display: flex;
4+
flex-direction: column;
5+
height: 100%;
6+
padding-top: var(--ifm-navbar-height);
7+
width: var(--doc-sidebar-width);
8+
}
9+
10+
.sidebarWithHideableNavbar {
11+
padding-top: 0;
12+
}
13+
14+
.sidebarHidden {
15+
opacity: 0;
16+
visibility: hidden;
17+
}
18+
19+
.sidebarLogo {
20+
display: flex !important;
21+
align-items: center;
22+
margin: 0 var(--ifm-navbar-padding-horizontal);
23+
min-height: var(--ifm-navbar-height);
24+
max-height: var(--ifm-navbar-height);
25+
color: inherit !important;
26+
text-decoration: none !important;
27+
}
28+
29+
.sidebarLogo img {
30+
margin-right: 0.5rem;
31+
height: 2rem;
32+
}
33+
}
34+
35+
.sidebarLogo {
36+
display: none;
37+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React from 'react';
2+
import clsx from 'clsx';
3+
import {
4+
NavbarSecondaryMenuFiller,
5+
type NavbarSecondaryMenuComponent,
6+
ThemeClassNames,
7+
} from '@docusaurus/theme-common';
8+
import {useNavbarMobileSidebar} from '@docusaurus/theme-common/internal';
9+
import DocSidebarItems from '@theme/DocSidebarItems';
10+
import type {Props} from '@theme/DocSidebar/Mobile';
11+
import SearchBar from '@site/docusaurus-lunr-search-main/src/theme/SearchBar';
12+
13+
// eslint-disable-next-line react/function-component-definition
14+
const DocSidebarMobileSecondaryMenu: NavbarSecondaryMenuComponent<Props> = ({
15+
sidebar,
16+
path,
17+
}) => {
18+
const mobileSidebar = useNavbarMobileSidebar();
19+
return (
20+
<ul className={clsx(ThemeClassNames.docs.docSidebarMenu, 'menu__list')}>
21+
<SearchBar />
22+
<DocSidebarItems
23+
items={sidebar}
24+
activePath={path}
25+
onItemClick={(item) => {
26+
// Mobile sidebar should only be closed if the category has a link
27+
if (item.type === 'category' && item.href) {
28+
mobileSidebar.toggle();
29+
}
30+
if (item.type === 'link') {
31+
mobileSidebar.toggle();
32+
}
33+
}}
34+
level={1}
35+
/>
36+
</ul>
37+
);
38+
};
39+
40+
function DocSidebarMobile(props: Props) {
41+
return (
42+
<NavbarSecondaryMenuFiller
43+
component={DocSidebarMobileSecondaryMenu}
44+
props={props}
45+
/>
46+
);
47+
}
48+
49+
export default React.memo(DocSidebarMobile);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React, {type ReactNode} from 'react';
2+
import clsx from 'clsx';
3+
import type {Props} from '@theme/Navbar/Search';
4+
5+
import styles from './styles.module.css';
6+
7+
export default function NavbarSearch({children, className}: Props): ReactNode {
8+
return null;
9+
return (
10+
<div className={clsx(className, styles.navbarSearchContainer)}>
11+
{children}
12+
</div>
13+
);
14+
}

0 commit comments

Comments
 (0)