Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#1 implement header #6

Merged
merged 3 commits into from
Jan 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"semi": "off",
"object-curly-newline": ["error", { "multiline": true }],
"jsx-a11y/anchor-is-valid": "off",
"no-use-before-define": "off",
"react/react-in-jsx-scope": "off",
"react/jsx-filename-extension": [
"warn",
Expand Down
31 changes: 26 additions & 5 deletions components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import Link from 'next/link';
import { useRouter } from 'next/router';

type HeaderProps = {
siteName: string
}

export default function Header({ siteName }: HeaderProps) {
export default function Header({ siteName, menus }: HeaderProps) {
return (
<header className="header">
<h1 className="logo">
Expand All @@ -14,6 +11,30 @@ export default function Header({ siteName }: HeaderProps) {
{/* eslint-disable-next-line jsx-a11y/anchor-has-content */}
<a className="btn-dark" />
</h1>
<MenuNav menus={menus} />
</header>
)
}

type HeaderProps = {
siteName: string,
menus: Menu[]
}

type Menu = {
name: string,
href: string
}

function MenuNav({ menus }: {menus: Menu[]}) {
const router = useRouter()
return (
<nav className="menu">
{menus.map((menu) => (
<Link href={menu.href}>
<a className={router.pathname === menu.href ? 'active' : ''}>{menu.name}</a>
</Link>
))}
</nav>
)
}
15 changes: 15 additions & 0 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Document, { Head, Html, Main, NextScript } from 'next/document'

export default class MyDocument extends Document {
render() {
return (
<Html>
<Head />
<body className="not-ready" data-menu="true">
<Main />
<NextScript />
</body>
</Html>
)
}
}
21 changes: 18 additions & 3 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
import Header from '../components/Header';

export default function Index({ siteName }: {siteName: string}) {
export default function Index({ siteName, menus }: IndexProps) {
return (
<Header siteName={siteName} />
<Header siteName={siteName} menus={menus} />
)
}

type IndexProps = {
siteName: string,
menus: MenuProps[]
}

type MenuProps = {
name: string
href: string
}

export async function getStaticProps() {
return { props: { siteName: process.env.SITE_NAME } }
return {
props: {
siteName: process.env.SITE_NAME,
menus: [{ name: 'About', href: '/about' }],
},
}
}
2 changes: 1 addition & 1 deletion public/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ body {
transition: background 0.4s ease-out;
}

body > * {
body > div > * {
raeperd marked this conversation as resolved.
Show resolved Hide resolved
flex-shrink: 0;
width: 100%;
margin-inline: auto;
Expand Down