|
| 1 | +// @flow |
| 2 | +// @jsx glam |
| 3 | + |
| 4 | +import './index.css'; |
| 5 | +import glam from 'glam'; |
| 6 | +import React, { Component } from 'react'; |
| 7 | +import { BrowserRouter, Link, Route, Switch } from 'react-router-dom'; |
| 8 | + |
| 9 | +import { Home, NoMatch } from './pages'; |
| 10 | + |
| 11 | +const borderColor = 'hsl(0, 0%, 88%)'; |
| 12 | +const navWidth = 180; |
| 13 | +const appWidth = 640; |
| 14 | +const appGutter = 20; |
| 15 | +const contentGutter = 30; |
| 16 | +const pagePadding = 260; |
| 17 | +const smallDevice = '@media (max-width: 769px)'; |
| 18 | +const largeDevice = '@media (min-width: 770px)'; |
| 19 | + |
| 20 | +const AppContainer = props => ( |
| 21 | + <div |
| 22 | + css={{ |
| 23 | + boxSizing: 'border-box', |
| 24 | + marginLeft: 'auto', |
| 25 | + marginRight: 'auto', |
| 26 | + maxWidth: appWidth + navWidth / 2, |
| 27 | + minHeight: '100vh', |
| 28 | + padding: `0 ${appGutter}px ${pagePadding}px`, |
| 29 | + |
| 30 | + [smallDevice]: { |
| 31 | + maxWidth: appWidth, |
| 32 | + }, |
| 33 | + }} |
| 34 | + {...props} |
| 35 | + /> |
| 36 | +); |
| 37 | +const PageContent = props => ( |
| 38 | + <div |
| 39 | + css={{ |
| 40 | + paddingBottom: contentGutter, |
| 41 | + paddingTop: contentGutter, |
| 42 | + paddingRight: navWidth / 2, |
| 43 | + |
| 44 | + [smallDevice]: { |
| 45 | + paddingTop: contentGutter * 2, |
| 46 | + }, |
| 47 | + }} |
| 48 | + {...props} |
| 49 | + /> |
| 50 | +); |
| 51 | +const AppContent = props => ( |
| 52 | + <div |
| 53 | + css={{ |
| 54 | + flex: '1 1 auto', |
| 55 | + marginLeft: 'auto', |
| 56 | + marginRight: 'auto', |
| 57 | + |
| 58 | + [largeDevice]: { |
| 59 | + paddingLeft: navWidth + contentGutter, |
| 60 | + |
| 61 | + ':before': { |
| 62 | + borderRight: `1px solid ${borderColor}`, |
| 63 | + content: ' ', |
| 64 | + marginLeft: -(navWidth + contentGutter), |
| 65 | + height: '100%', |
| 66 | + position: 'fixed', |
| 67 | + width: navWidth, |
| 68 | + }, |
| 69 | + }, |
| 70 | + }} |
| 71 | + {...props} |
| 72 | + /> |
| 73 | +); |
| 74 | +const Nav = props => ( |
| 75 | + <div |
| 76 | + css={{ |
| 77 | + [smallDevice]: { |
| 78 | + backgroundColor: 'rgba(255, 255, 255, 0.96)', |
| 79 | + boxShadow: 'inset 0 -1px 0 rgba(0, 0, 0, 0.1)', |
| 80 | + display: 'flex ', |
| 81 | + fontSize: 13, |
| 82 | + fontWeight: 'bold', |
| 83 | + marginLeft: -appGutter, |
| 84 | + marginRight: -appGutter, |
| 85 | + overflowX: 'auto', |
| 86 | + position: 'fixed', |
| 87 | + top: 0, |
| 88 | + width: '100%', |
| 89 | + WebkitOverflowScrolling: 'touch', |
| 90 | + }, |
| 91 | + |
| 92 | + [largeDevice]: { |
| 93 | + display: 'block', |
| 94 | + float: 'left', |
| 95 | + paddingTop: contentGutter, |
| 96 | + position: 'fixed', |
| 97 | + width: navWidth, |
| 98 | + zIndex: 1, |
| 99 | + }, |
| 100 | + }} |
| 101 | + {...props} |
| 102 | + /> |
| 103 | +); |
| 104 | +const NavItem = ({ selected, ...props }) => ( |
| 105 | + <Link |
| 106 | + css={{ |
| 107 | + color: selected ? 'hsl(0, 0%, 0%)' : 'hsl(0, 0%, 40%)', |
| 108 | + display: 'inline-block', |
| 109 | + padding: `15px ${appGutter}px`, |
| 110 | + position: 'relative', |
| 111 | + textDecoration: 'none', |
| 112 | + whiteSpace: 'nowrap', |
| 113 | + |
| 114 | + ':hover, :active': { |
| 115 | + color: selected ? 'hsl(0, 0%, 10%)' : '#2684FF', |
| 116 | + }, |
| 117 | + |
| 118 | + [smallDevice]: { |
| 119 | + boxShadow: selected ? 'inset 0 -1px 0 black' : null, |
| 120 | + }, |
| 121 | + |
| 122 | + [largeDevice]: { |
| 123 | + backgroundColor: selected ? 'white' : 'transparent', |
| 124 | + borderColor: selected ? borderColor : 'transparent', |
| 125 | + borderStyle: 'solid', |
| 126 | + borderWidth: '1px 0', |
| 127 | + display: 'block', |
| 128 | + padding: '10px 20px 10px 0', |
| 129 | + right: -1, |
| 130 | + |
| 131 | + ':before': { |
| 132 | + content: ' ', |
| 133 | + // background: 'linear-gradient(90deg, fade(#e9e9e9, 0%) 94%, #e9e9e9)', |
| 134 | + }, |
| 135 | + }, |
| 136 | + }} |
| 137 | + {...props} |
| 138 | + /> |
| 139 | +); |
| 140 | +const links = [{ label: 'Home', value: '/' }]; |
| 141 | + |
| 142 | +export default class App extends Component<*> { |
| 143 | + render() { |
| 144 | + return ( |
| 145 | + <BrowserRouter> |
| 146 | + <Route> |
| 147 | + <AppContainer> |
| 148 | + <Route |
| 149 | + render={({ location }) => ( |
| 150 | + <Nav> |
| 151 | + {links.map(l => { |
| 152 | + const selected = location.pathname === l.value; |
| 153 | + return ( |
| 154 | + <NavItem key={l.value} selected={selected} to={l.value}> |
| 155 | + {l.label} |
| 156 | + </NavItem> |
| 157 | + ); |
| 158 | + })} |
| 159 | + </Nav> |
| 160 | + )} |
| 161 | + /> |
| 162 | + <AppContent> |
| 163 | + <PageContent> |
| 164 | + <Switch> |
| 165 | + <Route exact path="/" component={Home} /> |
| 166 | + <Route component={NoMatch} /> |
| 167 | + </Switch> |
| 168 | + </PageContent> |
| 169 | + </AppContent> |
| 170 | + </AppContainer> |
| 171 | + </Route> |
| 172 | + </BrowserRouter> |
| 173 | + ); |
| 174 | + } |
| 175 | +} |
0 commit comments