Skip to content

Commit 91ad2b4

Browse files
committed
feat(Navbar): add Navbar components
1 parent 95b2a38 commit 91ad2b4

7 files changed

Lines changed: 229 additions & 0 deletions

File tree

lib/Navbar.jsx

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import React, { PropTypes } from 'react';
2+
import classNames from 'classnames';
3+
4+
const propTypes = {
5+
light: PropTypes.bool,
6+
dark: PropTypes.bool,
7+
full: PropTypes.bool,
8+
fixed: PropTypes.string,
9+
color: PropTypes.string,
10+
role: PropTypes.string,
11+
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
12+
};
13+
14+
const defaultProps = {
15+
tag: 'nav',
16+
role: 'navigation'
17+
};
18+
19+
class Navbar extends React.Component {
20+
constructor(props) {
21+
super(props);
22+
}
23+
24+
render() {
25+
const {
26+
className,
27+
light,
28+
dark,
29+
full,
30+
fixed,
31+
color,
32+
tag: Tag,
33+
...attributes
34+
} = this.props;
35+
36+
const classes = classNames(
37+
className,
38+
'navbar',
39+
{
40+
'navbar-light': light,
41+
'navbar-dark': dark,
42+
[`bg-${color}`]: color,
43+
'navbar-full': full,
44+
[`navbar-fixed-${fixed}`]: fixed
45+
}
46+
);
47+
48+
return (
49+
<Tag {...attributes} className={classes}/>
50+
);
51+
}
52+
}
53+
54+
Navbar.propTypes = propTypes;
55+
Navbar.defaultProps = defaultProps;
56+
57+
export default Navbar;

lib/NavbarBrand.jsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React, { PropTypes } from 'react';
2+
import classNames from 'classnames';
3+
4+
const propTypes = {
5+
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
6+
};
7+
8+
const defaultProps = {
9+
tag: 'a'
10+
};
11+
12+
class NavbarBrand extends React.Component {
13+
render() {
14+
const {
15+
className,
16+
tag: Tag,
17+
...attributes
18+
} = this.props;
19+
20+
const classes = classNames(
21+
className,
22+
'navbar-brand'
23+
);
24+
25+
return (
26+
<Tag {...attributes} className={classes}/>
27+
);
28+
}
29+
}
30+
31+
NavbarBrand.propTypes = propTypes;
32+
NavbarBrand.defaultProps = defaultProps;
33+
34+
export default NavbarBrand;

lib/NavbarToggler.jsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React, { PropTypes } from 'react';
2+
import classNames from 'classnames';
3+
4+
const propTypes = {
5+
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
6+
type: PropTypes.string
7+
};
8+
9+
const defaultProps = {
10+
tag: 'button',
11+
type: 'button'
12+
};
13+
14+
class NavbarToggler extends React.Component {
15+
render() {
16+
const {
17+
className,
18+
children,
19+
tag: Tag,
20+
...attributes
21+
} = this.props;
22+
23+
const classes = classNames(
24+
className,
25+
'navbar-toggler'
26+
);
27+
28+
return (
29+
<Tag {...attributes} className={classes}>
30+
{children || String.fromCharCode(9776)}
31+
</Tag>
32+
);
33+
}
34+
}
35+
36+
NavbarToggler.propTypes = propTypes;
37+
NavbarToggler.defaultProps = defaultProps;
38+
39+
export default NavbarToggler;

