UNPKG

4.49 kBJavaScriptView Raw
1"use strict";
2"use client";
3
4var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5exports.__esModule = true;
6exports.default = void 0;
7var _classnames = _interopRequireDefault(require("classnames"));
8var React = _interopRequireWildcard(require("react"));
9var _SelectableContext = _interopRequireDefault(require("@restart/ui/SelectableContext"));
10var _uncontrollable = require("uncontrollable");
11var _NavbarBrand = _interopRequireDefault(require("./NavbarBrand"));
12var _NavbarCollapse = _interopRequireDefault(require("./NavbarCollapse"));
13var _NavbarToggle = _interopRequireDefault(require("./NavbarToggle"));
14var _NavbarOffcanvas = _interopRequireDefault(require("./NavbarOffcanvas"));
15var _ThemeProvider = require("./ThemeProvider");
16var _NavbarContext = _interopRequireDefault(require("./NavbarContext"));
17var _NavbarText = _interopRequireDefault(require("./NavbarText"));
18var _jsxRuntime = require("react/jsx-runtime");
19function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
20function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21const Navbar = /*#__PURE__*/React.forwardRef((props, ref) => {
22 const {
23 bsPrefix: initialBsPrefix,
24 expand = true,
25 variant = 'light',
26 bg,
27 fixed,
28 sticky,
29 className,
30 // Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
31 as: Component = 'nav',
32 expanded,
33 onToggle,
34 onSelect,
35 collapseOnSelect = false,
36 ...controlledProps
37 } = (0, _uncontrollable.useUncontrolled)(props, {
38 expanded: 'onToggle'
39 });
40 const bsPrefix = (0, _ThemeProvider.useBootstrapPrefix)(initialBsPrefix, 'navbar');
41 const handleCollapse = (0, React.useCallback)((...args) => {
42 onSelect == null ? void 0 : onSelect(...args);
43 if (collapseOnSelect && expanded) {
44 onToggle == null ? void 0 : onToggle(false);
45 }
46 }, [onSelect, collapseOnSelect, expanded, onToggle]);
47
48 // will result in some false positives but that seems better
49 // than false negatives. strict `undefined` check allows explicit
50 // "nulling" of the role if the user really doesn't want one
51 if (controlledProps.role === undefined && Component !== 'nav') {
52 controlledProps.role = 'navigation';
53 }
54 let expandClass = `${bsPrefix}-expand`;
55 if (typeof expand === 'string') expandClass = `${expandClass}-${expand}`;
56 const navbarContext = (0, React.useMemo)(() => ({
57 onToggle: () => onToggle == null ? void 0 : onToggle(!expanded),
58 bsPrefix,
59 expanded: !!expanded,
60 expand
61 }), [bsPrefix, expanded, expand, onToggle]);
62 return /*#__PURE__*/(0, _jsxRuntime.jsx)(_NavbarContext.default.Provider, {
63 value: navbarContext,
64 children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_SelectableContext.default.Provider, {
65 value: handleCollapse,
66 children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Component, {
67 ref: ref,
68 ...controlledProps,
69 className: (0, _classnames.default)(className, bsPrefix, expand && expandClass, variant && `${bsPrefix}-${variant}`, bg && `bg-${bg}`, sticky && `sticky-${sticky}`, fixed && `fixed-${fixed}`)
70 })
71 })
72 });
73});
74Navbar.displayName = 'Navbar';
75var _default = Object.assign(Navbar, {
76 Brand: _NavbarBrand.default,
77 Collapse: _NavbarCollapse.default,
78 Offcanvas: _NavbarOffcanvas.default,
79 Text: _NavbarText.default,
80 Toggle: _NavbarToggle.default
81});
82exports.default = _default;
83module.exports = exports.default;
\No newline at end of file