1 | import React from 'react';
|
2 | import PropTypes from 'prop-types';
|
3 | import classNames from 'classnames';
|
4 | import { mapToCssModules, tagPropType } from './utils';
|
5 |
|
6 | const propTypes = {
|
7 | children: PropTypes.node,
|
8 |
|
9 | className: PropTypes.string,
|
10 |
|
11 | color: PropTypes.string,
|
12 |
|
13 | container: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
14 |
|
15 | cssModule: PropTypes.object,
|
16 |
|
17 | dark: PropTypes.bool,
|
18 |
|
19 | expand: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
20 |
|
21 | fixed: PropTypes.string,
|
22 |
|
23 | light: PropTypes.bool,
|
24 | role: PropTypes.string,
|
25 |
|
26 | sticky: PropTypes.string,
|
27 |
|
28 | tag: tagPropType,
|
29 | };
|
30 |
|
31 | const getExpandClass = (expand) => {
|
32 | if (expand === false) {
|
33 | return false;
|
34 | }
|
35 | if (expand === true || expand === 'xs') {
|
36 | return 'navbar-expand';
|
37 | }
|
38 |
|
39 | return `navbar-expand-${expand}`;
|
40 | };
|
41 |
|
42 | function Navbar(props) {
|
43 | const {
|
44 | expand = false,
|
45 | className,
|
46 | cssModule,
|
47 | light,
|
48 | dark,
|
49 | fixed,
|
50 | sticky,
|
51 | color,
|
52 | container = 'fluid',
|
53 | tag: Tag = 'nav',
|
54 | children,
|
55 | ...attributes
|
56 | } = props;
|
57 |
|
58 | const classes = mapToCssModules(
|
59 | classNames(className, 'navbar', getExpandClass(expand), {
|
60 | 'navbar-light': light,
|
61 | 'navbar-dark': dark,
|
62 | [`bg-${color}`]: color,
|
63 | [`fixed-${fixed}`]: fixed,
|
64 | [`sticky-${sticky}`]: sticky,
|
65 | }),
|
66 | cssModule,
|
67 | );
|
68 |
|
69 | const containerClass =
|
70 | container && container === true ? 'container' : `container-${container}`;
|
71 |
|
72 | return (
|
73 | <Tag {...attributes} className={classes}>
|
74 | {container ? <div className={containerClass}>{children}</div> : children}
|
75 | </Tag>
|
76 | );
|
77 | }
|
78 |
|
79 | Navbar.propTypes = propTypes;
|
80 |
|
81 | export default Navbar;
|