2021-02-09 21:01:42 +00:00
|
|
|
import React, { Component } from 'react';
|
2021-03-15 21:59:14 +00:00
|
|
|
import { Popover, List, ListItem, ListButton, Link, Icon, Actions, ActionsGroup, ActionsButton } from 'framework7-react';
|
2021-02-09 21:01:42 +00:00
|
|
|
import { f7 } from 'framework7-react';
|
2021-03-15 21:59:14 +00:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2021-02-09 21:01:42 +00:00
|
|
|
|
2021-02-16 17:31:27 +00:00
|
|
|
const idContextMenuElement = "idx-context-menu-popover";
|
|
|
|
|
2021-02-09 21:01:42 +00:00
|
|
|
class ContextMenuView extends Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
// f7.popover.open('#idx-context-menu-popover', '#idx-context-menu-target');
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const buttons = this.props.items || {};
|
|
|
|
|
|
|
|
return (
|
2021-02-16 17:31:27 +00:00
|
|
|
<Popover id={idContextMenuElement}
|
2021-02-09 21:01:42 +00:00
|
|
|
className="document-menu"
|
|
|
|
backdrop={false}
|
|
|
|
closeByBackdropClick={false}
|
|
|
|
closeByOutsideClick={false}
|
|
|
|
onPopoverClosed={e => this.props.onMenuClosed()}
|
|
|
|
>
|
|
|
|
<List className="list-block">
|
|
|
|
{buttons.map((b, index) =>
|
2021-03-03 11:47:49 +00:00
|
|
|
!b.icon ?
|
|
|
|
<ListButton title={b.caption} key={index} onClick={e => this.props.onMenuItemClick(b.event)} /> :
|
2021-03-17 08:46:57 +00:00
|
|
|
<ListButton key={index} onClick={e => this.props.onMenuItemClick(b.event)}>
|
2021-02-09 21:01:42 +00:00
|
|
|
<Icon slot="media" icon={`icon_mask ${b.icon}`} />
|
|
|
|
</ListButton>
|
|
|
|
)}
|
|
|
|
</List>
|
|
|
|
</Popover>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-15 21:59:14 +00:00
|
|
|
const ActionsWithExtraItems = ({items, onMenuItemClick, opened, onActionClosed}) => {
|
|
|
|
const { t } = useTranslation();
|
|
|
|
const _t = t('ContextMenu', {returnObjects: true});
|
|
|
|
return (
|
|
|
|
<Actions opened={opened} onActionsClosed={() => onActionClosed()}>
|
|
|
|
<ActionsGroup>
|
|
|
|
{items.length > 0 && items.map((item, index)=>{
|
|
|
|
return(
|
|
|
|
<ActionsButton key={`act-${item.caption}`} onClick={() => {onMenuItemClick(item.event)}}>{item.caption}</ActionsButton>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</ActionsGroup>
|
|
|
|
<ActionsGroup>
|
|
|
|
<ActionsButton>{_t.menuCancel}</ActionsButton>
|
|
|
|
</ActionsGroup>
|
|
|
|
</Actions>
|
|
|
|
)
|
|
|
|
};
|
|
|
|
|
2021-03-01 18:55:58 +00:00
|
|
|
const exportedIdMenuElemen = `#${idContextMenuElement}`;
|
2021-03-15 21:59:14 +00:00
|
|
|
export {ContextMenuView as default, exportedIdMenuElemen as idContextMenuElement, ActionsWithExtraItems};
|