Skip to content

Commit

Permalink
add page switch on click
Browse files Browse the repository at this point in the history
  • Loading branch information
sehnryr committed Oct 20, 2024
1 parent 1f34b9e commit e6ae7aa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src-www/App.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import { useState } from "react";

import NavBar from "./components/NavBar.tsx";
import NavItem from "./components/NavItem.tsx";
import Extension from "./pages/Extensions.tsx";
import More from "./pages/More.tsx";

export default function App() {
const [page, setPage] = useState("extension");

const pages: { [key: string]: React.ReactNode } = {
extension: <Extension />,
more: <More />,
};

return (
<div
style={{
Expand All @@ -13,13 +23,13 @@ export default function App() {
}}
>
<main style={{ flex: 1 }}>
<Extension />
{pages[page]}
</main>
<NavBar>
<NavItem>
<NavItem onClick={() => setPage("extension")}>
<span>Extensions</span>
</NavItem>
<NavItem>
<NavItem onClick={() => setPage("more")}>
<span>More</span>
</NavItem>
</NavBar>
Expand Down
6 changes: 5 additions & 1 deletion src-www/components/NavItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
export default function NavItem({ children }: { children: React.ReactNode }) {
export default function NavItem(
{ onClick, children }: { onClick: () => void; children: React.ReactNode },
) {
return (
<a
onClick={onClick}
style={{
cursor: "pointer",
display: "flex",
flexDirection: "column",
alignItems: "center",
Expand Down
7 changes: 7 additions & 0 deletions src-www/pages/More.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function More() {
return (
<div>
<h1>More</h1>
</div>
);
}

0 comments on commit e6ae7aa

Please sign in to comment.