Skip to content

Commit 6487e5c

Browse files
author
katiegoines
committed
add mobile toc menu
1 parent 11577aa commit 6487e5c

File tree

3 files changed

+67
-44
lines changed

3 files changed

+67
-44
lines changed

src/components/Layout/Layout.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import {
2424
import { SpaceShip } from '@/components/SpaceShip';
2525
import { LEFT_NAV_LINKS, RIGHT_NAV_LINKS } from '@/utils/globalnav';
2626
import { LayoutProvider, LayoutHeader } from '@/components/Layout';
27-
import { TableOfContents } from '@/components/TableOfContents';
2827
import type { HeadingInterface } from '@/components/TableOfContents/TableOfContents';
2928
import { Breadcrumbs } from '@/components/Breadcrumbs';
3029
import { debounce } from '@/utils/debounce';
@@ -272,7 +271,6 @@ export const Layout = ({
272271
{children}
273272
{showNextPrev && <NextPrevious />}
274273
</Flex>
275-
{showTOC ? <TableOfContents headers={tocHeadings} /> : null}
276274
</View>
277275
<Footer hasTOC={showTOC} />
278276
</View>

src/components/Layout/LayoutHeader.tsx

Lines changed: 49 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,17 @@ export const LayoutHeader = ({
9595
<IconMenu aria-hidden="true" />
9696
Menu
9797
</Button>
98-
99-
<Button
100-
onClick={() => handleTocToggle()}
101-
size="small"
102-
ref={tocButtonRef}
103-
className="search-menu-toggle mobile-toggle"
104-
>
105-
<IconMenu aria-hidden="true" />
106-
On this page
107-
</Button>
98+
{showTOC ? (
99+
<Button
100+
onClick={() => handleTocToggle()}
101+
size="small"
102+
ref={tocButtonRef}
103+
className="search-menu-toggle mobile-toggle"
104+
>
105+
<IconMenu aria-hidden="true" />
106+
On this page
107+
</Button>
108+
) : null}
108109

109110
<View
110111
className={classNames(
@@ -176,42 +177,50 @@ export const LayoutHeader = ({
176177
)}
177178
</div>
178179
</View>
180+
<div className="">
181+
{showTOC ? <TableOfContents headers={tocHeadings} /> : null}
182+
</div>
179183
</View>
180184

181-
{/* toc */}
182-
<View
183-
className={classNames('layout-sidebar', {
184-
'layout-sidebar--expanded': tocOpen
185-
})}
186-
>
187-
<Button
188-
size="small"
189-
colorTheme="overlay"
190-
className={classNames('layout-sidebar__mobile-toggle', 'right-menu', {
191-
'layout-sidebar__mobile-toggle--open': tocOpen
192-
})}
193-
ref={sidebarTocButtonRef}
194-
onClick={() => handleTocToggle()}
195-
>
196-
<IconDoubleChevron />
197-
<VisuallyHidden>Close table of contents</VisuallyHidden>
198-
</Button>
199-
<View
200-
className={classNames('layout-sidebar__backdrop', {
201-
'layout-sidebar__backdrop--expanded': tocOpen
202-
})}
203-
onClick={() => toggleTocOpen(false)}
204-
></View>
185+
{showTOC ? (
205186
<View
206-
className={classNames('layout-sidebar__inner', 'right-menu', {
207-
'layout-sidebar__inner--expanded': tocOpen
187+
className={classNames('layout-sidebar', 'right-menu', {
188+
'layout-sidebar--expanded': tocOpen
208189
})}
209190
>
210-
<div className="layout-sidebar-menu">
211-
<TableOfContents headers={tocHeadings} />
212-
</div>
191+
<View
192+
className={classNames('layout-sidebar__backdrop', {
193+
'layout-sidebar__backdrop--expanded': tocOpen
194+
})}
195+
onClick={() => toggleTocOpen(false)}
196+
></View>
197+
<View
198+
className={classNames('layout-sidebar__inner', 'right-menu', {
199+
'layout-sidebar__inner--expanded-right': tocOpen
200+
})}
201+
>
202+
<Button
203+
size="small"
204+
colorTheme="overlay"
205+
className={classNames(
206+
'layout-sidebar__mobile-toggle',
207+
'right-menu',
208+
{
209+
'layout-sidebar__mobile-toggle--open': tocOpen
210+
}
211+
)}
212+
ref={sidebarTocButtonRef}
213+
onClick={() => handleTocToggle()}
214+
>
215+
<IconDoubleChevron />
216+
<VisuallyHidden>Close table of contents</VisuallyHidden>
217+
</Button>
218+
<div className="layout-sidebar-menu">
219+
<TableOfContents headers={tocHeadings} />
220+
</div>
221+
</View>
213222
</View>
214-
</View>
223+
) : null}
215224
</View>
216225
);
217226
};

src/styles/layout.scss

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@
6666
opacity: 0;
6767
&.right-menu {
6868
transform: rotate(180deg);
69+
inset-inline-start: unset;
70+
inset-inline-end: var(--layout-sidebar-width);
6971
}
7072
&:focus {
7173
box-shadow: none;
@@ -99,7 +101,12 @@
99101
}
100102

101103
&--expanded {
102-
animation: menu 0.2s ease-out forwards;
104+
animation: menuLeft 0.2s ease-out forwards;
105+
animation-delay: 0.1s;
106+
}
107+
108+
&--expanded-right {
109+
animation: menuRight 0.2s ease-out forwards;
103110
animation-delay: 0.1s;
104111
}
105112
}
@@ -151,7 +158,7 @@
151158
z-index: 1;
152159
}
153160

154-
@keyframes menu {
161+
@keyframes menuLeft {
155162
0% {
156163
transform: translate(-100%, 0);
157164
}
@@ -169,6 +176,15 @@
169176
}
170177
}
171178

179+
@keyframes menuRight {
180+
0% {
181+
transform: translate(100%, 0);
182+
}
183+
100% {
184+
transform: translate(0, 0);
185+
}
186+
}
187+
172188
@media (min-width: $mq-mobile) {
173189
.search-menu-toggle {
174190
display: none;

0 commit comments

Comments
 (0)