You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.6 KiB

9 years ago
import React from 'react';
import Menu from 'rc-menu';
9 years ago
import animation from '../common/openAnimation';
9 years ago
function noop() {
}
9 years ago
const AntMenu = React.createClass({
getDefaultProps() {
9 years ago
return {
prefixCls: 'ant-menu',
onClick: noop,
onOpen: noop,
onClose: noop,
9 years ago
className: '',
theme: 'light', // or dark
};
},
getInitialState() {
return {
openKeys: []
9 years ago
};
},
handleClick(e) {
this.setState({
openKeys: []
});
this.props.onClick(e);
},
handleOpenKeys(e) {
this.setState({
openKeys: e.openKeys
});
this.props.onOpen();
},
handleCloseKeys(e) {
this.setState({
openKeys: e.openKeys
});
this.props.onClose();
},
render() {
let openAnimation = '';
switch (this.props.mode) {
case 'horizontal':
openAnimation = 'slide-up';
break;
case 'vertical':
openAnimation = 'zoom-big';
break;
case 'inline':
openAnimation = animation;
break;
default:
}
9 years ago
let props = {
openKeys: this.state.openKeys,
onClick: this.handleClick,
onOpen: this.handleOpenKeys,
onClose: this.handleCloseKeys,
};
9 years ago
const className = this.props.className + ' ' + this.props.prefixCls + '-' + this.props.theme;
if (this.props.mode === 'inline') {
9 years ago
return <Menu {...this.props} className={className} openAnimation={openAnimation} />;
} else {
9 years ago
return <Menu {...this.props} {...props} className={className} openTransitionName={openAnimation} />;
}
9 years ago
}
});
AntMenu.Divider = Menu.Divider;
AntMenu.Item = Menu.Item;
AntMenu.SubMenu = Menu.SubMenu;
export default AntMenu;