UNPKG

react-bootstrap

Version:

Bootstrap 3 components build with React

73 lines (61 loc) 1.7 kB
/** @jsx React.DOM */ import React from './react-es6'; import classSet from './react-es6/lib/cx'; import BootstrapMixin from './BootstrapMixin'; import utils from './utils'; var Nav = React.createClass({ mixins: [BootstrapMixin], propTypes: { bsStyle: React.PropTypes.oneOf(['tabs','pills']), stacked: React.PropTypes.bool, justified: React.PropTypes.bool, onSelect: React.PropTypes.func }, getDefaultProps: function () { return { bsClass: 'nav' }; }, render: function () { var classes = this.getBsClassSet(); classes['nav-stacked'] = this.props.stacked; classes['nav-justified'] = this.props.justified; return this.transferPropsTo( <nav> <ul className={classSet(classes)}> {utils.modifyChildren(this.props.children, this.renderNavItem)} </ul> </nav> ); }, getChildActiveProp: function (child) { if (child.props.active) { return true; } if (this.props.activeKey != null) { if (child.props.key === this.props.activeKey) { return true; } } if (this.props.activeHref != null) { if (child.props.href === this.props.activeHref) { return true; } } return child.props.active; }, renderNavItem: function (child) { return utils.cloneWithProps( child, { active: this.getChildActiveProp(child), activeKey: this.props.activeKey, activeHref: this.props.activeHref, onSelect: utils.createChainedFunction(child.onSelect, this.props.onSelect), ref: child.props.ref, key: child.props.key } ); } }); export default = Nav;