2017-11-17 14:38:54 +08:00
|
|
|
import * as React from 'react';
|
2017-06-30 21:07:01 +08:00
|
|
|
import { Item } from 'rc-menu';
|
2018-08-07 21:07:52 +08:00
|
|
|
import * as PropTypes from 'prop-types';
|
2017-06-30 21:07:01 +08:00
|
|
|
import Tooltip from '../tooltip';
|
2018-12-07 20:02:01 +08:00
|
|
|
import { ClickParam } from './index';
|
2017-06-30 21:07:01 +08:00
|
|
|
|
2018-11-20 23:26:40 +08:00
|
|
|
interface MenuItemProps {
|
|
|
|
rootPrefixCls?: string;
|
|
|
|
disabled?: boolean;
|
|
|
|
level?: number;
|
|
|
|
title?: React.ReactNode;
|
|
|
|
children?: React.ReactNode;
|
2018-12-02 23:55:25 +08:00
|
|
|
className?: string;
|
2018-12-07 10:54:21 +08:00
|
|
|
onClick?: (param: ClickParam) => void;
|
2018-11-20 23:26:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class MenuItem extends React.Component<MenuItemProps, any> {
|
2017-10-27 20:21:34 +08:00
|
|
|
static contextTypes = {
|
|
|
|
inlineCollapsed: PropTypes.bool,
|
|
|
|
};
|
|
|
|
static isMenuItem = 1;
|
2018-11-09 17:38:19 +08:00
|
|
|
context: any;
|
2017-11-16 16:08:30 +08:00
|
|
|
private menuItem: any;
|
2018-12-13 22:03:12 +08:00
|
|
|
|
2017-11-21 17:38:51 +08:00
|
|
|
onKeyDown = (e: React.MouseEvent<HTMLElement>) => {
|
2017-11-16 16:08:30 +08:00
|
|
|
this.menuItem.onKeyDown(e);
|
2018-12-07 20:02:01 +08:00
|
|
|
};
|
2017-11-21 17:38:51 +08:00
|
|
|
saveMenuItem = (menuItem: any) => {
|
2017-11-16 16:08:30 +08:00
|
|
|
this.menuItem = menuItem;
|
2018-12-07 20:02:01 +08:00
|
|
|
};
|
2017-10-27 20:21:34 +08:00
|
|
|
render() {
|
|
|
|
const { inlineCollapsed } = this.context;
|
2018-11-20 23:26:40 +08:00
|
|
|
const { level, children, rootPrefixCls } = this.props;
|
|
|
|
const { title, ...rest } = this.props;
|
|
|
|
|
|
|
|
let titleNode;
|
|
|
|
if (inlineCollapsed) {
|
|
|
|
titleNode = title || (level === 1 ? children : '');
|
|
|
|
}
|
|
|
|
|
2018-05-10 10:59:33 +08:00
|
|
|
return (
|
|
|
|
<Tooltip
|
2018-11-20 23:26:40 +08:00
|
|
|
title={titleNode}
|
2018-05-10 10:59:33 +08:00
|
|
|
placement="right"
|
2018-11-20 23:26:40 +08:00
|
|
|
overlayClassName={`${rootPrefixCls}-inline-collapsed-tooltip`}
|
2018-05-10 10:59:33 +08:00
|
|
|
>
|
2018-11-20 23:26:40 +08:00
|
|
|
<Item {...rest} title={inlineCollapsed ? null : title} ref={this.saveMenuItem} />
|
2018-05-10 10:59:33 +08:00
|
|
|
</Tooltip>
|
|
|
|
);
|
2017-10-27 20:21:34 +08:00
|
|
|
}
|
|
|
|
}
|
2017-08-04 21:24:59 +08:00
|
|
|
|
2017-06-30 21:07:01 +08:00
|
|
|
export default MenuItem;
|