1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 23:20:51 +00:00

package text-dropdown-menu for text-button dropdown menu

This commit is contained in:
shanshuirenjia
2019-04-21 16:27:20 +08:00
parent a3c9ae98b7
commit 79462f5fd3
3 changed files with 129 additions and 15 deletions

View File

@@ -30,7 +30,6 @@ class ItemDropDownMenu extends React.Component {
menuList: [],
isItemMenuShow: false,
};
}
componentDidMount() {
@@ -96,7 +95,7 @@ class ItemDropDownMenu extends React.Component {
onMenuItemClick = (event) => {
let operation = event.target.dataset.toggle;
this.props.onMenuItemClick(operation);
this.props.onMenuItemClick(operation, event);
}
render() {

View File

@@ -0,0 +1,105 @@
import React from 'react';
import PropTypes from 'prop-types';
import listener from '../context-menu/globalEventListener';
import { Dropdown, DropdownMenu, DropdownToggle, DropdownItem } from 'reactstrap';
import { gettext } from '../../utils/constants';
const propTypes = {
menuClass: PropTypes.string,
menuType: PropTypes.oneOf(['pc', 'mobile']),
menuChildren: PropTypes.string.isRequired,
menuList: PropTypes.array.isRequired,
isHandleContextMenuEvent: PropTypes.bool,
onMenuItemClick: PropTypes.func.isRequired,
};
class TextDropDownMenu extends React.Component {
static defaultProps = {
isHandleContextMenuEvent: true,
menuType: 'pc',
};
constructor(props) {
super(props);
this.state = {
isItemMenuShow: false,
};
}
componentDidMount() {
if (this.props.isHandleContextMenuEvent) {
this.listenerId = listener.register(this.onShowMenu, this.onHideMenu);
}
}
componentWillUnmount() {
if (this.props.isHandleContextMenuEvent && this.listenerId) {
listener.unregister(this.listenerId);
}
}
onShowMenu = () => {
// nothing todo
}
onHideMenu = () => {
if (this.state.isItemMenuShow) {
this.setState({isItemMenuShow: false});
}
}
onDropdownToggleClick = (e) => {
e.preventDefault();
e.stopPropagation();
this.toggleOperationMenu();
}
toggleOperationMenu = () => {
this.setState({isItemMenuShow: !this.state.isItemMenuShow});
}
onMenuItemClick = (event) => {
let operation = event.target.dataset.toggle;
this.props.onMenuItemClick(operation, event);
}
render() {
let { menuClass, menuChildren, menuList } = this.props;
menuClass = 'btn btn-secondary operation-item ' + menuClass;
if (!menuList.length) {
return '';
}
return (
<Dropdown isOpen={this.state.isItemMenuShow} toggle={this.toggleOperationMenu}>
<DropdownToggle
className={menuClass}
title={gettext('More Operations')}
data-toggle="dropdown"
aria-expanded={this.state.isItemMenuShow}
// onClick={this.onDropdownToggleClick}
>
{menuChildren}
</DropdownToggle>
<DropdownMenu>
{menuList.map((menuItem, index) => {
if (menuItem === 'Divider') {
return <DropdownItem key={index} divider />;
} else {
return (
<DropdownItem key={index} data-toggle={menuItem.key} onClick={this.onMenuItemClick}>{menuItem.value}</DropdownItem>
);
}
})}
</DropdownMenu>
</Dropdown>
);
}
}
TextDropDownMenu.propTypes = propTypes;
export default TextDropDownMenu;