|
1 | 1 | import React from 'react'; |
2 | | -import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; |
3 | | -import useLockBodyScroll from '@theme/hooks/useLockBodyScroll'; |
4 | | -import clsx from 'clsx'; |
5 | 2 | import styles from '../../styles.module.css'; |
6 | | -import QuickSocialLinksView from '../QuickSocialLinksView'; |
7 | 3 | import NavbarItem from '@theme/NavbarItem'; |
8 | | -import { useNavbarItems } from '../../controller'; |
| 4 | +import { |
| 5 | + useColorModeToggle, |
| 6 | + useNavbarItems, |
| 7 | + useSecondaryMenu, |
| 8 | +} from '../../controller'; |
| 9 | +import useLockBodyScroll from '@theme/hooks/useLockBodyScroll'; |
| 10 | +import clsx from 'clsx'; |
| 11 | +import Translate from '@docusaurus/Translate'; |
| 12 | +import Toggle from '@theme/Toggle'; |
| 13 | +import Logo from '@theme/Logo'; |
| 14 | +import IconClose from '@theme/IconClose'; |
9 | 15 |
|
10 | | -type Props = { |
11 | | - toggleSidebar: () => void; |
| 16 | +export type NavbarMobileSidebarProps = { |
12 | 17 | sidebarShown: boolean; |
| 18 | + toggleSidebar: () => void; |
13 | 19 | }; |
14 | 20 |
|
15 | | -const NavbarMobileSidebar: React.FC<Props> = (props) => { |
| 21 | +const NavbarMobileSidebar: React.FC<NavbarMobileSidebarProps> = (props) => { |
16 | 22 | const { toggleSidebar, sidebarShown } = props; |
17 | | - const { siteConfig } = useDocusaurusContext(); |
18 | | - const items = useNavbarItems(); |
19 | 23 | useLockBodyScroll(sidebarShown); |
| 24 | + const items = useNavbarItems(); |
| 25 | + |
| 26 | + const colorModeToggle = useColorModeToggle(); |
| 27 | + |
| 28 | + const secondaryMenu = useSecondaryMenu({ |
| 29 | + sidebarShown, |
| 30 | + toggleSidebar, |
| 31 | + }); |
20 | 32 |
|
21 | 33 | return ( |
22 | 34 | <div className="navbar-sidebar"> |
23 | 35 | <div className="navbar-sidebar__brand"> |
24 | | - <a |
25 | | - className={clsx('navbar__brand', styles.BrandText)} |
| 36 | + <Logo |
| 37 | + className="navbar__brand" |
| 38 | + imageClassName="navbar__logo" |
| 39 | + titleClassName="navbar__title" |
| 40 | + /> |
| 41 | + {!colorModeToggle.disabled && ( |
| 42 | + <Toggle |
| 43 | + className={styles.navbarSidebarToggle} |
| 44 | + checked={colorModeToggle.isDarkTheme} |
| 45 | + onChange={colorModeToggle.toggle} |
| 46 | + /> |
| 47 | + )} |
| 48 | + <button |
| 49 | + type="button" |
| 50 | + className="clean-btn navbar-sidebar__close" |
26 | 51 | onClick={toggleSidebar}> |
27 | | - {siteConfig.title} |
28 | | - </a> |
29 | | - <QuickSocialLinksView /> |
| 52 | + <IconClose |
| 53 | + color="var(--ifm-color-emphasis-600)" |
| 54 | + className={styles.navbarSidebarCloseSvg} |
| 55 | + /> |
| 56 | + </button> |
30 | 57 | </div> |
31 | | - <div className="navbar-sidebar__items"> |
32 | | - <div className="menu"> |
| 58 | + |
| 59 | + <div |
| 60 | + className={clsx('navbar-sidebar__items', { |
| 61 | + 'navbar-sidebar__items--show-secondary': secondaryMenu.shown, |
| 62 | + })}> |
| 63 | + <div className="navbar-sidebar__item menu"> |
33 | 64 | <ul className="menu__list"> |
34 | 65 | {items.map((item, i) => ( |
35 | | - <NavbarItem {...item} mobile onClick={toggleSidebar} key={i} /> |
| 66 | + // @ts-ignore |
| 67 | + <NavbarItem mobile {...item} onClick={toggleSidebar} key={i} /> |
36 | 68 | ))} |
37 | 69 | </ul> |
38 | 70 | </div> |
| 71 | + |
| 72 | + <div className="navbar-sidebar__item menu"> |
| 73 | + {items.length > 0 && ( |
| 74 | + <button |
| 75 | + type="button" |
| 76 | + className="clean-btn navbar-sidebar__back" |
| 77 | + onClick={secondaryMenu.hide}> |
| 78 | + <Translate |
| 79 | + id="theme.navbar.mobileSidebarSecondaryMenu.backButtonLabel" |
| 80 | + description="The label of the back button to return to main menu, inside the mobile navbar sidebar secondary menu (notably used to display the docs sidebar)"> |
| 81 | + ← Back to main menu |
| 82 | + </Translate> |
| 83 | + </button> |
| 84 | + )} |
| 85 | + {secondaryMenu.content} |
| 86 | + </div> |
39 | 87 | </div> |
40 | 88 | </div> |
41 | 89 | ); |
|
0 commit comments