diff --git a/packages/docusaurus-init/templates/bootstrap/docusaurus.config.js b/packages/docusaurus-init/templates/bootstrap/docusaurus.config.js index e10758cfee..dbf882b28b 100644 --- a/packages/docusaurus-init/templates/bootstrap/docusaurus.config.js +++ b/packages/docusaurus-init/templates/bootstrap/docusaurus.config.js @@ -14,6 +14,12 @@ module.exports = { src: 'img/logo.svg', }, links: [ + { + to: 'docs/doc1', + activeBasePath: 'docs', + label: 'Docs', + position: 'left', + }, {to: 'blog', label: 'Blog', position: 'left'}, { href: 'https://github.com/facebook/docusaurus', diff --git a/packages/docusaurus-theme-bootstrap/package.json b/packages/docusaurus-theme-bootstrap/package.json index d21c86130e..493ca995b1 100644 --- a/packages/docusaurus-theme-bootstrap/package.json +++ b/packages/docusaurus-theme-bootstrap/package.json @@ -9,6 +9,7 @@ }, "dependencies": { "bootstrap": "^4.4.1", + "classnames": "^2.2.6", "prism-react-renderer": "^1.1.0", "reactstrap": "^8.4.1", "@mdx-js/react": "^1.5.8" diff --git a/packages/docusaurus-theme-bootstrap/src/theme/DocItem/index.js b/packages/docusaurus-theme-bootstrap/src/theme/DocItem/index.js index 29a7d3f853..453096f7b5 100644 --- a/packages/docusaurus-theme-bootstrap/src/theme/DocItem/index.js +++ b/packages/docusaurus-theme-bootstrap/src/theme/DocItem/index.js @@ -46,7 +46,7 @@ function DocItem(props) { )} {permalink && } -
+
diff --git a/packages/docusaurus-theme-bootstrap/src/theme/DocPage/index.js b/packages/docusaurus-theme-bootstrap/src/theme/DocPage/index.js index 47f8be1d06..20fe578739 100644 --- a/packages/docusaurus-theme-bootstrap/src/theme/DocPage/index.js +++ b/packages/docusaurus-theme-bootstrap/src/theme/DocPage/index.js @@ -7,22 +7,34 @@ import React from 'react'; import renderRoutes from '@docusaurus/renderRoutes'; +import DocSidebar from '@theme/DocSidebar'; import MDXComponents from '@theme/MDXComponents'; import Layout from '@theme/Layout'; import {MDXProvider} from '@mdx-js/react'; +import {matchPath} from '@docusaurus/router'; function DocPage(props) { - const {route: baseRoute} = props; + const {route: baseRoute, docsMetadata, location} = props; + // case-sensitive route such as it is defined in the sidebar + const currentRoute = + baseRoute.routes.find((route) => { + return matchPath(location.pathname, route); + }) || {}; + const {permalinkToSidebar, docsSidebars} = docsMetadata; + const sidebar = permalinkToSidebar[currentRoute.path]; return ( - -
-
- - {renderRoutes(baseRoute.routes)} - -
-
+ + +
+ + {renderRoutes(baseRoute.routes)} + +
); } diff --git a/packages/docusaurus-theme-bootstrap/src/theme/DocSidebar/index.js b/packages/docusaurus-theme-bootstrap/src/theme/DocSidebar/index.js new file mode 100644 index 0000000000..19e8301e42 --- /dev/null +++ b/packages/docusaurus-theme-bootstrap/src/theme/DocSidebar/index.js @@ -0,0 +1,135 @@ +/** + * 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, {useState, useCallback} from 'react'; +import Link from '@docusaurus/Link'; +import isInternalUrl from '@docusaurus/isInternalUrl'; +import {NavItem, Nav, Button} from 'reactstrap'; +import useLockBodyScroll from '@theme/hooks/useLockBodyScroll'; +import classNames from 'classnames'; + +import styles from './styles.module.css'; + +const DocSidebarItem = ({item, onItemClick, ...props}) => { + const {items, href, label, type} = item; + + switch (type) { + case 'category': + return ( + items.length > 0 && ( +
+

{label}

+ {items.map((childItem) => ( + + ))} +
+ ) + ); + + case 'link': + default: + return ( + + + {label} + + + ); + } +}; + +const DocSidebar = (props) => { + const {docsSidebars, sidebar: currentSidebar} = props; + + const [sidebarShown, setSidebarShown] = useState(false); + const handleSidebarToggle = useCallback(() => { + setSidebarShown(!sidebarShown); + }, [sidebarShown, setSidebarShown]); + + useLockBodyScroll(sidebarShown); + + if (!currentSidebar) { + return null; + } + + const sidebarData = docsSidebars[currentSidebar]; + + if (!sidebarData) { + throw new Error( + `Cannot find the sidebar "${currentSidebar}" in the sidebar config!`, + ); + } + + return ( +
+
+
+ +
+
+ +
+
+
+ ); +}; + +export default DocSidebar; diff --git a/packages/docusaurus-theme-bootstrap/src/theme/DocSidebar/styles.module.css b/packages/docusaurus-theme-bootstrap/src/theme/DocSidebar/styles.module.css new file mode 100644 index 0000000000..3426eb7760 --- /dev/null +++ b/packages/docusaurus-theme-bootstrap/src/theme/DocSidebar/styles.module.css @@ -0,0 +1,58 @@ +@media only screen and (min-width: 997px) { + .sidebar { + min-width: 300px; + max-width: 300px; + transition: all 0.5s; + min-height: 100vh; + margin-left: 0; + font-size: 16px; + } + + .isOpen { + margin-left: 0; + transition: .5s; + } + + .sidebar ul p { + color: #fff; + padding: 10px; + } + .sidebarFAB { + display: none; + } +} + + +@media only screen and (max-width: 500px) { + .isOpen .sideMenu{ + min-width: 100%; + max-width: 100%; + width: 100%; + height: 100%; + position: absolute; + z-index: 1; + top: 0; + display: inherit; + background-color: #17a2b8; + align-items: stretch; + overflow: hidden; + transition: all 0.5s, height 0s; + } + + .sideMenu { + display: none; + } + + .sidebar { + width: 0; + } + + .sidebarFAB { + display: inline-flex; + position: fixed; + z-index: 2; + right: 1rem; + bottom: 2rem; + } + +} diff --git a/packages/docusaurus-theme-bootstrap/src/theme/Footer/index.js b/packages/docusaurus-theme-bootstrap/src/theme/Footer/index.js index 8916f3d5a3..3dc879d936 100644 --- a/packages/docusaurus-theme-bootstrap/src/theme/Footer/index.js +++ b/packages/docusaurus-theme-bootstrap/src/theme/Footer/index.js @@ -39,7 +39,7 @@ function Footer() { const {links} = footer || {}; return ( -