Skip to content

Commit adca9c6

Browse files
authored
Feat: Update Table of Contents styles (#239)
* feat: update ToC styles, add h3 headers to ToC * feat: increase ToC left margin, temporarily hide h3 from ToC
1 parent b4b45ce commit adca9c6

File tree

9 files changed

+54
-23
lines changed

9 files changed

+54
-23
lines changed

src/components/pages/doc-page/table-of-contents/table-of-contents.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import styles from './table-of-contents.module.scss';
77

88
const components = {
99
h2: HeadingLandmark('h2'),
10+
// uncomment the next line to add h3 to ToC
11+
// h3: HeadingLandmark('h3'),
1012
};
1113

1214
const TableOfContents = forwardRef(
@@ -22,7 +24,7 @@ const TableOfContents = forwardRef(
2224
const links = useLandmark(
2325
{
2426
containerRef: contentContainerRef,
25-
markSelector: 'h2',
27+
markSelector: 'h2', // replace to 'h2, h3' to include h3 in ToC
2628
},
2729
[],
2830
);
@@ -53,10 +55,14 @@ const TableOfContents = forwardRef(
5355
>
5456
<nav className={`${styles.anchorBar} ${label ?? ''}`}>
5557
<ul className={styles.anchorWrapper}>
56-
{links.map(({ title, anchor }, i) => (
58+
{links.map(({ title, anchor, tagName }, i) => (
5759
<li className={styles.anchorBox} key={`al-${i}`}>
5860
<a
59-
className={classNames(styles.anchor)}
61+
className={
62+
tagName === 'H2'
63+
? classNames(styles.h2)
64+
: classNames(styles.h3)
65+
}
6066
href={`${anchor}`}
6167
onClick={(e) => handleAnchorClick(e, anchor)}
6268
>

src/components/pages/doc-page/table-of-contents/table-of-contents.module.scss

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
display: flex;
66
justify-content: flex-end;
77
padding-top: 15px;
8+
9+
margin-right: -30px;
10+
811
@include lg-down {
912
display: none;
1013
}
@@ -20,34 +23,55 @@
2023
.anchor-wrapper {
2124
padding: 0;
2225
margin: 0;
23-
box-shadow: $light-block-shadow;
26+
//box-shadow: $light-block-shadow;
2427
display: flex;
2528
flex-flow: column;
26-
border: 1px solid $color-additional-2;
29+
//border: 1px solid $color-additional-2;
2730
list-style: none;
2831
}
2932

3033
.anchor-box {
3134
&:not(:last-child) {
32-
border-bottom: 1px solid $color-additional-2;
35+
//border-bottom: 1px solid $color-additional-2;
3336
}
3437
display: flex;
3538
align-items: center;
36-
min-height: 50px;
39+
// min-height: 50px;
40+
41+
& > * {
42+
width: 100%;
43+
margin-bottom: 10px;
44+
}
3745
}
3846

39-
.anchor {
47+
.h2 {
48+
text-decoration: none;
49+
box-sizing: border-box;
50+
display: block;
4051
text-decoration: none;
41-
font-size: $font-size-base;
42-
line-height: 20px;
43-
color: $color-secondary;
44-
transition: all 0.3s ease;
45-
display: inline-block;
46-
width: 100%;
47-
padding: 15px 20px;
48-
&_active {
52+
font-family: $font-family-primary;
53+
font-size: $font-size-sm;
54+
line-height: $line-height-sm;
55+
color: $color-primary;
56+
font-weight: 500;
57+
transition: color 0.3s;
58+
59+
&:hover {
4960
color: $color-accent-primary;
5061
}
62+
}
63+
64+
.h3 {
65+
box-sizing: border-box;
66+
padding-left: 15px;
67+
display: block;
68+
text-decoration: none;
69+
font-family: $font-family-primary;
70+
font-size: $font-size-sm;
71+
line-height: $line-height-sm;
72+
color: $color-primary;
73+
transition: color 0.3s;
74+
5175
&:hover {
5276
color: $color-accent-primary;
5377
}

src/components/templates/doc-page/doc-page-content/doc-page-content.view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const DocPageContent = ({ label, content, mod }) => {
5555
<Sticky topOffset={-15} bottomOffset={0} disableCompensation>
5656
{({ style }) => (
5757
<TableOfContents
58-
style={style}
58+
style={{ ...style, left: 350 }}
5959
contentContainerRef={contentContainerRef}
6060
/>
6161
)}

src/hooks/use-landmark.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const useLandmark = ({ containerRef, markSelector }, deps = []) => {
88
// get all marks of a parent
99
const allMarks = containerRef.current.querySelectorAll(markSelector);
1010
setLinks(
11-
Array.from(allMarks).map(({ id, innerText }) => ({
11+
Array.from(allMarks).map(({ id, innerText, tagName }) => ({
1212
title: innerText,
1313
anchor: `#${
1414
id ||
@@ -18,6 +18,7 @@ const useLandmark = ({ containerRef, markSelector }, deps = []) => {
1818
.replace(/^-*/g, '')
1919
.replace(/-*$/g, '')
2020
}`,
21+
tagName,
2122
})),
2223
);
2324
}

src/templates/docs/cloud.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ export default function ({ pageContext: { sidebarTree, navLinks } }) {
215215
<Sticky topOffset={-15} bottomOffset={0} disableCompensation>
216216
{({ style }) => (
217217
<TableOfContents
218-
style={style}
218+
style={{ ...style, left: 350 }}
219219
contentContainerRef={contentContainerRef}
220220
shouldMakeReplacement
221221
/>

src/templates/docs/examples.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default function ({ pageContext: { sidebarTree, navLinks } }) {
6464
<Sticky topOffset={-15} bottomOffset={0} disableCompensation>
6565
{({ style }) => (
6666
<TableOfContents
67-
style={style}
67+
style={{ ...style, left: 350 }}
6868
contentContainerRef={contentContainerRef}
6969
shouldMakeReplacement
7070
/>

src/templates/docs/guides.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default function ({ pageContext: { sidebarTree, navLinks } }) {
6565
<Sticky topOffset={-15} bottomOffset={10} disableCompensation>
6666
{({ style }) => (
6767
<TableOfContents
68-
style={style}
68+
style={{ ...style, left: 350 }}
6969
contentContainerRef={contentContainerRef}
7070
shouldMakeReplacement
7171
/>

src/templates/docs/integrations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ export default function ({ pageContext: { sidebarTree, navLinks } }) {
422422
<Sticky topOffset={-15} bottomOffset={0} disableCompensation>
423423
{({ style }) => (
424424
<TableOfContents
425-
style={style}
425+
style={{ ...style, left: 350 }}
426426
contentContainerRef={contentContainerRef}
427427
shouldMakeReplacement
428428
/>

src/templates/docs/javascript-api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export default function ({ data, pageContext: { sidebarTree, navLinks } }) {
7979
<Sticky topOffset={-15} bottomOffset={10} disableCompensation>
8080
{({ style }) => (
8181
<TableOfContents
82-
style={style}
82+
style={{ ...style, left: 350 }}
8383
contentContainerRef={contentContainerRef}
8484
shouldMakeReplacement
8585
/>

0 commit comments

Comments
 (0)