UNPKG

4.23 kBJavaScriptView Raw
1var _excluded = ["expand", "className", "cssModule", "light", "dark", "fixed", "sticky", "color", "container", "tag", "children"];
2function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
5function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
6import React from 'react';
7import PropTypes from 'prop-types';
8import classNames from 'classnames';
9import { mapToCssModules, tagPropType } from './utils';
10var propTypes = {
11 children: PropTypes.node,
12 /** Add custom class */
13 className: PropTypes.string,
14 /** Theme the navbar by adding a background color */
15 color: PropTypes.string,
16 /** Use any of the responsive containers to change how wide the content in your navbar is presented. */
17 container: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
18 /** Change underlying component's CSS base class name */
19 cssModule: PropTypes.object,
20 /** This prop is passed if the background is dark, to make the text lighter */
21 dark: PropTypes.bool,
22 /** Determine if to show toggler button */
23 expand: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
24 /** Make the navbar fixed at the top */
25 fixed: PropTypes.string,
26 /** Add `.navbar-light` class */
27 light: PropTypes.bool,
28 role: PropTypes.string,
29 /** Use `position: sticky` which isn't fully supported in every browser */
30 sticky: PropTypes.string,
31 /** Set a custom element for this component */
32 tag: tagPropType
33};
34var getExpandClass = function getExpandClass(expand) {
35 if (expand === false) {
36 return false;
37 }
38 if (expand === true || expand === 'xs') {
39 return 'navbar-expand';
40 }
41 return "navbar-expand-".concat(expand);
42};
43function Navbar(props) {
44 var _classNames;
45 var _props$expand = props.expand,
46 expand = _props$expand === void 0 ? false : _props$expand,
47 className = props.className,
48 cssModule = props.cssModule,
49 light = props.light,
50 dark = props.dark,
51 fixed = props.fixed,
52 sticky = props.sticky,
53 color = props.color,
54 _props$container = props.container,
55 container = _props$container === void 0 ? 'fluid' : _props$container,
56 _props$tag = props.tag,
57 Tag = _props$tag === void 0 ? 'nav' : _props$tag,
58 children = props.children,
59 attributes = _objectWithoutProperties(props, _excluded);
60 var classes = mapToCssModules(classNames(className, 'navbar', getExpandClass(expand), (_classNames = {
61 'navbar-light': light,
62 'navbar-dark': dark
63 }, _defineProperty(_classNames, "bg-".concat(color), color), _defineProperty(_classNames, "fixed-".concat(fixed), fixed), _defineProperty(_classNames, "sticky-".concat(sticky), sticky), _classNames)), cssModule);
64 var containerClass = container && container === true ? 'container' : "container-".concat(container);
65 return /*#__PURE__*/React.createElement(Tag, _extends({}, attributes, {
66 className: classes
67 }), container ? /*#__PURE__*/React.createElement("div", {
68 className: containerClass
69 }, children) : children);
70}
71Navbar.propTypes = propTypes;
72export default Navbar;
\No newline at end of file