UNPKG

2.43 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
3import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
4import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
5import _inherits from 'babel-runtime/helpers/inherits';
6import classNames from 'classnames';
7import React from 'react';
8import PropTypes from 'prop-types';
9
10import { prefix } from './utils/bootstrapUtils';
11import createChainedFunction from './utils/createChainedFunction';
12
13var propTypes = {
14 onClick: PropTypes.func,
15 /**
16 * The toggle content, if left empty it will render the default toggle (seen above).
17 */
18 children: PropTypes.node
19};
20
21var contextTypes = {
22 $bs_navbar: PropTypes.shape({
23 bsClass: PropTypes.string,
24 expanded: PropTypes.bool,
25 onToggle: PropTypes.func.isRequired
26 })
27};
28
29var NavbarToggle = function (_React$Component) {
30 _inherits(NavbarToggle, _React$Component);
31
32 function NavbarToggle() {
33 _classCallCheck(this, NavbarToggle);
34
35 return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
36 }
37
38 NavbarToggle.prototype.render = function render() {
39 var _props = this.props,
40 onClick = _props.onClick,
41 className = _props.className,
42 children = _props.children,
43 props = _objectWithoutProperties(_props, ['onClick', 'className', 'children']);
44
45 var navbarProps = this.context.$bs_navbar || { bsClass: 'navbar' };
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(
56 'button',
57 buttonProps,
58 children
59 );
60 }
61
62 return React.createElement(
63 'button',
64 buttonProps,
65 React.createElement(
66 'span',
67 { className: 'sr-only' },
68 'Toggle navigation'
69 ),
70 React.createElement('span', { className: 'icon-bar' }),
71 React.createElement('span', { className: 'icon-bar' }),
72 React.createElement('span', { className: 'icon-bar' })
73 );
74 };
75
76 return NavbarToggle;
77}(React.Component);
78
79NavbarToggle.propTypes = propTypes;
80NavbarToggle.contextTypes = contextTypes;
81
82export default NavbarToggle;
\No newline at end of file