lib/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import Container from './Container';
22
import Row from './Row';
33
import Col from './Col';
4+
import Navbar from './Navbar';
5+
import NavbarBrand from './NavbarBrand';
6+
import NavbarToggler from './NavbarToggler';
47
import Nav from './Nav';
58
import NavItem from './NavItem';
69
import NavDropdown from './NavDropdown';
@@ -29,6 +32,9 @@ export {
2932
Container,
3033
Row,
3134
Col,
35+
Navbar,
36+
NavbarBrand,
37+
NavbarToggler,
3238
Nav,
3339
NavItem,
3440
NavDropdown,

test/NavBrand.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* eslint react/no-multi-comp: 0, react/prop-types: 0 */
2+
import React from 'react';
3+
import { shallow } from 'enzyme';
4+
import { NavbarBrand } from 'reactstrap';;
5+
6+
describe('NavbarBrand', () => {
7+
it('should render .navbar-brand markup', () => {
8+
const wrapper = shallow(<NavbarBrand/>);
9+
10+
expect(wrapper.html()).toBe('<a class="navbar-brand"></a>');
11+
});
12+
13+
it('should render custom tag', () => {
14+
const wrapper = shallow(<NavbarBrand tag="div"/>);
15+
16+
expect(wrapper.html()).toBe('<div class="navbar-brand"></div>');
17+
});
18+
19+
it('sholid render children', () => {
20+
const wrapper = shallow(<NavbarBrand>Children</NavbarBrand>);
21+
22+
expect(wrapper.html()).toBe('<a class="navbar-brand">Children</a>');
23+
});
24+
25+
it('should pass additional classNames', () => {
26+
const wrapper = shallow(<NavbarBrand className="extra"/>);
27+
28+
expect(wrapper.hasClass('extra')).toBe(true);
29+
expect(wrapper.hasClass('navbar-brand')).toBe(true);
30+
});
31+
});

test/NavToggler.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* eslint react/no-multi-comp: 0, react/prop-types: 0 */
2+
import React from 'react';
3+
import { shallow } from 'enzyme';
4+
import { NavbarToggler } from 'reactstrap';;
5+
6+
describe('NavbarToggler', () => {
7+
it('should render .navbar-toggler markup', () => {
8+
const wrapper = shallow(<NavbarToggler/>);
9+
10+
expect(wrapper.html()).toBe('<button type="button" class="navbar-toggler">☰</button>');
11+
});
12+
13+
it('should render custom tag', () => {
14+
const wrapper = shallow(<NavbarToggler tag="div"/>);
15+
16+
expect(wrapper.html()).toBe('<div type="button" class="navbar-toggler">☰</div>');
17+
});
18+
19+
it('sholid render children', () => {
20+
const wrapper = shallow(<NavbarToggler>Children</NavbarToggler>);
21+
22+
expect(wrapper.html()).toBe('<button type="button" class="navbar-toggler">Children</button>');
23+
});
24+
25+
it('should pass additional classNames', () => {
26+
const wrapper = shallow(<NavbarToggler className="extra"/>);
27+
28+
expect(wrapper.hasClass('extra')).toBe(true);
29+
expect(wrapper.hasClass('navbar-toggler')).toBe(true);
30+
});
31+
});

test/Navbar.spec.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* eslint react/no-multi-comp: 0, react/prop-types: 0 */
2+
import React from 'react';
3+
import { shallow } from 'enzyme';
4+
import { Navbar } from 'reactstrap';;
5+
6+
describe('Navbar', () => {
7+
it('should render .navbar markup', () => {
8+
const wrapper = shallow(<Navbar/>);
9+
10+
expect(wrapper.html()).toBe('<nav role="navigation" class="navbar"></nav>');
11+
});
12+
13+
it('should render custom tag', () => {
14+
const wrapper = shallow(<Navbar tag="div"/>);
15+
16+
expect(wrapper.html()).toBe('<div role="navigation" class="navbar"></div>');
17+
});
18+
19+
it('sholid render children', () => {
20+
const wrapper = shallow(<Navbar>Children</Navbar>);
21+
22+
expect(wrapper.html()).toBe('<nav role="navigation" class="navbar">Children</nav>');
23+
});
24+
25+
it('should pass additional classNames', () => {
26+
const wrapper = shallow(<Navbar className="extra"/>);
27+
28+
expect(wrapper.hasClass('extra')).toBe(true);
29+
expect(wrapper.hasClass('navbar')).toBe(true);
30+
});
31+
});

0 commit comments

Comments
 (0)