|
1 | | -import React, { cloneElement } from 'react'; |
2 | | -import BootstrapMixin from './BootstrapMixin'; |
3 | | -import CollapsableMixin from './CollapsableMixin'; |
4 | | -import classNames from 'classnames'; |
5 | | -import domUtils from './utils/domUtils'; |
| 1 | +import deprecationWarning from './utils/deprecationWarning'; |
| 2 | +import CollapsibleNav from './CollapsibleNav'; |
6 | 3 |
|
7 | | -import ValidComponentChildren from './utils/ValidComponentChildren'; |
8 | | -import createChainedFunction from './utils/createChainedFunction'; |
| 4 | +let CollapsableNav = CollapsibleNav; |
9 | 5 |
|
10 | | -const CollapsableNav = React.createClass({ |
11 | | - mixins: [BootstrapMixin, CollapsableMixin], |
12 | | - |
13 | | - propTypes: { |
14 | | - onSelect: React.PropTypes.func, |
15 | | - activeHref: React.PropTypes.string, |
16 | | - activeKey: React.PropTypes.any, |
17 | | - collapsable: React.PropTypes.bool, |
18 | | - expanded: React.PropTypes.bool, |
19 | | - eventKey: React.PropTypes.any |
20 | | - }, |
21 | | - |
22 | | - getCollapsableDOMNode() { |
23 | | - return this.getDOMNode(); |
24 | | - }, |
25 | | - |
26 | | - getCollapsableDimensionValue() { |
27 | | - let height = 0; |
28 | | - let nodes = this.refs; |
29 | | - for (let key in nodes) { |
30 | | - if (nodes.hasOwnProperty(key)) { |
31 | | - |
32 | | - let n = nodes[key].getDOMNode() |
33 | | - , h = n.offsetHeight |
34 | | - , computedStyles = domUtils.getComputedStyles(n); |
35 | | - |
36 | | - height += (h + parseInt(computedStyles.marginTop, 10) + parseInt(computedStyles.marginBottom, 10)); |
37 | | - } |
38 | | - } |
39 | | - return height; |
40 | | - }, |
41 | | - |
42 | | - render() { |
43 | | - /* |
44 | | - * this.props.collapsable is set in NavBar when a eventKey is supplied. |
45 | | - */ |
46 | | - let classes = this.props.collapsable ? this.getCollapsableClassSet() : {}; |
47 | | - /* |
48 | | - * prevent duplicating navbar-collapse call if passed as prop. kind of overkill... good cadidate to have check implemented as a util that can |
49 | | - * also be used elsewhere. |
50 | | - */ |
51 | | - if (this.props.className === undefined || this.props.className.split(' ').indexOf('navbar-collapse') === -2) { |
52 | | - classes['navbar-collapse'] = this.props.collapsable; |
53 | | - } |
54 | | - |
55 | | - return ( |
56 | | - <div eventKey={this.props.eventKey} className={classNames(this.props.className, classes)} > |
57 | | - {ValidComponentChildren.map(this.props.children, this.props.collapsable ? this.renderCollapsableNavChildren : this.renderChildren )} |
58 | | - </div> |
59 | | - ); |
60 | | - }, |
61 | | - |
62 | | - getChildActiveProp(child) { |
63 | | - if (child.props.active) { |
64 | | - return true; |
65 | | - } |
66 | | - if (this.props.activeKey != null) { |
67 | | - if (child.props.eventKey === this.props.activeKey) { |
68 | | - return true; |
69 | | - } |
70 | | - } |
71 | | - if (this.props.activeHref != null) { |
72 | | - if (child.props.href === this.props.activeHref) { |
73 | | - return true; |
74 | | - } |
75 | | - } |
76 | | - |
77 | | - return child.props.active; |
78 | | - }, |
79 | | - |
80 | | - renderChildren(child, index) { |
81 | | - let key = child.key ? child.key : index; |
82 | | - return cloneElement( |
83 | | - child, |
84 | | - { |
85 | | - activeKey: this.props.activeKey, |
86 | | - activeHref: this.props.activeHref, |
87 | | - ref: 'nocollapse_' + key, |
88 | | - key: key, |
89 | | - navItem: true |
90 | | - } |
91 | | - ); |
92 | | - }, |
93 | | - |
94 | | - renderCollapsableNavChildren(child, index) { |
95 | | - let key = child.key ? child.key : index; |
96 | | - return cloneElement( |
97 | | - child, |
98 | | - { |
99 | | - active: this.getChildActiveProp(child), |
100 | | - activeKey: this.props.activeKey, |
101 | | - activeHref: this.props.activeHref, |
102 | | - onSelect: createChainedFunction(child.props.onSelect, this.props.onSelect), |
103 | | - ref: 'collapsable_' + key, |
104 | | - key: key, |
105 | | - navItem: true |
106 | | - } |
107 | | - ); |
108 | | - } |
109 | | -}); |
| 6 | +deprecationWarning('CollapsableNav', 'CollapsibleNav'); |
110 | 7 |
|
111 | 8 | export default CollapsableNav; |
0 commit comments