-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor TOC into own component
- Loading branch information
Showing
7 changed files
with
122 additions
and
75 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
10 changes: 10 additions & 0 deletions
10
packages/docusaurus-theme-classic/src/theme/BlogPostPage/styles.module.css
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,10 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
.blogContainer { | ||
max-width: inherit; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* 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 useTOCHighlight from '@theme/hooks/useTOCHighlight'; | ||
import styles from './styles.module.css'; | ||
|
||
const LINK_CLASS_NAME = 'table-of-contents__link'; | ||
const ACTIVE_LINK_CLASS_NAME = 'table-of-contents__link--active'; | ||
const TOP_OFFSET = 100; | ||
|
||
/* eslint-disable jsx-a11y/control-has-associated-label */ | ||
function Headings({headings, isChild}: {headings; isChild?: boolean}) { | ||
if (!headings.length) { | ||
return null; | ||
} | ||
return ( | ||
<ul | ||
className={ | ||
isChild ? '' : 'table-of-contents table-of-contents__left-border' | ||
}> | ||
{headings.map((heading) => ( | ||
<li key={heading.id}> | ||
<a | ||
href={`#${heading.id}`} | ||
className={LINK_CLASS_NAME} | ||
// Developer provided the HTML, so assume it's safe. | ||
// eslint-disable-next-line react/no-danger | ||
dangerouslySetInnerHTML={{__html: heading.value}} | ||
/> | ||
<Headings isChild headings={heading.children} /> | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
} | ||
|
||
function TOC({headings}) { | ||
useTOCHighlight(LINK_CLASS_NAME, ACTIVE_LINK_CLASS_NAME, TOP_OFFSET); | ||
return ( | ||
<div className="col col--3"> | ||
<div className={styles.tableOfContents}> | ||
<Headings headings={headings} /> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default TOC; |
43 changes: 43 additions & 0 deletions
43
packages/docusaurus-theme-classic/src/theme/TOC/styles.module.css
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,43 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
.tableOfContents { | ||
display: inherit; | ||
max-height: calc(100vh - (var(--ifm-navbar-height) + 2rem)); | ||
overflow-y: auto; | ||
position: sticky; | ||
top: calc(var(--ifm-navbar-height) + 2rem); | ||
} | ||
|
||
.tableOfContents::-webkit-scrollbar { | ||
width: 7px; | ||
} | ||
|
||
.tableOfContents::-webkit-scrollbar-track { | ||
background: #f1f1f1; | ||
border-radius: 10px; | ||
} | ||
|
||
.tableOfContents::-webkit-scrollbar-thumb { | ||
background: #888; | ||
border-radius: 10px; | ||
} | ||
|
||
.tableOfContents::-webkit-scrollbar-thumb:hover { | ||
background: #555; | ||
} | ||
|
||
@media only screen and (max-width: 996px) { | ||
.tableOfContents { | ||
display: none; | ||
} | ||
|
||
.docItemContainer { | ||
padding: 0 0.3rem; | ||
} | ||
} | ||
|
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