Skip to content

Commit

Permalink
Feat: Update Table of Contents styles (#239)
Browse files Browse the repository at this point in the history
* feat: update ToC styles, add h3 headers to ToC

* feat: increase ToC left margin, temporarily hide h3 from ToC
  • Loading branch information
vi-nastya authored Mar 16, 2021
1 parent b4b45ce commit adca9c6
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import styles from './table-of-contents.module.scss';

const components = {
h2: HeadingLandmark('h2'),
// uncomment the next line to add h3 to ToC
// h3: HeadingLandmark('h3'),
};

const TableOfContents = forwardRef(
Expand All @@ -22,7 +24,7 @@ const TableOfContents = forwardRef(
const links = useLandmark(
{
containerRef: contentContainerRef,
markSelector: 'h2',
markSelector: 'h2', // replace to 'h2, h3' to include h3 in ToC
},
[],
);
Expand Down Expand Up @@ -53,10 +55,14 @@ const TableOfContents = forwardRef(
>
<nav className={`${styles.anchorBar} ${label ?? ''}`}>
<ul className={styles.anchorWrapper}>
{links.map(({ title, anchor }, i) => (
{links.map(({ title, anchor, tagName }, i) => (
<li className={styles.anchorBox} key={`al-${i}`}>
<a
className={classNames(styles.anchor)}
className={
tagName === 'H2'
? classNames(styles.h2)
: classNames(styles.h3)
}
href={`${anchor}`}
onClick={(e) => handleAnchorClick(e, anchor)}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
display: flex;
justify-content: flex-end;
padding-top: 15px;

margin-right: -30px;

@include lg-down {
display: none;
}
Expand All @@ -20,34 +23,55 @@
.anchor-wrapper {
padding: 0;
margin: 0;
box-shadow: $light-block-shadow;
//box-shadow: $light-block-shadow;
display: flex;
flex-flow: column;
border: 1px solid $color-additional-2;
//border: 1px solid $color-additional-2;
list-style: none;
}

.anchor-box {
&:not(:last-child) {
border-bottom: 1px solid $color-additional-2;
//border-bottom: 1px solid $color-additional-2;
}
display: flex;
align-items: center;
min-height: 50px;
// min-height: 50px;

& > * {
width: 100%;
margin-bottom: 10px;
}
}

.anchor {
.h2 {
text-decoration: none;
box-sizing: border-box;
display: block;
text-decoration: none;
font-size: $font-size-base;
line-height: 20px;
color: $color-secondary;
transition: all 0.3s ease;
display: inline-block;
width: 100%;
padding: 15px 20px;
&_active {
font-family: $font-family-primary;
font-size: $font-size-sm;
line-height: $line-height-sm;
color: $color-primary;
font-weight: 500;
transition: color 0.3s;

&:hover {
color: $color-accent-primary;
}
}

.h3 {
box-sizing: border-box;
padding-left: 15px;
display: block;
text-decoration: none;
font-family: $font-family-primary;
font-size: $font-size-sm;
line-height: $line-height-sm;
color: $color-primary;
transition: color 0.3s;

&:hover {
color: $color-accent-primary;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const DocPageContent = ({ label, content, mod }) => {
<Sticky topOffset={-15} bottomOffset={0} disableCompensation>
{({ style }) => (
<TableOfContents
style={style}
style={{ ...style, left: 350 }}
contentContainerRef={contentContainerRef}
/>
)}
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/use-landmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const useLandmark = ({ containerRef, markSelector }, deps = []) => {
// get all marks of a parent
const allMarks = containerRef.current.querySelectorAll(markSelector);
setLinks(
Array.from(allMarks).map(({ id, innerText }) => ({
Array.from(allMarks).map(({ id, innerText, tagName }) => ({
title: innerText,
anchor: `#${
id ||
Expand All @@ -18,6 +18,7 @@ const useLandmark = ({ containerRef, markSelector }, deps = []) => {
.replace(/^-*/g, '')
.replace(/-*$/g, '')
}`,
tagName,
})),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/templates/docs/cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export default function ({ pageContext: { sidebarTree, navLinks } }) {
<Sticky topOffset={-15} bottomOffset={0} disableCompensation>
{({ style }) => (
<TableOfContents
style={style}
style={{ ...style, left: 350 }}
contentContainerRef={contentContainerRef}
shouldMakeReplacement
/>
Expand Down
2 changes: 1 addition & 1 deletion src/templates/docs/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function ({ pageContext: { sidebarTree, navLinks } }) {
<Sticky topOffset={-15} bottomOffset={0} disableCompensation>
{({ style }) => (
<TableOfContents
style={style}
style={{ ...style, left: 350 }}
contentContainerRef={contentContainerRef}
shouldMakeReplacement
/>
Expand Down
2 changes: 1 addition & 1 deletion src/templates/docs/guides.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default function ({ pageContext: { sidebarTree, navLinks } }) {
<Sticky topOffset={-15} bottomOffset={10} disableCompensation>
{({ style }) => (
<TableOfContents
style={style}
style={{ ...style, left: 350 }}
contentContainerRef={contentContainerRef}
shouldMakeReplacement
/>
Expand Down
2 changes: 1 addition & 1 deletion src/templates/docs/integrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ export default function ({ pageContext: { sidebarTree, navLinks } }) {
<Sticky topOffset={-15} bottomOffset={0} disableCompensation>
{({ style }) => (
<TableOfContents
style={style}
style={{ ...style, left: 350 }}
contentContainerRef={contentContainerRef}
shouldMakeReplacement
/>
Expand Down
2 changes: 1 addition & 1 deletion src/templates/docs/javascript-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default function ({ data, pageContext: { sidebarTree, navLinks } }) {
<Sticky topOffset={-15} bottomOffset={10} disableCompensation>
{({ style }) => (
<TableOfContents
style={style}
style={{ ...style, left: 350 }}
contentContainerRef={contentContainerRef}
shouldMakeReplacement
/>
Expand Down

0 comments on commit adca9c6

Please sign in to comment.