-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathWindowTopBarPluginMenu.js
More file actions
77 lines (70 loc) · 2.17 KB
/
WindowTopBarPluginMenu.js
File metadata and controls
77 lines (70 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { useContext, useId, useState } from 'react';
import PropTypes from 'prop-types';
import MoreVertIcon from '@mui/icons-material/MoreVertSharp';
import Menu from '@mui/material/Menu';
import { useTranslation } from 'react-i18next';
import MiradorMenuButton from '../containers/MiradorMenuButton';
import { PluginHook } from './PluginHook';
import WorkspaceContext from '../contexts/WorkspaceContext';
/**
*
*/
export function WindowTopBarPluginMenu({
PluginComponents = [], windowId, menuIcon = <MoreVertIcon />,
}) {
const { t } = useTranslation();
const container = useContext(WorkspaceContext);
const pluginProps = arguments[0]; // eslint-disable-line prefer-rest-params
const [anchorEl, setAnchorEl] = useState(null);
const [open, setOpen] = useState(false);
const windowPluginMenuId = useId();
/** */
const handleMenuClick = (event) => {
setAnchorEl(event.currentTarget);
setOpen(true);
};
/** */
const handleMenuClose = () => {
setAnchorEl(null);
setOpen(false);
};
if (!PluginComponents || PluginComponents.length === 0) return null;
return (
<>
<MiradorMenuButton
aria-haspopup="true"
aria-label={t('windowPluginMenu')}
aria-owns={open ? windowPluginMenuId : undefined}
selected={open}
onClick={handleMenuClick}
>
{menuIcon}
</MiradorMenuButton>
<Menu
id={windowPluginMenuId}
container={container?.current}
anchorEl={anchorEl}
anchorOrigin={{
horizontal: 'right',
vertical: 'bottom',
}}
transformOrigin={{
horizontal: 'right',
vertical: 'top',
}}
open={open}
onClose={handleMenuClose}
>
<PluginHook handleClose={handleMenuClose} {...pluginProps} />
</Menu>
</>
);
}
WindowTopBarPluginMenu.propTypes = {
anchorEl: PropTypes.object, // eslint-disable-line react/forbid-prop-types
container: PropTypes.shape({ current: PropTypes.instanceOf(Element) }),
menuIcon: PropTypes.element,
open: PropTypes.bool,
PluginComponents: PropTypes.array, // eslint-disable-line react/forbid-prop-types
windowId: PropTypes.string.isRequired,
};