Skip to content

Commit b84b7bd

Browse files
ldirerparmentelat
authored andcommitted
add fullscreen button to hide side navigation elements and widen content
1 parent c71e28b commit b84b7bd

File tree

5 files changed

+57
-0
lines changed

5 files changed

+57
-0
lines changed

packages/site/src/components/Navigation/Navigation.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export const ConfigurablePrimaryNavigation = ({
9191
return (
9292
<>
9393
{open && !mobileOnly && headings && (
94+
// overlay to dim content when hamburger menu is open on mobile
9495
<div
9596
className="fixed inset-0 z-30 bg-black opacity-50"
9697
style={{ marginTop: top }}

packages/site/src/components/Navigation/TopNav.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { LoadingBar } from './Loading.js';
1616
import { HomeLink } from './HomeLink.js';
1717
import { ActionMenu } from './ActionMenu.js';
1818
import { ExternalOrInternalLink } from './Link.js';
19+
import { FullScreenButton } from '@myst-theme/book/app/routes/fullScreenButton.js';
1920

2021
export const DEFAULT_NAV_HEIGHT = 60;
2122

@@ -149,6 +150,7 @@ export function TopNav({ hideToc, hideSearch }: { hideToc?: boolean; hideSearch?
149150
<NavItems nav={nav} />
150151
<div className="flex-grow block"></div>
151152
{!hideSearch && <Search />}
153+
<FullScreenButton />
152154
<ThemeButton />
153155
<div className="block sm:hidden">
154156
<ActionMenu actions={actions} />

themes/book/app/root.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { LinksFunction, V2_MetaFunction, LoaderFunction } from '@remix-run/node';
22
import tailwind from '~/styles/app.css';
3+
import fullscreenCss from '~/styles/fullscreen.css';
34
import thebeCoreCss from 'thebe-core/dist/lib/thebe-core.css';
45
import { getConfig } from '~/utils/loaders.server';
56
import type { SiteLoader } from '@myst-theme/common';
@@ -41,6 +42,7 @@ export const meta: V2_MetaFunction<typeof loader> = ({ data }) => {
4142
export const links: LinksFunction = () => {
4243
return [
4344
{ rel: 'stylesheet', href: tailwind },
45+
{ rel: 'stylesheet', href: fullscreenCss },
4446
{ rel: 'stylesheet', href: thebeCoreCss },
4547
{
4648
rel: 'stylesheet',
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React, { useCallback, useEffect, useState } from 'react';
2+
3+
import { ArrowsPointingOutIcon } from '@heroicons/react/24/solid';
4+
import { ArrowsPointingInIcon } from '@heroicons/react/24/solid';
5+
export function FullScreenButton() {
6+
const [isFullscreen, setIsFullscreen] = useState(false);
7+
const toggle = useCallback(() => {
8+
setIsFullscreen((prev) => !prev);
9+
}, []);
10+
11+
useEffect(() => {
12+
if (isFullscreen) {
13+
document.body.classList.add('fullscreen');
14+
} else {
15+
document.body.classList.remove('fullscreen');
16+
}
17+
18+
// Cleanup function to remove the class when component unmounts
19+
return () => {
20+
document.body.classList.remove('fullscreen');
21+
};
22+
}, [isFullscreen]);
23+
24+
const ToggledIcon = isFullscreen ? ArrowsPointingInIcon : ArrowsPointingOutIcon;
25+
26+
return (
27+
<button
28+
onClick={toggle}
29+
className="h-8 w-8 ml-3 rounded-full aspect-square border border-stone-700 dark:border-white hover:bg-neutral-100 border-solid overflow-hidden text-stone-700 dark:text-white hover:text-stone-500 dark:hover:text-neutral-800"
30+
title="Toggle fullscreen"
31+
aria-label="Toggle fullscreen"
32+
aria-pressed={isFullscreen}
33+
>
34+
<ToggledIcon className="h-full w-full p-0.5 text-text-slate-700 dark:text-slate-10" />
35+
</button>
36+
);
37+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
3+
.fullscreen nav[aria-label="Table of Contents"] {
4+
display: none;
5+
}
6+
.fullscreen nav[aria-label="Document Outline"] {
7+
display: none;
8+
}
9+
10+
11+
12+
body.fullscreen .article-grid > *, .article-left-grid > *, .article-center-grid > * {
13+
/* make elements take more space in the parent grid. Overrides an existing rule in the app CSS. */
14+
grid-column: page;
15+
}

0 commit comments

Comments
 (0)