react-bootstrap
Version:
Bootstrap 3 components build with React
46 lines (39 loc) • 1.23 kB
JSX
var React = require('react');
var joinClasses = require('./utils/joinClasses');
var classSet = require('./utils/classSet');
var cloneWithProps = require('./utils/cloneWithProps');
var createChainedFunction = require('./utils/createChainedFunction');
var ValidComponentChildren = require('./utils/ValidComponentChildren');
var DropdownMenu = React.createClass({
propTypes: {
pullRight: React.PropTypes.bool,
onSelect: React.PropTypes.func
},
render: function () {
var classes = {
'dropdown-menu': true,
'dropdown-menu-right': this.props.pullRight
};
return (
<ul
{...this.props}
className={joinClasses(this.props.className, classSet(classes))}
role="menu">
{ValidComponentChildren.map(this.props.children, this.renderMenuItem)}
</ul>
);
},
renderMenuItem: function (child, index) {
return cloneWithProps(
child,
{
// Capture onSelect events
onSelect: createChainedFunction(child.props.onSelect, this.props.onSelect),
// Force special props to be transferred
key: child.key ? child.key : index,
ref: child.ref
}
);
}
});
module.exports = DropdownMenu;