-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
418 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import {useColorMode, useThemeConfig} from '@docusaurus/theme-common'; | ||
import ColorModeToggle from '@theme/ColorModeToggle'; | ||
import type {Props} from '@theme/Navbar/ColorModeToggle'; | ||
import styles from './styles.module.css'; | ||
|
||
export default function NavbarColorModeToggle({ | ||
className, | ||
}: Props): JSX.Element | null { | ||
const navbarStyle = useThemeConfig().navbar.style; | ||
const disabled = useThemeConfig().colorMode.disableSwitch; | ||
const {colorMode, setColorMode} = useColorMode(); | ||
|
||
if (disabled) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<ColorModeToggle | ||
className={className} | ||
buttonClassName={ | ||
navbarStyle === 'dark' ? styles.darkNavbarColorModeToggle : undefined | ||
} | ||
value={colorMode} | ||
onChange={setColorMode} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.darkNavbarColorModeToggle:hover { | ||
background: var(--ifm-color-gray-800); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import React, {type ReactNode} from 'react'; | ||
import {useThemeConfig, ErrorCauseBoundary} from '@docusaurus/theme-common'; | ||
import { | ||
splitNavbarItems, | ||
useNavbarMobileSidebar, | ||
} from '@docusaurus/theme-common/internal'; | ||
import NavbarItem, {type Props as NavbarItemConfig} from '@theme/NavbarItem'; | ||
import NavbarColorModeToggle from '@theme/Navbar/ColorModeToggle'; | ||
import SearchBar from '@theme/SearchBar'; | ||
import NavbarMobileSidebarToggle from '@theme/Navbar/MobileSidebar/Toggle'; | ||
import NavbarLogo from '@theme/Navbar/Logo'; | ||
import NavbarSearch from '@theme/Navbar/Search'; | ||
|
||
import styles from './styles.module.css'; | ||
|
||
function useNavbarItems() { | ||
// TODO temporary casting until ThemeConfig type is improved | ||
return useThemeConfig().navbar.items as NavbarItemConfig[]; | ||
} | ||
|
||
function NavbarItems({items}: {items: NavbarItemConfig[]}): JSX.Element { | ||
return ( | ||
<> | ||
{items.map((item, i) => ( | ||
<ErrorCauseBoundary | ||
key={i} | ||
onError={(error) => | ||
new Error( | ||
`A theme navbar item failed to render. | ||
Please double-check the following navbar item (themeConfig.navbar.items) of your Docusaurus config: | ||
${JSON.stringify(item, null, 2)}`, | ||
{cause: error}, | ||
) | ||
}> | ||
<NavbarItem {...item} /> | ||
</ErrorCauseBoundary> | ||
))} | ||
</> | ||
); | ||
} | ||
|
||
function NavbarContentLayout({ | ||
left, | ||
right, | ||
}: { | ||
left: ReactNode; | ||
right: ReactNode; | ||
}) { | ||
return ( | ||
<div className="navbar__inner"> | ||
<div className="navbar__items">{left}</div> | ||
<div className="navbar__items navbar__items--right">{right}</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default function NavbarContent(): JSX.Element { | ||
const mobileSidebar = useNavbarMobileSidebar(); | ||
|
||
const items = useNavbarItems(); | ||
const [leftItems, rightItems] = splitNavbarItems(items); | ||
|
||
const searchBarItem = items.find((item) => item.type === 'search'); | ||
|
||
return ( | ||
<NavbarContentLayout | ||
left={ | ||
// TODO stop hardcoding items? | ||
<> | ||
{!mobileSidebar.disabled && <NavbarMobileSidebarToggle />} | ||
<NavbarLogo /> | ||
<NavbarItems items={leftItems} /> | ||
</> | ||
} | ||
right={ | ||
// TODO stop hardcoding items? | ||
// Ask the user to add the respective navbar items => more flexible | ||
<> | ||
<NavbarItems items={rightItems} /> | ||
<NavbarColorModeToggle className={styles.colorModeToggle} /> | ||
{!searchBarItem && ( | ||
<NavbarSearch> | ||
<SearchBar /> | ||
</NavbarSearch> | ||
)} | ||
</> | ||
} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
Hide color mode toggle in small viewports | ||
*/ | ||
@media (max-width: 996px) { | ||
.colorModeToggle { | ||
display: none; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { translate } from '@docusaurus/Translate' | ||
import { useThemeConfig } from '@docusaurus/theme-common' | ||
import { useHideableNavbar, useNavbarMobileSidebar } from '@docusaurus/theme-common/internal' | ||
import type { Props } from '@theme/Navbar/Layout' | ||
import NavbarMobileSidebar from '@theme/Navbar/MobileSidebar' | ||
import clsx from 'clsx' | ||
import { type ComponentProps } from 'react' | ||
import { useLocation } from 'react-router-dom' | ||
|
||
import styles from './styles.module.css' | ||
|
||
function NavbarBackdrop(props: ComponentProps<'div'>) { | ||
return <div role="presentation" {...props} className={clsx('navbar-sidebar__backdrop', props.className)} /> | ||
} | ||
|
||
export default function NavbarLayout({ children }: Props): JSX.Element { | ||
const { | ||
navbar: { hideOnScroll, style }, | ||
} = useThemeConfig() | ||
const mobileSidebar = useNavbarMobileSidebar() | ||
const { navbarRef, isNavbarVisible } = useHideableNavbar(hideOnScroll) | ||
|
||
const location = useLocation() | ||
const isHomePage = location.pathname === '/' | ||
|
||
return ( | ||
<nav | ||
ref={navbarRef} | ||
aria-label={translate({ | ||
id: 'theme.NavBar.navAriaLabel', | ||
message: 'Main', | ||
description: 'The ARIA label for the main navigation', | ||
})} | ||
className={clsx( | ||
'navbar', | ||
'navbar--fixed-top', | ||
isHomePage && 'bg-transparent', | ||
hideOnScroll && [styles.navbarHideable, !isNavbarVisible && styles.navbarHidden], | ||
{ | ||
'navbar--dark': style === 'dark', | ||
'navbar--primary': style === 'primary', | ||
'navbar-sidebar--show': mobileSidebar.shown, | ||
}, | ||
)} | ||
> | ||
{children} | ||
<NavbarBackdrop onClick={mobileSidebar.toggle} /> | ||
<NavbarMobileSidebar /> | ||
</nav> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.navbarHideable { | ||
transition: transform var(--ifm-transition-fast) ease; | ||
} | ||
|
||
.navbarHidden { | ||
transform: translate3d(0, calc(-100% - 2px), 0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
import Logo from '@theme/Logo'; | ||
|
||
export default function NavbarLogo(): JSX.Element { | ||
return ( | ||
<Logo | ||
className="navbar__brand" | ||
imageClassName="navbar__logo" | ||
titleClassName="navbar__title text--truncate" | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from 'react'; | ||
import {useNavbarMobileSidebar} from '@docusaurus/theme-common/internal'; | ||
import {translate} from '@docusaurus/Translate'; | ||
import NavbarColorModeToggle from '@theme/Navbar/ColorModeToggle'; | ||
import IconClose from '@theme/Icon/Close'; | ||
import NavbarLogo from '@theme/Navbar/Logo'; | ||
|
||
function CloseButton() { | ||
const mobileSidebar = useNavbarMobileSidebar(); | ||
return ( | ||
<button | ||
type="button" | ||
aria-label={translate({ | ||
id: 'theme.docs.sidebar.closeSidebarButtonAriaLabel', | ||
message: 'Close navigation bar', | ||
description: 'The ARIA label for close button of mobile sidebar', | ||
})} | ||
className="clean-btn navbar-sidebar__close" | ||
onClick={() => mobileSidebar.toggle()}> | ||
<IconClose color="var(--ifm-color-emphasis-600)" /> | ||
</button> | ||
); | ||
} | ||
|
||
export default function NavbarMobileSidebarHeader(): JSX.Element { | ||
return ( | ||
<div className="navbar-sidebar__brand"> | ||
<NavbarLogo /> | ||
<NavbarColorModeToggle className="margin-right--md" /> | ||
<CloseButton /> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.