mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-09 22:32:53 +02:00
style(v2): basic sidebar component (#1020)
This commit is contained in:
parent
aae5c4dc85
commit
2e9656917c
7 changed files with 110 additions and 48 deletions
51
v2/lib/theme/Sidebar/index.js
Normal file
51
v2/lib/theme/Sidebar/index.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
import React from 'react';
|
||||
import {Link} from 'react-router-dom';
|
||||
|
||||
import classnames from 'classnames';
|
||||
|
||||
import styles from './styles.css';
|
||||
|
||||
function Sidebar(props) {
|
||||
const {metadata, docsSidebars, docsMetadatas} = props;
|
||||
const {sidebar, language, id: thisID} = metadata;
|
||||
if (!sidebar || !docsSidebars) {
|
||||
return null;
|
||||
}
|
||||
const thisSidebar = docsSidebars[sidebar];
|
||||
return (
|
||||
thisSidebar && (
|
||||
<div className={styles.sidebar}>
|
||||
{Object.keys(thisSidebar).map(categoryName => (
|
||||
<div className={styles.sidebarGroup} key={categoryName}>
|
||||
<h3 className={styles.sidebarGroupTitle}>{categoryName}</h3>
|
||||
<ul className={styles.sidebarList}>
|
||||
{thisSidebar[categoryName].map(rawLinkID => {
|
||||
const linkID = (language ? `${language}-` : '') + rawLinkID;
|
||||
const linkMetadata = docsMetadatas[linkID];
|
||||
if (!linkMetadata) {
|
||||
throw new Error(
|
||||
`Improper sidebars.json file, document with id '${linkID}' not found.`,
|
||||
);
|
||||
}
|
||||
const activeItem = linkID === thisID;
|
||||
return (
|
||||
<li key={linkID}>
|
||||
<Link
|
||||
className={classnames(styles.sidebarLink, {
|
||||
[styles.sidebarLinkActive]: activeItem,
|
||||
})}
|
||||
to={linkMetadata.permalink}>
|
||||
{linkMetadata.sidebar_label || linkMetadata.title}
|
||||
</Link>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export default Sidebar;
|
Loading…
Add table
Add a link
Reference in a new issue