2015-08-06 16:49:54 +08:00
|
|
|
import React from 'react';
|
2016-02-01 16:34:26 +08:00
|
|
|
import Menu, { Item, Divider, SubMenu, ItemGroup } from 'rc-menu';
|
2015-08-25 11:11:21 +08:00
|
|
|
import animation from '../common/openAnimation';
|
2015-08-06 16:49:54 +08:00
|
|
|
|
2015-11-05 14:18:46 +08:00
|
|
|
function noop() {
|
|
|
|
}
|
|
|
|
|
2015-08-06 16:49:54 +08:00
|
|
|
const AntMenu = React.createClass({
|
2015-08-24 18:18:46 +08:00
|
|
|
getDefaultProps() {
|
2015-08-06 16:49:54 +08:00
|
|
|
return {
|
2015-11-05 14:18:46 +08:00
|
|
|
prefixCls: 'ant-menu',
|
|
|
|
onClick: noop,
|
|
|
|
onOpen: noop,
|
|
|
|
onClose: noop,
|
2015-11-14 15:33:29 +08:00
|
|
|
className: '',
|
|
|
|
theme: 'light', // or dark
|
2015-11-05 14:18:46 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
getInitialState() {
|
|
|
|
return {
|
|
|
|
openKeys: []
|
2015-08-06 16:49:54 +08:00
|
|
|
};
|
|
|
|
},
|
2015-11-05 19:09:33 +08:00
|
|
|
handleClick(e) {
|
2015-11-05 14:18:46 +08:00
|
|
|
this.setState({
|
|
|
|
openKeys: []
|
|
|
|
});
|
2015-11-05 19:09:33 +08:00
|
|
|
this.props.onClick(e);
|
2015-11-05 14:18:46 +08:00
|
|
|
},
|
|
|
|
handleOpenKeys(e) {
|
|
|
|
this.setState({
|
|
|
|
openKeys: e.openKeys
|
|
|
|
});
|
2015-12-27 13:34:59 +08:00
|
|
|
this.props.onOpen(e);
|
2015-11-05 14:18:46 +08:00
|
|
|
},
|
|
|
|
handleCloseKeys(e) {
|
|
|
|
this.setState({
|
|
|
|
openKeys: e.openKeys
|
|
|
|
});
|
2015-12-27 13:34:59 +08:00
|
|
|
this.props.onClose(e);
|
2015-11-05 14:18:46 +08:00
|
|
|
},
|
2015-08-24 18:18:46 +08:00
|
|
|
render() {
|
2015-12-31 17:55:45 +08:00
|
|
|
let openAnimation = this.props.openAnimation || this.props.openTransitionName;
|
|
|
|
if (!openAnimation) {
|
|
|
|
switch (this.props.mode) {
|
2016-01-21 22:45:21 +08:00
|
|
|
case 'horizontal':
|
|
|
|
openAnimation = 'slide-up';
|
|
|
|
break;
|
|
|
|
case 'vertical':
|
|
|
|
openAnimation = 'zoom-big';
|
|
|
|
break;
|
|
|
|
case 'inline':
|
|
|
|
openAnimation = animation;
|
|
|
|
break;
|
|
|
|
default:
|
2015-12-31 17:55:45 +08:00
|
|
|
}
|
2015-08-24 18:18:46 +08:00
|
|
|
}
|
2015-11-12 14:57:54 +08:00
|
|
|
|
2015-12-31 17:55:45 +08:00
|
|
|
let props = {};
|
2016-02-17 18:04:42 +08:00
|
|
|
const className = `${this.props.className} ${this.props.prefixCls}-${this.props.theme}`;
|
2016-01-02 01:26:40 +08:00
|
|
|
if (this.props.mode !== 'inline') {
|
2015-12-31 17:55:45 +08:00
|
|
|
// 这组属性的目的是
|
|
|
|
// 弹出型的菜单需要点击后立即关闭
|
|
|
|
// 另外,弹出型的菜单的受控模式没有使用场景
|
|
|
|
props = {
|
|
|
|
openKeys: this.state.openKeys,
|
|
|
|
onClick: this.handleClick,
|
|
|
|
onOpen: this.handleOpenKeys,
|
|
|
|
onClose: this.handleCloseKeys,
|
2016-01-02 01:26:40 +08:00
|
|
|
openTransitionName: openAnimation,
|
2015-12-31 17:55:45 +08:00
|
|
|
className,
|
|
|
|
};
|
2015-08-24 18:18:46 +08:00
|
|
|
} else {
|
2015-12-31 17:55:45 +08:00
|
|
|
props = {
|
2016-01-02 01:26:40 +08:00
|
|
|
openAnimation,
|
2015-12-31 17:55:45 +08:00
|
|
|
className,
|
|
|
|
};
|
2015-08-24 18:18:46 +08:00
|
|
|
}
|
2015-12-31 17:55:45 +08:00
|
|
|
return <Menu {...this.props} {...props} />;
|
2015-08-06 16:49:54 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-02-01 16:34:26 +08:00
|
|
|
AntMenu.Divider = Divider;
|
|
|
|
AntMenu.Item = Item;
|
|
|
|
AntMenu.SubMenu = SubMenu;
|
|
|
|
AntMenu.ItemGroup = ItemGroup;
|
2015-08-06 16:49:54 +08:00
|
|
|
|
|
|
|
export default AntMenu;
|