Skip to content

Commit

Permalink
feat: implement a simple layout & menu system
Browse files Browse the repository at this point in the history
  • Loading branch information
elevenpassin committed Feb 28, 2020
1 parent 23a5c68 commit 8d7daa4
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 13 deletions.
22 changes: 11 additions & 11 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from "react";
import { Helmet } from "react-helmet";
import { Link, Router } from "@reach/router";
import { Router } from "@reach/router";
import "./App.css";

import Layout from "./components/Layout";
import Home from "./pages/Home";
import Event from "./pages/Event";
import Events from "./pages/Events";
Expand All @@ -18,16 +19,15 @@ function App() {
content="An open forum for geeks to connect, discuss & learn latest ideas, technologies and trends in software development"
/>
</Helmet>
<div class="app-container">
<nav>
<Link to="/">Home</Link> | <Link to="/events">Events</Link> |{" "}
<Link to="/events/123">Event</Link>
</nav>
<Router>
<Home path="/" />
<Events path="/events" />
<Event path="/events/:eventId" />
</Router>

<div className="app-container">
<Layout>
<Router>
<Home path="/" />
<Events path="/events" />
<Event path="/events/:eventId" />
</Router>
</Layout>
</div>
</>
);
Expand Down
4 changes: 4 additions & 0 deletions src/assets/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/assets/menu.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions src/components/Layout/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React, { useState } from "react";
import { Link } from "@reach/router";

import "./layout.scss";
import logo from "../../assets/logo.svg";
import menu from "../../assets/menu.svg";

const isPartiallyActive = ({ isPartiallyCurrent }) => {
return isPartiallyCurrent ? { className: "active" } : {};
};
const isActive = ({ isCurrent }) => {
return isCurrent ? { className: "active" } : {};
};

export default ({ children }) => {
const [menuState, setMenuState] = useState(false);
const toggleMenu = () => setMenuState(!menuState);

const Menu = menuState ? (
<ul className="menu">
<Link getProps={isActive} to="/">
<li>Home</li>
</Link>
<Link getProps={isPartiallyActive} to="/events">
<li>Events</li>
</Link>
</ul>
) : null;
return (
<div className="layout">
<nav>
<div className="topbar">
<Link to="/">
<img className="logo" src={logo} alt="GeekNight Logo" />
</Link>
<div className="menu-toggle" onClick={toggleMenu}>
<span>
<b>Menu</b>
</span>
<img src={menu} alt="Menu icon" />
</div>
</div>
{Menu}
</nav>
{children}
</div>
);
};
42 changes: 42 additions & 0 deletions src/components/Layout/layout.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
body {
background: red;
}

nav {
display: flex;
flex-flow: column;
justify-content: flex-start;
min-height: 60px;
background: white;
}

.topbar {
display: flex;
flex-flow: row;
justify-content: space-between;
margin: 15px;
}

.logo {
height: 40px;
}
.menu-toggle {
margin: auto 0;
}
.menu-toggle:hover {
cursor: pointer;
}

.menu-toggle img {
margin: 0;
display: inline-block;
vertical-align: middle;
}
.menu-toggle span {
vertical-align: middle;
margin-right: 5px;
}

.active {
color: blueviolet;
}
3 changes: 1 addition & 2 deletions src/index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
@import-normalize; /* bring in normalize.css styles */
@import '~bulma/css/bulma.css'; /* import our bulma css framework */

@import "~bulma/css/bulma.css"; /* import our bulma css framework */

0 comments on commit 8d7daa4

Please sign in to comment.