Skip to content

Commit 943f322

Browse files
committed
Merge pull request #510 from benoitvallon/responsive-navbar-react-bootstrap
Adds react-bootstrap responsive navbar
2 parents a57dd47 + d67a79c commit 943f322

File tree

3 files changed

+52
-34
lines changed

3 files changed

+52
-34
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,13 @@
9999
"pretty-error": "^1.2.0",
100100
"query-string": "^3.0.0",
101101
"react": "^0.14.2",
102+
"react-bootstrap": "^0.27.3",
102103
"react-document-meta": "^2.0.0",
103104
"react-dom": "^0.14.1",
104105
"react-inline-css": "^2.0.0",
105106
"react-redux": "^4.0.0",
106107
"react-router": "^1.0.0-rc3",
108+
"react-router-bootstrap": "^0.19.3",
107109
"redux": "^3.0.4",
108110
"redux-form": "^3.0.0",
109111
"serialize-javascript": "^1.1.2",

src/containers/App/App.js

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
import React, { Component, PropTypes } from 'react';
2-
import { IndexLink, Link } from 'react-router';
32
import { connect } from 'react-redux';
3+
import { IndexLink } from 'react-router';
4+
import { LinkContainer } from 'react-router-bootstrap';
5+
import { Navbar, NavBrand, Nav, NavItem, CollapsibleNav } from 'react-bootstrap';
46
import DocumentMeta from 'react-document-meta';
57
import { isLoaded as isInfoLoaded, load as loadInfo } from 'redux/modules/info';
68
import { isLoaded as isAuthLoaded, load as loadAuth, logout } from 'redux/modules/auth';
79
import { InfoBar } from 'components';
810
import { pushState } from 'redux-router';
911
import config from '../../config';
1012

11-
const NavbarLink = ({to, className, component, children}) => {
12-
const Comp = component || Link;
13-
14-
return (
15-
<Comp to={to} className={className} activeStyle={{
16-
color: '#33e0ff'
17-
}}>
18-
{children}
19-
</Comp>
20-
);
21-
};
22-
2313
@connect(
2414
state => ({user: state.auth.user}),
2515
{logout, pushState})
@@ -67,32 +57,51 @@ export default class App extends Component {
6757
return (
6858
<div className={styles.app}>
6959
<DocumentMeta {...config.app}/>
70-
<nav className="navbar navbar-default navbar-fixed-top">
71-
<div className="container">
72-
<NavbarLink to="/" className="navbar-brand" component={IndexLink}>
60+
<Navbar fixedTop toggleNavKey={0}>
61+
<NavBrand>
62+
<IndexLink to="/" activeStyle={{color: '#33e0ff'}}>
7363
<div className={styles.brand}/>
74-
React Redux Example
75-
</NavbarLink>
64+
<span>React Redux Example</span>
65+
</IndexLink>
66+
</NavBrand>
7667

77-
<ul className="nav navbar-nav">
78-
{user && <li><NavbarLink to="/chat">Chat</NavbarLink></li>}
68+
<CollapsibleNav eventKey={0}>
69+
<Nav navbar>
70+
{user && <LinkContainer to="/chat">
71+
<NavItem eventKey={1}>Chat</NavItem>
72+
</LinkContainer>}
7973

80-
<li><NavbarLink to="/widgets">Widgets</NavbarLink></li>
81-
<li><NavbarLink to="/survey">Survey</NavbarLink></li>
82-
<li><NavbarLink to="/about">About Us</NavbarLink></li>
83-
{!user && <li><NavbarLink to="/login">Login</NavbarLink></li>}
84-
{user && <li className="logout-link"><a href="/logout" onClick={::this.handleLogout}>Logout</a></li>}
85-
</ul>
74+
<LinkContainer to="/widgets">
75+
<NavItem eventKey={2}>Widgets</NavItem>
76+
</LinkContainer>
77+
<LinkContainer to="/survey">
78+
<NavItem eventKey={3}>Survey</NavItem>
79+
</LinkContainer>
80+
<LinkContainer to="/about">
81+
<NavItem eventKey={4}>About Us</NavItem>
82+
</LinkContainer>
83+
84+
{!user &&
85+
<LinkContainer to="/login">
86+
<NavItem eventKey={5}>Login</NavItem>
87+
</LinkContainer>}
88+
{user &&
89+
<LinkContainer to="/logout">
90+
<NavItem eventKey={6} className="logout-link" onClick={::this.handleLogout}>
91+
Logout
92+
</NavItem>
93+
</LinkContainer>}
94+
</Nav>
8695
{user &&
8796
<p className={styles.loggedInMessage + ' navbar-text'}>Logged in as <strong>{user.name}</strong>.</p>}
88-
<ul className="nav navbar-nav navbar-right">
89-
<li>
90-
<a href="https://github.com/erikras/react-redux-universal-hot-example"
91-
target="_blank" title="View on Github"><i className="fa fa-github"/></a>
92-
</li>
93-
</ul>
94-
</div>
95-
</nav>
97+
<Nav navbar right>
98+
<NavItem eventKey={1} target="_blank" title="View on Github" href="https://github.com/erikras/react-redux-universal-hot-example">
99+
<i className="fa fa-github"/>
100+
</NavItem>
101+
</Nav>
102+
</CollapsibleNav>
103+
</Navbar>
104+
96105
<div className={styles.appContent}>
97106
{this.props.children}
98107
</div>

src/theme/bootstrap.overrides.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@
77
position: relative;
88
padding-left: 50px;
99
}
10+
11+
.navbar-default .navbar-nav > .active > a,
12+
.navbar-default .navbar-nav > .active > a:hover,
13+
.navbar-default .navbar-nav > .active > a:focus {
14+
color: #33e0ff;
15+
background-color: transparent;
16+
}

0 commit comments

Comments
 (0)