@@ -15,30 +15,48 @@ const propTypes = {
1515 tag : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . string ] ) ,
1616 className : PropTypes . string ,
1717 cssModule : PropTypes . object ,
18- toggleable : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . string ] ) ,
19- expandable : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . string ] ) ,
18+ toggleable : deprecated ( PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . string ] ) , 'Please use the prop "expand"' ) ,
19+ expand : PropTypes . oneOfType ( [ PropTypes . bool , PropTypes . string ] ) ,
2020} ;
2121
2222const defaultProps = {
2323 tag : 'nav' ,
24- toggleable : false ,
25- expandable : false ,
24+ expand : false ,
25+ } ;
26+
27+ const getExpandClass = ( expand ) => {
28+ if ( expand === false ) {
29+ return false ;
30+ } else if ( expand === true || expand === 'xs' ) {
31+ return 'navbar-expand' ;
32+ }
33+
34+ return `navbar-expand-${ expand } ` ;
35+ } ;
36+
37+ // To better maintain backwards compatibility while toggleable is deprecated.
38+ // We must map breakpoints to the next breakpoint so that toggleable and expand do the same things at the same breakpoint.
39+ const toggleableToExpand = {
40+ xs : 'sm' ,
41+ sm : 'md' ,
42+ md : 'lg' ,
43+ lg : 'xl' ,
2644} ;
2745
2846const getToggleableClass = ( toggleable ) => {
29- if ( toggleable === false ) {
47+ if ( toggleable === undefined || toggleable === 'xl' ) {
3048 return false ;
31- } else if ( toggleable === true || toggleable === 'xs' ) {
49+ } else if ( toggleable === false ) {
3250 return 'navbar-expand' ;
3351 }
3452
35- return `navbar-expand-${ toggleable } ` ;
53+ return `navbar-expand-${ toggleable === true ? 'sm' : ( toggleableToExpand [ toggleable ] || toggleable ) } ` ;
3654} ;
3755
3856const Navbar = ( props ) => {
3957 const {
4058 toggleable,
41- expandable ,
59+ expand ,
4260 className,
4361 cssModule,
4462 light,
@@ -54,7 +72,7 @@ const Navbar = (props) => {
5472 const classes = mapToCssModules ( classNames (
5573 className ,
5674 'navbar' ,
57- getToggleableClass ( toggleable || expandable ) ,
75+ getExpandClass ( expand ) || getToggleableClass ( toggleable ) ,
5876 {
5977 'navbar-light' : light ,
6078 'navbar-dark' : inverse || dark ,
0 commit comments