Skip to content

Commit 7b1c7b2

Browse files
committed
Add deprecation path!
good idea @taion, should help some folks upgrade.
1 parent 0be007f commit 7b1c7b2

File tree

8 files changed

+346
-22
lines changed

8 files changed

+346
-22
lines changed

docs/examples/NavbarBasic.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ const navbarInstance = (
99
<NavItem eventKey={1} href="#">Link</NavItem>
1010
<NavItem eventKey={2} href="#">Link</NavItem>
1111
<NavDropdown eventKey={3} title="Dropdown" id="basic-nav-dropdown">
12-
<MenuItem eventKey="1">Action</MenuItem>
13-
<MenuItem eventKey="2">Another action</MenuItem>
14-
<MenuItem eventKey="3">Something else here</MenuItem>
12+
<MenuItem eventKey={3.1}>Action</MenuItem>
13+
<MenuItem eventKey={3.2}>Another action</MenuItem>
14+
<MenuItem eventKey={3.3}>Something else here</MenuItem>
1515
<MenuItem divider />
16-
<MenuItem eventKey="4">Separated link</MenuItem>
16+
<MenuItem eventKey={3.3}>Separated link</MenuItem>
1717
</NavDropdown>
1818
</Nav>
1919
</Navbar>

docs/examples/NavbarCollapsible.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ const navbarInstance = (
1010
<Nav>
1111
<NavItem eventKey={1} href="#">Link</NavItem>
1212
<NavItem eventKey={2} href="#">Link</NavItem>
13-
<NavDropdown eventKey={3} title="Dropdown" id="collapsible-navbar-dropdown">
14-
<MenuItem eventKey="1">Action</MenuItem>
15-
<MenuItem eventKey="2">Another action</MenuItem>
16-
<MenuItem eventKey="3">Something else here</MenuItem>
13+
<NavDropdown eventKey={3} title="Dropdown" id="basic-nav-dropdown">
14+
<MenuItem eventKey={3.1}>Action</MenuItem>
15+
<MenuItem eventKey={3.2}>Another action</MenuItem>
16+
<MenuItem eventKey={3.3}>Something else here</MenuItem>
1717
<MenuItem divider />
18-
<MenuItem eventKey="4">Separated link</MenuItem>
18+
<MenuItem eventKey={3.3}>Separated link</MenuItem>
1919
</NavDropdown>
2020
</Nav>
21-
<Nav right>
21+
<Nav pullRight>
2222
<NavItem eventKey={1} href="#">Link Right</NavItem>
2323
<NavItem eventKey={2} href="#">Link Right</NavItem>
2424
</Nav>

src/CollapsibleNav.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React, { cloneElement } from 'react';
22
import Collapse from './Collapse';
33
import classNames from 'classnames';
4+
import deprecationWarning from './utils/deprecationWarning';
45

56
import ValidComponentChildren from './utils/ValidComponentChildren';
67
import createChainedFunction from './utils/createChainedFunction';
78

8-
const CollapsibleNav = React.createClass({
9+
let CollapsibleNav = React.createClass({
910

1011
propTypes: {
1112
onSelect: React.PropTypes.func,
@@ -95,4 +96,7 @@ const CollapsibleNav = React.createClass({
9596
}
9697
});
9798

98-
export default CollapsibleNav;
99+
export default deprecationWarning.wrapper(CollapsibleNav,
100+
'CollapsibleNav', 'Navbar.Collapse',
101+
'http://react-bootstrap.github.io/components.html#navbars'
102+
);

src/Nav.js

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import tbsUtils, { bsStyles, bsClass as _bsClass } from './utils/bootstrapUtils'
77
import ValidComponentChildren from './utils/ValidComponentChildren';
88
import createChainedFunction from './utils/createChainedFunction';
99

10+
import Collapse from './Collapse';
11+
1012
class Nav extends React.Component {
1113

1214
render() {
@@ -17,18 +19,19 @@ class Nav extends React.Component {
1719
classes[tbsUtils.prefix(this.props, 'stacked')] = this.props.stacked;
1820
classes[tbsUtils.prefix(this.props, 'justified')] = this.props.justified;
1921

20-
2122
if (isNavbar) {
2223
let bsClass = this.context.$bs_navbar_bsClass || 'navbar';
2324
const navbarRight = this.props.right != null ? this.props.right : this.props.pullRight;
2425

2526
classes[tbsUtils.prefix({ bsClass }, 'nav')] = true;
2627
classes[tbsUtils.prefix({ bsClass }, 'right')] = navbarRight;
28+
classes[tbsUtils.prefix({ bsClass }, 'left')] = this.props.pullLeft;
2729
} else {
2830
classes['pull-right'] = this.props.pullRight;
31+
classes['pull-left'] = this.props.pullLeft;
2932
}
3033

31-
return (
34+
let list = (
3235
<ul ref="ul"
3336
{...this.props}
3437
id={ulId || id}
@@ -38,6 +41,22 @@ class Nav extends React.Component {
3841
{ValidComponentChildren.map(this.props.children, this.renderNavItem, this)}
3942
</ul>
4043
);
44+
45+
// TODO remove in 0.29
46+
if (this.context.$bs_deprecated_navbar && this.props.collapsible) {
47+
list = (
48+
<Collapse
49+
in={this.props.expanded}
50+
className={isNavbar ? 'navbar-collapse' : void 0}
51+
>
52+
<div>
53+
{ list }
54+
</div>
55+
</Collapse>
56+
);
57+
}
58+
59+
return list;
4160
}
4261

4362
getChildActiveProp(child) {
@@ -115,23 +134,41 @@ Nav.propTypes = {
115134
ulId: deprecated(React.PropTypes.string,
116135
'The wrapping `<nav>` has been removed you can use `id` now'),
117136

118-
expanded: React.PropTypes.bool,
119-
137+
/**
138+
* Apply styling an alignment for use in a Navbar. This prop will be set
139+
* automatically when the Nav is used inside a Navbar.
140+
*/
120141
navbar: React.PropTypes.bool,
121142
eventKey: React.PropTypes.any,
122143
pullRight: React.PropTypes.bool,
123-
right: deprecated(React.PropTypes.bool, 'Use the `pullRight` prop instead')
144+
pullLeft: React.PropTypes.bool,
145+
146+
right: deprecated(React.PropTypes.bool,
147+
'Use the `pullRight` prop instead'),
148+
149+
/**
150+
* @private
151+
*/
152+
expanded: React.PropTypes.bool,
153+
154+
/**
155+
* @private
156+
*/
157+
collapsible: deprecated(React.PropTypes.bool,
158+
'Use `Navbar.Collapse` instead, to create collapsible Navbars'),
124159
};
125160

126161
Nav.contextTypes = {
127162
$bs_navbar: React.PropTypes.bool,
128-
$bs_navbar_bsClass: React.PropTypes.string
163+
$bs_navbar_bsClass: React.PropTypes.string,
164+
165+
$bs_deprecated_navbar: React.PropTypes.bool
129166
};
130167

131168
Nav.defaultProps = {
132169
justified: false,
133170
pullRight: false,
134-
right: false,
171+
pullLeft: false,
135172
stacked: false
136173
};
137174

src/Navbar.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import React, { PropTypes } from 'react';
22
import uncontrollable from 'uncontrollable';
33
import classNames from 'classnames';
44
import elementType from 'react-prop-types/lib/elementType';
5+
import deprecationWarning from './utils/deprecationWarning';
6+
import ValidComponentChildren from './utils/ValidComponentChildren';
57

68
import Grid from './Grid';
9+
import OldNavbar from './deprecated/Navbar';
710
import NavbarBrand from './NavbarBrand';
811
import NavbarHeader from './NavbarHeader';
912
import NavbarToggle from './NavbarToggle';
@@ -12,6 +15,21 @@ import NavbarCollapse from './NavbarCollapse';
1215
import tbsUtils, { bsClass as bsClasses, bsStyles } from './utils/bootstrapUtils';
1316
import { DEFAULT, INVERSE } from './styleMaps';
1417

18+
let has = (obj, key) => obj && {}.hasOwnProperty.call(obj, key);
19+
20+
function shouldRenderOldNavbar(component) {
21+
let props = component.props;
22+
return (
23+
has(props, 'toggleButton') ||
24+
has(props, 'toggleNavKey') ||
25+
has(props, 'brand') ||
26+
// this should be safe b/c the new version requires wrapping in a Header
27+
ValidComponentChildren.findValidComponents(
28+
props.children, child => child.props.bsRole === 'brand'
29+
).length > 0
30+
);
31+
}
32+
1533
let Navbar = React.createClass({
1634

1735
propTypes: {
@@ -106,6 +124,17 @@ let Navbar = React.createClass({
106124
...props
107125
} = this.props;
108126

127+
if (shouldRenderOldNavbar(this)) {
128+
deprecationWarning({ message:
129+
'Rendering a deprecated version of the Navbar due to the use of deprecated ' +
130+
'props. Please use the new Navbar api, and remove `toggleButton`, `toggleNavKey`, `brand` or ' +
131+
'use of the `<NavBrand>` component outside of a `<Navbar.Header>`. \n\n' +
132+
'for more details see: http://react-bootstrap.github.io/components.html#navbars'
133+
});
134+
135+
return <OldNavbar {...this.props}/>;
136+
}
137+
109138
const classes = tbsUtils.getClassSet(this.props);
110139

111140
classes[tbsUtils.prefix(this.props, 'fixed-top')] = this.props.fixedTop;

0 commit comments

Comments
 (0)