UNPKG

2.28 kBJavaScriptView Raw
1import _extends from "@babel/runtime-corejs2/helpers/esm/extends";
2import _objectWithoutPropertiesLoose from "@babel/runtime-corejs2/helpers/esm/objectWithoutPropertiesLoose";
3import _inheritsLoose from "@babel/runtime-corejs2/helpers/esm/inheritsLoose";
4import classNames from 'classnames';
5import React from 'react';
6import PropTypes from 'prop-types';
7import { prefix } from './utils/bootstrapUtils';
8import createChainedFunction from './utils/createChainedFunction';
9var propTypes = {
10 onClick: PropTypes.func,
11
12 /**
13 * The toggle content, if left empty it will render the default toggle (seen above).
14 */
15 children: PropTypes.node
16};
17var contextTypes = {
18 $bs_navbar: PropTypes.shape({
19 bsClass: PropTypes.string,
20 expanded: PropTypes.bool,
21 onToggle: PropTypes.func.isRequired
22 })
23};
24
25var NavbarToggle =
26/*#__PURE__*/
27function (_React$Component) {
28 _inheritsLoose(NavbarToggle, _React$Component);
29
30 function NavbarToggle() {
31 return _React$Component.apply(this, arguments) || this;
32 }
33
34 var _proto = NavbarToggle.prototype;
35
36 _proto.render = function render() {
37 var _this$props = this.props,
38 onClick = _this$props.onClick,
39 className = _this$props.className,
40 children = _this$props.children,
41 props = _objectWithoutPropertiesLoose(_this$props, ["onClick", "className", "children"]);
42
43 var navbarProps = this.context.$bs_navbar || {
44 bsClass: 'navbar'
45 };
46
47 var buttonProps = _extends({
48 type: 'button'
49 }, props, {
50 onClick: createChainedFunction(onClick, navbarProps.onToggle),
51 className: classNames(className, prefix(navbarProps, 'toggle'), !navbarProps.expanded && 'collapsed')
52 });
53
54 if (children) {
55 return React.createElement("button", buttonProps, children);
56 }
57
58 return React.createElement("button", buttonProps, React.createElement("span", {
59 className: "sr-only"
60 }, "Toggle navigation"), React.createElement("span", {
61 className: "icon-bar"
62 }), React.createElement("span", {
63 className: "icon-bar"
64 }), React.createElement("span", {
65 className: "icon-bar"
66 }));
67 };
68
69 return NavbarToggle;
70}(React.Component);
71
72NavbarToggle.propTypes = propTypes;
73NavbarToggle.contextTypes = contextTypes;
74export default NavbarToggle;
\No newline at end of file