Skip to content

Commit 99699f4

Browse files
author
katiegoines
committed
changes re: heather
1 parent a4ed463 commit 99699f4

File tree

5 files changed

+45
-16
lines changed

5 files changed

+45
-16
lines changed

src/components/Layout/Layout.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ export const Layout = ({
274274
{children}
275275
{showNextPrev && <NextPrevious />}
276276
</Flex>
277-
{showTOC ? <TableOfContents headers={tocHeadings} /> : null}
277+
{showTOC ? (
278+
<TableOfContents headers={tocHeadings} forDesktop />
279+
) : null}
278280
</View>
279281
<Footer hasTOC={showTOC} />
280282
</View>

src/components/Layout/LayoutHeader.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
ALGOLIA_INDEX_NAME,
99
ALGOLIA_APP_ID
1010
} from '../../constants/algolia';
11-
import { IconMenu, IconDoubleChevron } from '@/components/Icons';
11+
import { IconTOC, IconDoubleChevron } from '@/components/Icons';
1212
import { Menu } from '@/components/Menu';
1313
import { LayoutContext } from '@/components/Layout';
1414
import { PlatformNavigator } from '@/components/PlatformNavigator';
@@ -46,8 +46,8 @@ export const LayoutHeader = ({
4646
const router = useRouter();
4747
const asPathWithNoHash = usePathWithoutHash();
4848

49-
const handleMenuToggle = (menu) => {
50-
if (menu === 'menu' && !menuOpen) {
49+
const handleMenuToggle = () => {
50+
if (!menuOpen) {
5151
toggleMenuOpen(true);
5252
// For keyboard navigators, move focus to the close menu button in the nav
5353
setTimeout(() => sidebarMenuButtonRef?.current?.focus(), 0);
@@ -56,8 +56,10 @@ export const LayoutHeader = ({
5656
// For keyboard navigators, move focus back to menu button in header
5757
menuButtonRef?.current?.focus();
5858
}
59+
};
5960

60-
if (menu === 'toc' && !tocOpen) {
61+
const handleTocToggle = () => {
62+
if (!tocOpen) {
6163
toggleTocOpen(true);
6264
// For keyboard navigators, move focus to the close menu button in the nav
6365
setTimeout(() => sidebarTocButtonRef?.current?.focus(), 0);
@@ -86,22 +88,22 @@ export const LayoutHeader = ({
8688
<View as="header" className="layout-header">
8789
<Flex className={`layout-search layout-search--${pageType}`}>
8890
<Button
89-
onClick={() => handleMenuToggle('menu')}
91+
onClick={() => handleMenuToggle()}
9092
size="small"
9193
ref={menuButtonRef}
9294
className="search-menu-toggle mobile-toggle"
9395
>
94-
<IconMenu aria-hidden="true" />
96+
<IconTOC aria-hidden="true" />
9597
Menu
9698
</Button>
9799
{showTOC ? (
98100
<Button
99-
onClick={() => handleMenuToggle('toc')}
101+
onClick={() => handleTocToggle()}
100102
size="small"
101103
ref={tocButtonRef}
102104
className="search-menu-toggle mobile-toggle"
103105
>
104-
<IconMenu aria-hidden="true" />
106+
<IconTOC aria-hidden="true" />
105107
On this page
106108
</Button>
107109
) : null}
@@ -152,7 +154,7 @@ export const LayoutHeader = ({
152154
'layout-sidebar__mobile-toggle--open': menuOpen
153155
})}
154156
ref={sidebarMenuButtonRef}
155-
onClick={() => handleMenuToggle('menu')}
157+
onClick={() => handleMenuToggle()}
156158
>
157159
<IconDoubleChevron />
158160
<VisuallyHidden>Close menu</VisuallyHidden>
@@ -176,7 +178,6 @@ export const LayoutHeader = ({
176178
)}
177179
</div>
178180
</View>
179-
{showTOC ? <div className=""></div> : null}
180181
</View>
181182

182183
{showTOC ? (
@@ -207,13 +208,13 @@ export const LayoutHeader = ({
207208
}
208209
)}
209210
ref={sidebarTocButtonRef}
210-
onClick={() => handleMenuToggle('toc')}
211+
onClick={() => handleTocToggle()}
211212
>
212213
<IconDoubleChevron />
213214
<VisuallyHidden>Close table of contents</VisuallyHidden>
214215
</Button>
215216
<div className="layout-sidebar-menu">
216-
<TableOfContents headers={tocHeadings} />
217+
<TableOfContents headers={tocHeadings} forDesktop={false} />
217218
</div>
218219
</View>
219220
</View>

src/components/TableOfContents/TableOfContents.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ export interface HeadingInterface {
99
}
1010
interface TableOfContents {
1111
headers?: HeadingInterface[];
12+
forDesktop?: boolean;
1213
}
1314

14-
export const TableOfContents = ({ headers }) => {
15+
export const TableOfContents = ({ headers, forDesktop }) => {
1516
const { tocOpen, toggleTocOpen } = useContext(LayoutContext);
1617

1718
const onLinkClick = () => {
@@ -21,8 +22,14 @@ export const TableOfContents = ({ headers }) => {
2122
}
2223
};
2324

25+
const hideOnMobile = forDesktop ? 'desktop-toc' : '';
26+
2427
return (
25-
<Flex as="nav" className="toc" aria-labelledby="tocHeader">
28+
<Flex
29+
as="nav"
30+
className={`toc ${hideOnMobile}`}
31+
aria-labelledby="tocHeader"
32+
>
2633
{headers ? (
2734
<Heading level={2} id="tocHeader" className="toc-header">
2835
<IconTOC /> On this page

src/styles/layout.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
}
229229
}
230230

231-
@media (min-width: 1360px) {
231+
@media (min-width: $mq-mobile) {
232232
.main--toc {
233233
margin-inline-end: var(--layout-toc-width);
234234
}

src/styles/toc.scss

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
margin-top: var(--amplify-space-large);
44
padding-block: var(--amplify-space-large);
55
border-top: 1px solid var(--amplify-colors-neutral-20);
6+
7+
&.desktop-toc {
8+
@media (max-width: $mq-mobile) {
9+
display: none;
10+
}
11+
}
12+
13+
@media (min-width: $mq-mobile) {
14+
margin-top: inherit;
15+
border-top: inherit;
16+
}
617
}
718
.toc-header {
819
font-size: var(--amplify-font-sizes-medium);
@@ -12,6 +23,10 @@
1223
align-items: center;
1324
gap: var(--amplify-space-xxs);
1425
color: var(--amplify-colors-font-tertiary);
26+
27+
@media (max-width: $mq-mobile) {
28+
padding: var(--amplify-space-xs) var(--amplify-space-large);
29+
}
1530
}
1631
.toc-list {
1732
margin: 0;
@@ -27,6 +42,10 @@
2742
text-decoration: none;
2843
line-height: var(--amplify-line-heights-small);
2944
margin-block: var(--amplify-space-xs);
45+
46+
@media (max-width: $mq-mobile) {
47+
padding: var(--amplify-space-xs) var(--amplify-space-large);
48+
}
3049
&:visited {
3150
color: var(--amplify-colors-font-primary);
3251
}

0 commit comments

Comments
 (0)