Skip to content

Commit 5395e8d

Browse files
committed
feat(Nav/Navbar): update to bs v4 beta
Navbar deprecated inverse in favor of dark Narbar added expandable as alais to toggleable since class name has change Navbar changed toggler class to use expand Navbar removed full as it is no longer a thing NavbarToggler remove left and right as they are no longer a thing Nav change vertical to allow for string breakpoint (sm,md,lg,etc) .flex-{vertical}-column Nav add horizontal to trigger .justift-content-{horizontal} utility classes Nav add card prop to trigger with tabs/pills props to make .card-header-tabs and .card-header-pills respectfully Nav add fill prop to trigger nav-fill class fix some examples/docs (removing props which no longer exist) and adding new props to the lists (still needs additonal new examples) Update tests
1 parent 53687fa commit 5395e8d

9 files changed

Lines changed: 82 additions & 44 deletions

File tree

docs/lib/Components/NavbarPage.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ export default class NavsPage extends React.Component {
2828
<PrismCode className="language-jsx">
2929
{`Navbar.propTypes = {
3030
light: PropTypes.bool,
31-
inverse: PropTypes.bool,
32-
full: PropTypes.bool,
31+
dark: PropTypes.bool,
3332
fixed: PropTypes.string,
3433
color: PropTypes.string,
3534
role: PropTypes.string,
3635
toggleable: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
36+
expandable: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]), // alias for toggleable
3737
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
3838
// pass in custom element to use
3939
}`}
@@ -62,8 +62,6 @@ export default class NavsPage extends React.Component {
6262
<PrismCode className="language-jsx">
6363
{`NavbarToggler.propTypes = {
6464
type: PropTypes.string,
65-
right: PropTypes.bool,
66-
left: PropTypes.bool,
6765
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
6866
// pass in custom element to use
6967
}`}

docs/lib/Components/NavsPage.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ export default class NavssPage extends React.Component {
3131
{`Nav.propTypes = {
3232
tabs: PropTypes.bool,
3333
pills: PropTypes.bool,
34-
vertical: PropTypes.bool,
34+
card: PropTypes.bool,
35+
justified: PropTypes.bool,
36+
fill: PropTypes.bool,
37+
vertical: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
38+
horizontal: PropTypes.string,
3539
navbar: PropTypes.bool,
3640
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
3741
// pass in custom element to use

docs/lib/examples/Navbar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export default class Example extends React.Component {
1919
return (
2020
<div>
2121
<Navbar color="faded" light toggleable>
22-
<NavbarToggler right onClick={this.toggle} />
22+
<NavbarToggler onClick={this.toggle} />
2323
<NavbarBrand href="/">reactstrap</NavbarBrand>
2424
<Collapse isOpen={this.state.isOpen} navbar>
2525
<Nav className="ml-auto" navbar>

src/Nav.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,30 @@ import { mapToCssModules } from './utils';
66
const propTypes = {
77
tabs: PropTypes.bool,
88
pills: PropTypes.bool,
9-
vertical: PropTypes.bool,
9+
vertical: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
10+
horizontal: PropTypes.string,
1011
justified: PropTypes.bool,
12+
fill: PropTypes.bool,
1113
navbar: PropTypes.bool,
14+
card: PropTypes.bool,
1215
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
1316
className: PropTypes.string,
1417
cssModule: PropTypes.object,
1518
};
1619

1720
const defaultProps = {
18-
tag: 'ul'
21+
tag: 'ul',
22+
vertical: false,
23+
};
24+
25+
const getVerticalClass = (vertical) => {
26+
if (vertical === false) {
27+
return false;
28+
} else if (vertical === true || vertical === 'xs') {
29+
return 'flex-column';
30+
}
31+
32+
return `flex-${vertical}-column`;
1933
};
2034

2135
const Nav = (props) => {
@@ -25,20 +39,27 @@ const Nav = (props) => {
2539
tabs,
2640
pills,
2741
vertical,
42+
horizontal,
2843
justified,
44+
fill,
2945
navbar,
46+
card,
3047
tag: Tag,
3148
...attributes
3249
} = props;
3350

3451
const classes = mapToCssModules(classNames(
3552
className,
3653
navbar ? 'navbar-nav' : 'nav',
54+
horizontal ? `justify-content-${horizontal}` : false,
55+
getVerticalClass(vertical),
3756
{
3857
'nav-tabs': tabs,
58+
'card-header-tabs': card && tabs,
3959
'nav-pills': pills,
60+
'card-header-pills': card && pills,
4061
'nav-justified': justified,
41-
'flex-column': vertical
62+
'nav-fill': fill,
4263
}
4364
), cssModule);
4465

src/Navbar.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import classNames from 'classnames';
4-
import { mapToCssModules } from './utils';
4+
import { mapToCssModules, deprecated } from './utils';
55

66
const propTypes = {
77
light: PropTypes.bool,
8-
inverse: PropTypes.bool,
8+
dark: PropTypes.bool,
9+
inverse: deprecated(PropTypes.bool, 'Please use the prop "dark"'),
910
full: PropTypes.bool,
1011
fixed: PropTypes.string,
1112
sticky: PropTypes.string,
@@ -15,31 +16,34 @@ const propTypes = {
1516
className: PropTypes.string,
1617
cssModule: PropTypes.object,
1718
toggleable: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
19+
expandable: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
1820
};
1921

2022
const defaultProps = {
2123
tag: 'nav',
2224
toggleable: false,
25+
expandable: false,
2326
};
2427

2528
const getToggleableClass = (toggleable) => {
2629
if (toggleable === false) {
2730
return false;
2831
} else if (toggleable === true || toggleable === 'xs') {
29-
return 'navbar-toggleable';
32+
return 'navbar-expand';
3033
}
3134

32-
return `navbar-toggleable-${toggleable}`;
35+
return `navbar-expand-${toggleable}`;
3336
};
3437

3538
const Navbar = (props) => {
3639
const {
3740
toggleable,
41+
expandable,
3842
className,
3943
cssModule,
4044
light,
45+
dark,
4146
inverse,
42-
full,
4347
fixed,
4448
sticky,
4549
color,
@@ -50,12 +54,11 @@ const Navbar = (props) => {
5054
const classes = mapToCssModules(classNames(
5155
className,
5256
'navbar',
53-
getToggleableClass(toggleable),
57+
getToggleableClass(toggleable || expandable),
5458
{
5559
'navbar-light': light,
56-
'navbar-inverse': inverse,
60+
'navbar-dark': inverse || dark,
5761
[`bg-${color}`]: color,
58-
'navbar-full': full,
5962
[`fixed-${fixed}`]: fixed,
6063
[`sticky-${sticky}`]: sticky,
6164
}

src/NavbarToggler.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ const propTypes = {
99
className: PropTypes.string,
1010
cssModule: PropTypes.object,
1111
children: PropTypes.node,
12-
right: PropTypes.bool,
13-
left: PropTypes.bool,
1412
};
1513

1614
const defaultProps = {
@@ -23,17 +21,13 @@ const NavbarToggler = (props) => {
2321
className,
2422
cssModule,
2523
children,
26-
right,
27-
left,
2824
tag: Tag,
2925
...attributes
3026
} = props;
3127

3228
const classes = mapToCssModules(classNames(
3329
className,
3430
'navbar-toggler',
35-
right && 'navbar-toggler-right',
36-
left && 'navbar-toggler-left'
3731
), cssModule);
3832

3933
return (

src/__tests__/Nav.spec.js

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,60 @@ describe('Nav', () => {
2121
expect(wrapper.html()).toBe('<ul class="nav">Children</ul>');
2222
});
2323

24-
it('should handle justified attribute', () => {
24+
it('should handle justified prop', () => {
2525
const wrapper = shallow(<Nav justified />);
2626

2727
expect(wrapper.html()).toBe('<ul class="nav nav-justified"></ul>');
2828
});
2929

30-
it('should handle pills attribute', () => {
30+
it('should handle fill prop', () => {
31+
const wrapper = shallow(<Nav fill />);
32+
33+
expect(wrapper.html()).toBe('<ul class="nav nav-fill"></ul>');
34+
});
35+
36+
it('should handle pills prop', () => {
3137
const wrapper = shallow(<Nav pills />);
3238

3339
expect(wrapper.html()).toBe('<ul class="nav nav-pills"></ul>');
3440
});
3541

36-
it('should handle tabs attribute', () => {
42+
it('should handle pills prop with card prop', () => {
43+
const wrapper = shallow(<Nav pills card />);
44+
45+
expect(wrapper.html()).toBe('<ul class="nav nav-pills card-header-pills"></ul>');
46+
});
47+
48+
it('should handle tabs prop', () => {
3749
const wrapper = shallow(<Nav tabs />);
3850

3951
expect(wrapper.html()).toBe('<ul class="nav nav-tabs"></ul>');
4052
});
4153

42-
it('should handle vertical attribute', () => {
54+
it('should handle tabs prop with card prop', () => {
55+
const wrapper = shallow(<Nav tabs card />);
56+
57+
expect(wrapper.html()).toBe('<ul class="nav nav-tabs card-header-tabs"></ul>');
58+
});
59+
60+
it('should handle vertical prop', () => {
4361
const wrapper = shallow(<Nav vertical />);
4462

4563
expect(wrapper.html()).toBe('<ul class="nav flex-column"></ul>');
4664
});
4765

66+
it('should handle vertical prop with string', () => {
67+
const wrapper = shallow(<Nav vertical="sm" />);
68+
69+
expect(wrapper.html()).toBe('<ul class="nav flex-sm-column"></ul>');
70+
});
71+
72+
it('should handle horizontal prop with string', () => {
73+
const wrapper = shallow(<Nav horizontal="end" />);
74+
75+
expect(wrapper.html()).toBe('<ul class="nav justify-content-end"></ul>');
76+
});
77+
4878
it('should pass additional classNames', () => {
4979
const wrapper = shallow(<Nav className="extra" />);
5080

src/__tests__/Navbar.spec.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ describe('Navbar', () => {
1212
it('should render default .navbar-toggleable class', () => {
1313
const wrapper = shallow(<Navbar toggleable />);
1414

15-
expect(wrapper.html()).toBe('<nav class="navbar navbar-toggleable"></nav>');
15+
expect(wrapper.html()).toBe('<nav class="navbar navbar-expand"></nav>');
1616
});
1717

1818
it('should render size based .navbar-toggleable-* classes', () => {
1919
const wrapper = shallow(<Navbar toggleable="md" />);
2020

21-
expect(wrapper.html()).toBe('<nav class="navbar navbar-toggleable-md"></nav>');
21+
expect(wrapper.html()).toBe('<nav class="navbar navbar-expand-md"></nav>');
2222
});
2323

2424
it('should render custom tag', () => {
@@ -47,13 +47,13 @@ describe('Navbar', () => {
4747
});
4848

4949
it('should render prop based classes', () => {
50-
const wrapper = shallow(<Navbar light inverse toggleable="sm" color="success" full sticky="top" fixed="top" />);
50+
const wrapper = shallow(<Navbar light dark toggleable="sm" color="success" full sticky="top" fixed="top" />);
5151

5252
expect(wrapper.hasClass('bg-success')).toBe(true);
5353
expect(wrapper.hasClass('navbar')).toBe(true);
54-
expect(wrapper.hasClass('navbar-toggleable-sm')).toBe(true);
54+
expect(wrapper.hasClass('navbar-expand-sm')).toBe(true);
5555
expect(wrapper.hasClass('navbar-light')).toBe(true);
56-
expect(wrapper.hasClass('navbar-inverse')).toBe(true);
56+
expect(wrapper.hasClass('navbar-dark')).toBe(true);
5757
expect(wrapper.hasClass('fixed-top')).toBe(true);
5858
expect(wrapper.hasClass('sticky-top')).toBe(true);
5959
});

src/__tests__/NavbarToggler.spec.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,4 @@ describe('NavbarToggler', () => {
2727
expect(wrapper.hasClass('extra')).toBe(true);
2828
expect(wrapper.hasClass('navbar-toggler')).toBe(true);
2929
});
30-
31-
it('should apply .navbar-toggler-right when right prop is true', () => {
32-
const wrapper = shallow(<NavbarToggler right />);
33-
34-
expect(wrapper.hasClass('navbar-toggler-right')).toBe(true);
35-
});
36-
37-
it('should apply .navbar-toggler-left when left prop is true', () => {
38-
const wrapper = shallow(<NavbarToggler left />);
39-
40-
expect(wrapper.hasClass('navbar-toggler-left')).toBe(true);
41-
});
4230
});

0 commit comments

Comments
 (0)