Skip to content

Commit c6fbff2

Browse files
committed
fix: CNavbar: change sticky prop to bool, small fixes, clean code
1 parent c7f6eba commit c6fbff2

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

src/CNavbar.js

+15-26
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
import React from 'react';
2-
import PropTypes from 'prop-types';
3-
import classNames from 'classnames';
4-
import {mapToCssModules, tagPropType} from './Shared/helper.js';
5-
6-
const getExpandClass = expand=>{
7-
if (expand === false) {
8-
return false;
9-
} else if (expand === true || expand === 'xs') {
10-
return 'navbar-expand';
11-
}
12-
return `navbar-expand-${expand}`;
13-
};
1+
import React from 'react'
2+
import PropTypes from 'prop-types'
3+
import classNames from 'classnames'
4+
import { mapToCssModules, tagPropType } from './Shared/helper.js'
145

156
//component - CoreUI / CNavbar
167

17-
const CNavbar = props=>{
8+
const CNavbar = props => {
189

1910
const {
2011
tag: Tag,
@@ -28,25 +19,24 @@ const CNavbar = props=>{
2819
sticky,
2920
color,
3021
...attributes
31-
} = props;
22+
} = props
3223

3324
//render
3425

3526
const classes = mapToCssModules(classNames(
36-
className,
37-
'navbar',
38-
getExpandClass(expandable),
27+
'navbar', className,
3928
light ? 'navbar-light' : 'navbar-dark',
4029
{
30+
[`navbar-expand${expandable===true ? '': `-${expandable}`}`]: expandable,
4131
[`bg-${color}`]: color,
4232
[`fixed-${fixed}`]: fixed,
43-
[`sticky-${sticky}`]: sticky,
33+
'sticky-top': sticky
4434
}
45-
), cssModule);
35+
), cssModule)
4636

4737
return (
48-
<Tag {...attributes} className={classes} ref={innerRef} />
49-
);
38+
<Tag className={classes} {...attributes} ref={innerRef}/>
39+
)
5040

5141
}
5242

@@ -58,14 +48,13 @@ CNavbar.propTypes = {
5848
innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func, PropTypes.string]),
5949
light: PropTypes.bool,
6050
color: PropTypes.string,
61-
fixed: PropTypes.string,
62-
sticky: PropTypes.string,
51+
fixed: PropTypes.oneOf(['', 'top', 'bottom']),
52+
sticky: PropTypes.bool,
6353
expandable: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
6454
};
6555

6656
CNavbar.defaultProps = {
67-
tag: 'nav',
68-
expandable: false,
57+
tag: 'nav'
6958
};
7059

7160
export default CNavbar;

0 commit comments

Comments
 (0)