forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move CollapsableNav => CollapsibleNav
And refactor CollapsableNav to use CollapsibleMixin
- Loading branch information
Showing
2 changed files
with
125 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,8 @@ | ||
import React, { cloneElement } from 'react'; | ||
import BootstrapMixin from './BootstrapMixin'; | ||
import CollapsableMixin from './CollapsableMixin'; | ||
import classNames from 'classnames'; | ||
import domUtils from './utils/domUtils'; | ||
import deprecationWarning from './utils/deprecationWarning'; | ||
import CollapsibleNav from './CollapsibleNav'; | ||
|
||
import ValidComponentChildren from './utils/ValidComponentChildren'; | ||
import createChainedFunction from './utils/createChainedFunction'; | ||
let CollapsableNav = CollapsibleNav; | ||
|
||
const CollapsableNav = React.createClass({ | ||
mixins: [BootstrapMixin, CollapsableMixin], | ||
|
||
propTypes: { | ||
onSelect: React.PropTypes.func, | ||
activeHref: React.PropTypes.string, | ||
activeKey: React.PropTypes.any, | ||
collapsable: React.PropTypes.bool, | ||
expanded: React.PropTypes.bool, | ||
eventKey: React.PropTypes.any | ||
}, | ||
|
||
getCollapsableDOMNode() { | ||
return this.getDOMNode(); | ||
}, | ||
|
||
getCollapsableDimensionValue() { | ||
let height = 0; | ||
let nodes = this.refs; | ||
for (let key in nodes) { | ||
if (nodes.hasOwnProperty(key)) { | ||
|
||
let n = nodes[key].getDOMNode() | ||
, h = n.offsetHeight | ||
, computedStyles = domUtils.getComputedStyles(n); | ||
|
||
height += (h + parseInt(computedStyles.marginTop, 10) + parseInt(computedStyles.marginBottom, 10)); | ||
} | ||
} | ||
return height; | ||
}, | ||
|
||
render() { | ||
/* | ||
* this.props.collapsable is set in NavBar when a eventKey is supplied. | ||
*/ | ||
let classes = this.props.collapsable ? this.getCollapsableClassSet() : {}; | ||
/* | ||
* prevent duplicating navbar-collapse call if passed as prop. kind of overkill... good cadidate to have check implemented as a util that can | ||
* also be used elsewhere. | ||
*/ | ||
if (this.props.className === undefined || this.props.className.split(' ').indexOf('navbar-collapse') === -2) { | ||
classes['navbar-collapse'] = this.props.collapsable; | ||
} | ||
|
||
return ( | ||
<div eventKey={this.props.eventKey} className={classNames(this.props.className, classes)} > | ||
{ValidComponentChildren.map(this.props.children, this.props.collapsable ? this.renderCollapsableNavChildren : this.renderChildren )} | ||
</div> | ||
); | ||
}, | ||
|
||
getChildActiveProp(child) { | ||
if (child.props.active) { | ||
return true; | ||
} | ||
if (this.props.activeKey != null) { | ||
if (child.props.eventKey === this.props.activeKey) { | ||
return true; | ||
} | ||
} | ||
if (this.props.activeHref != null) { | ||
if (child.props.href === this.props.activeHref) { | ||
return true; | ||
} | ||
} | ||
|
||
return child.props.active; | ||
}, | ||
|
||
renderChildren(child, index) { | ||
let key = child.key ? child.key : index; | ||
return cloneElement( | ||
child, | ||
{ | ||
activeKey: this.props.activeKey, | ||
activeHref: this.props.activeHref, | ||
ref: 'nocollapse_' + key, | ||
key: key, | ||
navItem: true | ||
} | ||
); | ||
}, | ||
|
||
renderCollapsableNavChildren(child, index) { | ||
let key = child.key ? child.key : index; | ||
return cloneElement( | ||
child, | ||
{ | ||
active: this.getChildActiveProp(child), | ||
activeKey: this.props.activeKey, | ||
activeHref: this.props.activeHref, | ||
onSelect: createChainedFunction(child.props.onSelect, this.props.onSelect), | ||
ref: 'collapsable_' + key, | ||
key: key, | ||
navItem: true | ||
} | ||
); | ||
} | ||
}); | ||
deprecationWarning('CollapsableNav', 'CollapsibleNav'); | ||
|
||
export default CollapsableNav; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import React, { cloneElement } from 'react'; | ||
import BootstrapMixin from './BootstrapMixin'; | ||
import CollapsibleMixin from './CollapsibleMixin'; | ||
import classNames from 'classnames'; | ||
import domUtils from './utils/domUtils'; | ||
|
||
import ValidComponentChildren from './utils/ValidComponentChildren'; | ||
import createChainedFunction from './utils/createChainedFunction'; | ||
|
||
const CollapsibleNav = React.createClass({ | ||
mixins: [BootstrapMixin, CollapsibleMixin], | ||
|
||
propTypes: { | ||
onSelect: React.PropTypes.func, | ||
activeHref: React.PropTypes.string, | ||
activeKey: React.PropTypes.any, | ||
collapsable: React.PropTypes.bool, | ||
expanded: React.PropTypes.bool, | ||
eventKey: React.PropTypes.any | ||
}, | ||
|
||
getCollapsibleDOMNode() { | ||
return this.getDOMNode(); | ||
}, | ||
|
||
getCollapsibleDimensionValue() { | ||
let height = 0; | ||
let nodes = this.refs; | ||
for (let key in nodes) { | ||
if (nodes.hasOwnProperty(key)) { | ||
|
||
let n = nodes[key].getDOMNode() | ||
, h = n.offsetHeight | ||
, computedStyles = domUtils.getComputedStyles(n); | ||
|
||
height += (h + | ||
parseInt(computedStyles.marginTop, 10) + | ||
parseInt(computedStyles.marginBottom, 10) | ||
); | ||
} | ||
} | ||
return height; | ||
}, | ||
|
||
render() { | ||
/* | ||
* this.props.collapsable is set in NavBar when a eventKey is supplied. | ||
*/ | ||
let classes = this.props.collapsable ? this.getCollapsibleClassSet() : {}; | ||
/* | ||
* prevent duplicating navbar-collapse call if passed as prop. | ||
* kind of overkill... | ||
* good cadidate to have check implemented as an util that can | ||
* also be used elsewhere. | ||
*/ | ||
if (this.props.className === undefined || | ||
this.props.className.split(' ').indexOf('navbar-collapse') === -2) { | ||
classes['navbar-collapse'] = this.props.collapsable; | ||
} | ||
|
||
return ( | ||
<div eventKey={this.props.eventKey} className={classNames(this.props.className, classes)} > | ||
{ValidComponentChildren.map(this.props.children, | ||
this.props.collapsable ? | ||
this.renderCollapsibleNavChildren : | ||
this.renderChildren | ||
)} | ||
</div> | ||
); | ||
}, | ||
|
||
getChildActiveProp(child) { | ||
if (child.props.active) { | ||
return true; | ||
} | ||
if (this.props.activeKey != null) { | ||
if (child.props.eventKey === this.props.activeKey) { | ||
return true; | ||
} | ||
} | ||
if (this.props.activeHref != null) { | ||
if (child.props.href === this.props.activeHref) { | ||
return true; | ||
} | ||
} | ||
|
||
return child.props.active; | ||
}, | ||
|
||
renderChildren(child, index) { | ||
let key = child.key ? child.key : index; | ||
return cloneElement( | ||
child, | ||
{ | ||
activeKey: this.props.activeKey, | ||
activeHref: this.props.activeHref, | ||
ref: 'nocollapse_' + key, | ||
key: key, | ||
navItem: true | ||
} | ||
); | ||
}, | ||
|
||
renderCollapsibleNavChildren(child, index) { | ||
let key = child.key ? child.key : index; | ||
return cloneElement( | ||
child, | ||
{ | ||
active: this.getChildActiveProp(child), | ||
activeKey: this.props.activeKey, | ||
activeHref: this.props.activeHref, | ||
onSelect: createChainedFunction(child.props.onSelect, this.props.onSelect), | ||
ref: 'collapsable_' + key, | ||
key: key, | ||
navItem: true | ||
} | ||
); | ||
} | ||
}); | ||
|
||
export default CollapsibleNav; |