forked from xyflow/xyflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
90 lines (80 loc) · 2.1 KB
/
index.js
File metadata and controls
90 lines (80 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import React, { useState } from 'react';
import ReactDOM from 'react-dom';
import { BrowserRouter as Router, Route, Switch, NavLink, withRouter } from 'react-router-dom';
import Overview from './Overview';
import Basic from './Basic';
import CustomNode from './CustomNode';
import Stress from './Stress';
import Inactive from './Inactive';
import Empty from './Empty';
import Edges from './Edges';
import Horizontal from './Horizontal';
import './index.css';
const routes = [{
path: '/',
component: Overview,
label: 'Overview'
}, {
path: '/basic',
component: Basic,
label: 'Basic'
}, {
path: '/edges',
component: Edges,
label: 'Edges'
}, {
path: '/custom-node',
component: CustomNode,
label: 'CustomNode'
}, {
path: '/horizontal',
component: Horizontal,
label: 'Horizontal'
}, {
path: '/stress',
component: Stress,
label: 'Stress'
}, {
path: '/empty',
component: Empty
}, {
path: '/inactive',
component: Inactive
}];
const navLinks = routes.filter(route => route.label);
const SourceDisplay = withRouter(({ location }) => {
const route = routes.find(route => route.path === location.pathname);
const sourceLink = `https://github.com/wbkd/react-flow/tree/master/example/src/${route.label}/index.js`;
return (
<a className="sourcedisplay" href={sourceLink}>
{'<Source />'}
</a>
);
});
const Header = () => {
const [menuOpen, setMenuOpen] = useState();
return (
<header>
<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 => (
<Route exact path={route.path} render={() => <route.component />} key={route.path} />
))}
</Switch>
</Router>
), document.getElementById('root'));