Merge pull request #216 from wbkd/develop

refactor(examples): mobile friendly
This commit is contained in:
Moritz
2020-05-12 11:14:30 +02:00
committed by GitHub
3 changed files with 77 additions and 12 deletions

View File

@@ -70,6 +70,7 @@ const RichGraph = () => {
type="button"
onClick={addRandomNode}
style={{ position: 'absolute', right: 10, top: 30, zIndex: 4 }}
className="richexample__add"
>
add node
</button>

View File

@@ -23,10 +23,13 @@ header {
border-bottom: 1px solid #eee;
display: flex;
font-weight: 700;
align-items: center;
}
header a {
.logo {
text-decoration: none;
display: block;
line-height: 1;
}
header a, header a:focus, header a:active, header a:visited {
@@ -37,20 +40,41 @@ header a:hover {
color: #333;
}
header nav {
font-weight: 400;
.menu {
margin-left: auto;
background: rgb(255, 96, 96);
color: white;
border: none;
padding: 5px 12px;
border-radius: 5px;
}
nav {
font-weight: 400;
display: none;
position: absolute;
width: 94%;
top: 46px;
z-index: 10;
left: 0;
padding: 3%;
background: rgba(255,255,255,0.9);
}
nav.is-open {
display: block;
}
nav a {
margin-left: 10px;
text-decoration: none;
font-size: 12px;
font-size: 14px;
background: rgb(255, 96, 96);
color: white;
padding: 5px 12px;
border-radius: 5px;
position: relative;
display: block;
margin-bottom: 5px;
}
nav a, nav a:focus, nav a:active, nav a:visited {
@@ -76,7 +100,7 @@ nav a.active:before {
.sourcedisplay {
position: absolute;
top: 45px;
top: 50px;
right: 15px;
z-index: 4;
text-decoration: none;
@@ -89,4 +113,35 @@ nav a.active:before {
.sourcedisplay:hover {
color: #111;
}
}
.richexample__add {
display: none;
}
@media screen and (min-width: 768px) {
nav {
position: relative;
display: block;
margin-left: auto;
width: auto;
padding: 0;
top: auto;
left: auto;
}
nav a {
margin-left: 10px;
font-size: 12px;
display: inline-block;
margin-bottom: 0;
}
.menu {
display: none;
}
.richexample__add {
display: block;
}
}

View File

@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route, Switch, NavLink, withRouter } from 'react-router-dom';
@@ -58,18 +58,27 @@ const SourceDisplay = withRouter(({ location }) => {
);
});
ReactDOM.render((
<Router forceRefresh={true}>
const Header = () => {
const [menuOpen, setMenuOpen] = useState();
return (
<header>
<a href="https://github.com/wbkd/react-flow">React Flow</a>
<nav>
<a className="logo" href="https://github.com/wbkd/react-flow">React Flow</a>
<nav className={menuOpen ? 'is-open' : ''}>
{navLinks.map(route => (
<NavLink to={route.path} key={route.label} exact>
{route.label}
</NavLink>
))}
</nav>
<button className="menu" onClick={() => setMenuOpen(!menuOpen)}>Menu</button>
</header>
);
}
ReactDOM.render((
<Router forceRefresh={true}>
<Header />
<SourceDisplay />
<Switch>
{routes.map(route => (