diff --git a/packages/docusaurus-theme-classic/src/theme-classic.d.ts b/packages/docusaurus-theme-classic/src/theme-classic.d.ts index 9f3c48ed3da0..2e07f3a43833 100644 --- a/packages/docusaurus-theme-classic/src/theme-classic.d.ts +++ b/packages/docusaurus-theme-classic/src/theme-classic.d.ts @@ -47,13 +47,33 @@ declare module '@theme/BlogListPaginator' { export default function BlogListPaginator(props: Props): JSX.Element; } -declare module '@theme/BlogSidebar' { +declare module '@theme/BlogSidebar/Desktop' { + import type {BlogSidebar} from '@docusaurus/plugin-content-blog'; + + export interface Props { + readonly sidebar: BlogSidebar; + } + + export default function BlogSidebarDesktop(props: Props): JSX.Element; +} + +declare module '@theme/BlogSidebar/Mobile' { import type {BlogSidebar} from '@docusaurus/plugin-content-blog'; export interface Props { readonly sidebar: BlogSidebar; } + export default function BlogSidebarMobile(props: Props): JSX.Element; +} + +declare module '@theme/BlogSidebar' { + import type {BlogSidebar} from '@docusaurus/plugin-content-blog'; + + export interface Props { + readonly sidebar?: BlogSidebar; + } + export default function BlogSidebar(props: Props): JSX.Element; } diff --git a/packages/docusaurus-theme-classic/src/theme/BlogLayout/index.tsx b/packages/docusaurus-theme-classic/src/theme/BlogLayout/index.tsx index 009eef93276d..30d68822c650 100644 --- a/packages/docusaurus-theme-classic/src/theme/BlogLayout/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/BlogLayout/index.tsx @@ -20,11 +20,7 @@ export default function BlogLayout(props: Props): JSX.Element {
- {hasSidebar && ( - - )} +
+ + + ); +} diff --git a/packages/docusaurus-theme-classic/src/theme/BlogSidebar/styles.module.css b/packages/docusaurus-theme-classic/src/theme/BlogSidebar/Desktop/styles.module.css similarity index 95% rename from packages/docusaurus-theme-classic/src/theme/BlogSidebar/styles.module.css rename to packages/docusaurus-theme-classic/src/theme/BlogSidebar/Desktop/styles.module.css index d3e7700af508..3ca0d4b8d5e7 100644 --- a/packages/docusaurus-theme-classic/src/theme/BlogSidebar/styles.module.css +++ b/packages/docusaurus-theme-classic/src/theme/BlogSidebar/Desktop/styles.module.css @@ -40,11 +40,7 @@ } @media (max-width: 996px) { - .sidebarDesktop { - display: none; - } - .sidebar { - top: 0; + display: none; } } diff --git a/packages/docusaurus-theme-classic/src/theme/BlogSidebar/Mobile/index.tsx b/packages/docusaurus-theme-classic/src/theme/BlogSidebar/Mobile/index.tsx new file mode 100644 index 000000000000..a07967840419 --- /dev/null +++ b/packages/docusaurus-theme-classic/src/theme/BlogSidebar/Mobile/index.tsx @@ -0,0 +1,38 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import React from 'react'; +import Link from '@docusaurus/Link'; +import {NavbarSecondaryMenuFiller} from '@docusaurus/theme-common'; +import type {Props} from '@theme/BlogSidebar/Mobile'; + +function BlogSidebarMobileSecondaryMenu({sidebar}: Props): JSX.Element { + return ( +
    + {sidebar.items.map((item) => ( +
  • + + {item.title} + +
  • + ))} +
+ ); +} + +export default function BlogSidebarMobile(props: Props): JSX.Element { + return ( + + ); +} diff --git a/packages/docusaurus-theme-classic/src/theme/BlogSidebar/index.tsx b/packages/docusaurus-theme-classic/src/theme/BlogSidebar/index.tsx index ad478860fe42..742f4bd42781 100644 --- a/packages/docusaurus-theme-classic/src/theme/BlogSidebar/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/BlogSidebar/index.tsx @@ -6,61 +6,19 @@ */ import React from 'react'; -import clsx from 'clsx'; -import Link from '@docusaurus/Link'; -import {translate} from '@docusaurus/Translate'; -import { - NavbarSecondaryMenuFiller, - useWindowSize, -} from '@docusaurus/theme-common'; +import BlogSidebarDesktop from '@theme/BlogSidebar/Desktop'; +import BlogSidebarMobile from '@theme/BlogSidebar/Mobile'; +import {useWindowSize} from '@docusaurus/theme-common'; import type {Props} from '@theme/BlogSidebar'; -import styles from './styles.module.css'; -function BlogSidebarContent({ - sidebar, - className, -}: Props & {className?: string}): JSX.Element { - return ( - - ); -} - -export default function BlogSidebar(props: Props): JSX.Element | null { +export default function BlogSidebar({sidebar}: Props): JSX.Element | null { const windowSize = useWindowSize(); - if (props.sidebar.items.length === 0) { + if (!sidebar?.items.length) { return null; } // Mobile sidebar doesn't need to be server-rendered if (windowSize === 'mobile') { - return ( - - ); + return ; } - return ; + return ; }