1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
3 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
4 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
5 | import _inherits from 'babel-runtime/helpers/inherits';
|
6 |
|
7 |
|
8 |
|
9 | import classNames from 'classnames';
|
10 | import React from 'react';
|
11 | import PropTypes from 'prop-types';
|
12 | import elementType from 'prop-types-extra/lib/elementType';
|
13 | import uncontrollable from 'uncontrollable';
|
14 |
|
15 | import Grid from './Grid';
|
16 | import NavbarBrand from './NavbarBrand';
|
17 | import NavbarCollapse from './NavbarCollapse';
|
18 | import NavbarHeader from './NavbarHeader';
|
19 | import NavbarToggle from './NavbarToggle';
|
20 | import { bsClass as setBsClass, bsStyles, getClassSet, prefix, splitBsPropsAndOmit } from './utils/bootstrapUtils';
|
21 | import { Style } from './utils/StyleConfig';
|
22 | import createChainedFunction from './utils/createChainedFunction';
|
23 |
|
24 | var propTypes = {
|
25 | |
26 |
|
27 |
|
28 |
|
29 | fixedTop: PropTypes.bool,
|
30 | |
31 |
|
32 |
|
33 |
|
34 | fixedBottom: PropTypes.bool,
|
35 | |
36 |
|
37 |
|
38 | staticTop: PropTypes.bool,
|
39 | |
40 |
|
41 |
|
42 | inverse: PropTypes.bool,
|
43 | |
44 |
|
45 |
|
46 |
|
47 | fluid: PropTypes.bool,
|
48 |
|
49 | |
50 |
|
51 |
|
52 | componentClass: elementType,
|
53 | |
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | onToggle: PropTypes.func,
|
61 | |
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | onSelect: PropTypes.func,
|
83 | |
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 | collapseOnSelect: PropTypes.bool,
|
91 | |
92 |
|
93 |
|
94 |
|
95 |
|
96 | expanded: PropTypes.bool,
|
97 |
|
98 | role: PropTypes.string
|
99 | };
|
100 |
|
101 | var defaultProps = {
|
102 | componentClass: 'nav',
|
103 | fixedTop: false,
|
104 | fixedBottom: false,
|
105 | staticTop: false,
|
106 | inverse: false,
|
107 | fluid: false,
|
108 | collapseOnSelect: false
|
109 | };
|
110 |
|
111 | var childContextTypes = {
|
112 | $bs_navbar: PropTypes.shape({
|
113 | bsClass: PropTypes.string,
|
114 | expanded: PropTypes.bool,
|
115 | onToggle: PropTypes.func.isRequired,
|
116 | onSelect: PropTypes.func
|
117 | })
|
118 | };
|
119 |
|
120 | var Navbar = function (_React$Component) {
|
121 | _inherits(Navbar, _React$Component);
|
122 |
|
123 | function Navbar(props, context) {
|
124 | _classCallCheck(this, Navbar);
|
125 |
|
126 | var _this = _possibleConstructorReturn(this, _React$Component.call(this, props, context));
|
127 |
|
128 | _this.handleToggle = _this.handleToggle.bind(_this);
|
129 | _this.handleCollapse = _this.handleCollapse.bind(_this);
|
130 | return _this;
|
131 | }
|
132 |
|
133 | Navbar.prototype.getChildContext = function getChildContext() {
|
134 | var _props = this.props,
|
135 | bsClass = _props.bsClass,
|
136 | expanded = _props.expanded,
|
137 | onSelect = _props.onSelect,
|
138 | collapseOnSelect = _props.collapseOnSelect;
|
139 |
|
140 |
|
141 | return {
|
142 | $bs_navbar: {
|
143 | bsClass: bsClass,
|
144 | expanded: expanded,
|
145 | onToggle: this.handleToggle,
|
146 | onSelect: createChainedFunction(onSelect, collapseOnSelect ? this.handleCollapse : null)
|
147 | }
|
148 | };
|
149 | };
|
150 |
|
151 | Navbar.prototype.handleCollapse = function handleCollapse() {
|
152 | var _props2 = this.props,
|
153 | onToggle = _props2.onToggle,
|
154 | expanded = _props2.expanded;
|
155 |
|
156 |
|
157 | if (expanded) {
|
158 | onToggle(false);
|
159 | }
|
160 | };
|
161 |
|
162 | Navbar.prototype.handleToggle = function handleToggle() {
|
163 | var _props3 = this.props,
|
164 | onToggle = _props3.onToggle,
|
165 | expanded = _props3.expanded;
|
166 |
|
167 |
|
168 | onToggle(!expanded);
|
169 | };
|
170 |
|
171 | Navbar.prototype.render = function render() {
|
172 | var _extends2;
|
173 |
|
174 | var _props4 = this.props,
|
175 | Component = _props4.componentClass,
|
176 | fixedTop = _props4.fixedTop,
|
177 | fixedBottom = _props4.fixedBottom,
|
178 | staticTop = _props4.staticTop,
|
179 | inverse = _props4.inverse,
|
180 | fluid = _props4.fluid,
|
181 | className = _props4.className,
|
182 | children = _props4.children,
|
183 | props = _objectWithoutProperties(_props4, ['componentClass', 'fixedTop', 'fixedBottom', 'staticTop', 'inverse', 'fluid', 'className', 'children']);
|
184 |
|
185 | var _splitBsPropsAndOmit = splitBsPropsAndOmit(props, ['expanded', 'onToggle', 'onSelect', 'collapseOnSelect']),
|
186 | bsProps = _splitBsPropsAndOmit[0],
|
187 | elementProps = _splitBsPropsAndOmit[1];
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 | if (elementProps.role === undefined && Component !== 'nav') {
|
195 | elementProps.role = 'navigation';
|
196 | }
|
197 |
|
198 | if (inverse) {
|
199 | bsProps.bsStyle = Style.INVERSE;
|
200 | }
|
201 |
|
202 | var classes = _extends({}, getClassSet(bsProps), (_extends2 = {}, _extends2[prefix(bsProps, 'fixed-top')] = fixedTop, _extends2[prefix(bsProps, 'fixed-bottom')] = fixedBottom, _extends2[prefix(bsProps, 'static-top')] = staticTop, _extends2));
|
203 |
|
204 | return React.createElement(
|
205 | Component,
|
206 | _extends({}, elementProps, { className: classNames(className, classes) }),
|
207 | React.createElement(
|
208 | Grid,
|
209 | { fluid: fluid },
|
210 | children
|
211 | )
|
212 | );
|
213 | };
|
214 |
|
215 | return Navbar;
|
216 | }(React.Component);
|
217 |
|
218 | Navbar.propTypes = propTypes;
|
219 | Navbar.defaultProps = defaultProps;
|
220 | Navbar.childContextTypes = childContextTypes;
|
221 |
|
222 | setBsClass('navbar', Navbar);
|
223 |
|
224 | var UncontrollableNavbar = uncontrollable(Navbar, { expanded: 'onToggle' });
|
225 |
|
226 | function createSimpleWrapper(tag, suffix, displayName) {
|
227 | var Wrapper = function Wrapper(_ref, _ref2) {
|
228 | var _ref2$$bs_navbar = _ref2.$bs_navbar,
|
229 | navbarProps = _ref2$$bs_navbar === undefined ? { bsClass: 'navbar' } : _ref2$$bs_navbar;
|
230 |
|
231 | var Component = _ref.componentClass,
|
232 | className = _ref.className,
|
233 | pullRight = _ref.pullRight,
|
234 | pullLeft = _ref.pullLeft,
|
235 | props = _objectWithoutProperties(_ref, ['componentClass', 'className', 'pullRight', 'pullLeft']);
|
236 |
|
237 | return React.createElement(Component, _extends({}, props, {
|
238 | className: classNames(className, prefix(navbarProps, suffix), pullRight && prefix(navbarProps, 'right'), pullLeft && prefix(navbarProps, 'left'))
|
239 | }));
|
240 | };
|
241 |
|
242 | Wrapper.displayName = displayName;
|
243 |
|
244 | Wrapper.propTypes = {
|
245 | componentClass: elementType,
|
246 | pullRight: PropTypes.bool,
|
247 | pullLeft: PropTypes.bool
|
248 | };
|
249 |
|
250 | Wrapper.defaultProps = {
|
251 | componentClass: tag,
|
252 | pullRight: false,
|
253 | pullLeft: false
|
254 | };
|
255 |
|
256 | Wrapper.contextTypes = {
|
257 | $bs_navbar: PropTypes.shape({
|
258 | bsClass: PropTypes.string
|
259 | })
|
260 | };
|
261 |
|
262 | return Wrapper;
|
263 | }
|
264 |
|
265 | UncontrollableNavbar.Brand = NavbarBrand;
|
266 | UncontrollableNavbar.Header = NavbarHeader;
|
267 | UncontrollableNavbar.Toggle = NavbarToggle;
|
268 | UncontrollableNavbar.Collapse = NavbarCollapse;
|
269 |
|
270 | UncontrollableNavbar.Form = createSimpleWrapper('div', 'form', 'NavbarForm');
|
271 | UncontrollableNavbar.Text = createSimpleWrapper('p', 'text', 'NavbarText');
|
272 | UncontrollableNavbar.Link = createSimpleWrapper('a', 'link', 'NavbarLink');
|
273 |
|
274 |
|
275 | export default bsStyles([Style.DEFAULT, Style.INVERSE], Style.DEFAULT, UncontrollableNavbar); |
\ | No newline at end of file |