This commit is contained in:
yehuozhili
2021-07-11 23:52:15 +08:00
parent fd981cadfd
commit 2ee2c3fb50
2 changed files with 50 additions and 3 deletions

View File

@@ -2,4 +2,44 @@
title: 右键菜单
sTitle: dooringx-lib插件开发
order: 15
---
---
右键菜单可以进行自定义:
```js
// 自定义右键
const contextMenuState = config.getContextMenuState();
const unmountContextMenu = contextMenuState.unmountContextMenu;
const commander = config.getCommanderRegister();
const ContextMenu = () => {
const handleclick = () => {
unmountContextMenu();
};
return (
<div
style={{
left: contextMenuState.left,
top: contextMenuState.top,
position: 'fixed',
background: 'rgb(24, 23, 23)',
}}
>
<div
style={{ width: '100%' }}
onClick={() => {
commander.exec('redo');
handleclick();
}}
>
<Button>自定义</Button>
</div>
</div>
);
};
contextMenuState.contextMenu = <ContextMenu></ContextMenu>;
```
先拿到contextMenuStatecontextMenuState上有个unmountContextMenu是关闭右键菜单方法。
所以在点击后需要调用关闭。
同时上面的left和top是右键的位置。