Improve layout (#74)
This improves the layout of all our pages to look more like the mandala page.
Additionally, some form widgets now have better layout, and the header takes up less vertical space.
At an implementation level, the component hierarchy of pages has been inverted to make this kind of layout easier. Now fully laid-out pages are contained within `<Page>` components that are at the top of the component hierarchy, and which are defined by each specific page (mandala, creature, vocabulary, etc).
I had to do a few architectural things to avoid circular imports, though; most notably, this involved the creation of a new React context called a `PageContext`.
It uses CSS grid, which should be pretty well-supported amongst recent browsers.
2021-04-02 23:00:29 +00:00
|
|
|
import React, { useContext } from "react";
|
|
|
|
import type { PageName } from "./pages";
|
|
|
|
|
|
|
|
export type PageContext = {
|
|
|
|
currPage: PageName;
|
|
|
|
allPages: PageName[];
|
|
|
|
};
|
|
|
|
|
|
|
|
export const PageContext = React.createContext<PageContext>({
|
|
|
|
currPage: "vocabulary",
|
|
|
|
allPages: [],
|
|
|
|
});
|
|
|
|
|
|
|
|
export const PAGE_QUERY_ARG = "p";
|
|
|
|
|
|
|
|
const PageLink: React.FC<{ page: PageName }> = ({ page }) => (
|
|
|
|
<a href={`?${PAGE_QUERY_ARG}=${encodeURIComponent(page)}`}>{page}</a>
|
|
|
|
);
|
|
|
|
|
|
|
|
const Navbar: React.FC<{}> = (props) => {
|
|
|
|
const pc = useContext(PageContext);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<nav>
|
|
|
|
<ul className="navbar">
|
|
|
|
{pc.allPages.map((pageName) => (
|
|
|
|
<li key={pageName}>
|
|
|
|
{pc.currPage === pageName ? pageName : <PageLink page={pageName} />}
|
|
|
|
</li>
|
|
|
|
))}
|
|
|
|
</ul>
|
|
|
|
</nav>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export type PageProps = {
|
|
|
|
title: string;
|
|
|
|
children?: any;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const Page: React.FC<PageProps> = ({ title, children }) => {
|
|
|
|
return (
|
|
|
|
<div className="page">
|
|
|
|
<header>
|
2021-04-02 23:02:40 +00:00
|
|
|
<h1>Mystic Symbolic {title}</h1>
|
Improve layout (#74)
This improves the layout of all our pages to look more like the mandala page.
Additionally, some form widgets now have better layout, and the header takes up less vertical space.
At an implementation level, the component hierarchy of pages has been inverted to make this kind of layout easier. Now fully laid-out pages are contained within `<Page>` components that are at the top of the component hierarchy, and which are defined by each specific page (mandala, creature, vocabulary, etc).
I had to do a few architectural things to avoid circular imports, though; most notably, this involved the creation of a new React context called a `PageContext`.
It uses CSS grid, which should be pretty well-supported amongst recent browsers.
2021-04-02 23:00:29 +00:00
|
|
|
<Navbar />
|
|
|
|
</header>
|
|
|
|
{children}
|
|
|
|
<footer>
|
|
|
|
<p>
|
|
|
|
For more details about this project, see its{" "}
|
|
|
|
<a href="https://github.com/toolness/mystic-symbolic" target="_blank">
|
|
|
|
GitHub repository
|
|
|
|
</a>
|
|
|
|
.
|
|
|
|
</p>
|
|
|
|
</footer>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|