Skip to content

Commit 72902bc

Browse files
committed
Refine website desktop navbar layout
1 parent dbc855e commit 72902bc

3 files changed

Lines changed: 131 additions & 2 deletions

File tree

website/docusaurus.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,16 @@ const config: Config = {
116116
label: 'Documentation',
117117
position: 'left',
118118
},
119+
{type: 'search', position: 'right'},
119120
...(showVersionDropdown
120121
? [
121122
{
122123
type: 'docsVersionDropdown' as const,
123-
position: 'left' as const,
124+
position: 'right' as const,
124125
dropdownActiveClassDisabled: true,
125126
},
126127
]
127128
: []),
128-
{type: 'search', position: 'right'},
129129
{
130130
href: 'https://github.com/MagnusOpera/Terrabuild',
131131
label: 'GitHub',
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import React, {type ReactNode} from 'react';
2+
import clsx from 'clsx';
3+
import {
4+
useThemeConfig,
5+
ErrorCauseBoundary,
6+
ThemeClassNames,
7+
} from '@docusaurus/theme-common';
8+
import {
9+
splitNavbarItems,
10+
useNavbarMobileSidebar,
11+
} from '@docusaurus/theme-common/internal';
12+
import NavbarItem, {type Props as NavbarItemConfig} from '@theme/NavbarItem';
13+
import NavbarColorModeToggle from '@theme/Navbar/ColorModeToggle';
14+
import SearchBar from '@theme/SearchBar';
15+
import NavbarMobileSidebarToggle from '@theme/Navbar/MobileSidebar/Toggle';
16+
import NavbarLogo from '@theme/Navbar/Logo';
17+
import NavbarSearch from '@theme/Navbar/Search';
18+
19+
function useNavbarItems() {
20+
return useThemeConfig().navbar.items as NavbarItemConfig[];
21+
}
22+
23+
function NavbarItems({items}: {items: NavbarItemConfig[]}): ReactNode {
24+
return (
25+
<>
26+
{items.map((item, i) => (
27+
<ErrorCauseBoundary
28+
key={i}
29+
onError={(error) =>
30+
new Error(
31+
`A theme navbar item failed to render.
32+
Please double-check the following navbar item (themeConfig.navbar.items) of your Docusaurus config:
33+
${JSON.stringify(item, null, 2)}`,
34+
{cause: error},
35+
)
36+
}>
37+
<NavbarItem {...item} />
38+
</ErrorCauseBoundary>
39+
))}
40+
</>
41+
);
42+
}
43+
44+
export default function NavbarContent(): ReactNode {
45+
const mobileSidebar = useNavbarMobileSidebar();
46+
const items = useNavbarItems();
47+
const [leftItems, rightItems] = splitNavbarItems(items);
48+
const hasSearchItem = items.some((item) => item.type === 'search');
49+
const rightItemsWithoutSearch = rightItems.filter((item) => item.type !== 'search');
50+
51+
return (
52+
<div className="navbar__inner tb-navbar-inner">
53+
<div
54+
className={clsx(
55+
ThemeClassNames.layout.navbar.containerLeft,
56+
'navbar__items tb-navbar-left',
57+
)}>
58+
{!mobileSidebar.disabled && <NavbarMobileSidebarToggle />}
59+
<NavbarLogo />
60+
<NavbarItems items={leftItems} />
61+
</div>
62+
63+
{hasSearchItem && (
64+
<div className="tb-navbar-center">
65+
<NavbarSearch className="tb-navbar-search">
66+
<SearchBar />
67+
</NavbarSearch>
68+
</div>
69+
)}
70+
71+
<div
72+
className={clsx(
73+
ThemeClassNames.layout.navbar.containerRight,
74+
'navbar__items navbar__items--right tb-navbar-right',
75+
)}>
76+
<NavbarItems items={rightItemsWithoutSearch} />
77+
<NavbarColorModeToggle />
78+
</div>
79+
</div>
80+
);
81+
}

website/theme/custom.css

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,4 +275,52 @@
275275
backdrop-filter: blur(14px);
276276
-webkit-backdrop-filter: blur(14px);
277277
}
278+
279+
.tb-navbar-inner {
280+
position: relative;
281+
display: flex;
282+
align-items: center;
283+
width: 100%;
284+
}
285+
286+
.tb-navbar-left,
287+
.tb-navbar-right {
288+
flex: 1 1 0;
289+
min-width: 0;
290+
}
291+
292+
.tb-navbar-right {
293+
justify-content: flex-end;
294+
gap: 0.35rem;
295+
}
296+
297+
.tb-navbar-center {
298+
position: absolute;
299+
left: 50%;
300+
transform: translateX(-50%);
301+
width: min(38rem, calc(100vw - 34rem));
302+
z-index: 1;
303+
}
304+
305+
.tb-navbar-search,
306+
.tb-navbar-search .navbar__search,
307+
.tb-navbar-search .searchBarContainer_V7YW,
308+
.tb-navbar-search .navbar__search-input,
309+
.tb-navbar-search .DocSearch-Button {
310+
width: 100%;
311+
}
312+
313+
.tb-navbar-search {
314+
padding: 0;
315+
}
316+
317+
.tb-navbar-search .navbar__search,
318+
.tb-navbar-search .searchBarContainer_V7YW {
319+
max-width: none;
320+
padding: 0;
321+
}
322+
323+
.tb-navbar-search .DocSearch-Button {
324+
min-width: 30rem;
325+
}
278326
}

0 commit comments

Comments
 (0)