-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathWindowTopBar.js
More file actions
117 lines (112 loc) · 4.32 KB
/
WindowTopBar.js
File metadata and controls
117 lines (112 loc) · 4.32 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import PropTypes from 'prop-types';
import { styled } from '@mui/material/styles';
import MenuIcon from '@mui/icons-material/MenuSharp';
import CloseIcon from '@mui/icons-material/CloseSharp';
import Toolbar from '@mui/material/Toolbar';
import AppBar from '@mui/material/AppBar';
import { useTranslation } from 'react-i18next';
import classNames from 'classnames';
import WindowTopMenuButton from '../containers/WindowTopMenuButton';
import WindowTopBarPluginArea from '../containers/WindowTopBarPluginArea';
import WindowTopBarPluginMenu from '../containers/WindowTopBarPluginMenu';
import WindowTopBarTitle from '../containers/WindowTopBarTitle';
import MiradorMenuButton from '../containers/MiradorMenuButton';
import FullScreenButton from '../containers/FullScreenButton';
import WindowMaxIcon from './icons/WindowMaxIcon';
import WindowMinIcon from './icons/WindowMinIcon';
import ns from '../config/css-ns';
const Root = styled(AppBar, { name: 'WindowTopBar', slot: 'root' })(() => ({
zIndex: 1100,
}));
const StyledToolbar = styled(Toolbar, { name: 'WindowTopBar', slot: 'toolbar' })(({ ownerState, theme }) => ({
backgroundColor: theme.palette.shades?.main,
borderTop: '2px solid',
borderTopColor: ownerState?.focused ? theme.palette.primary.main : 'transparent',
minHeight: 32,
paddingLeft: theme.spacing(0.5),
paddingRight: theme.spacing(0.5),
...(ownerState?.windowDraggable && {
cursor: 'move',
}),
}));
/**
* WindowTopBar
*/
export function WindowTopBar({
removeWindow, windowId, toggleWindowSideBar,
maximizeWindow = () => {}, maximized = false, minimizeWindow = () => {}, allowClose = true, allowMaximize = true,
focusWindow = () => {}, allowFullscreen = false, allowTopMenuButton = true, allowWindowSideBar = true,
component = 'nav', sideBarOpen = false,
}) {
const { t } = useTranslation();
const ownerState = arguments[0]; // eslint-disable-line prefer-rest-params
return (
<Root component={component} aria-label={t('windowNavigation')} position="relative" color="default" enableColorOnDark>
<StyledToolbar
disableGutters
onMouseDown={focusWindow}
ownerState={ownerState}
className={classNames(ns('window-top-bar'))}
variant="dense"
>
{allowWindowSideBar && (
<MiradorMenuButton
aria-expanded={sideBarOpen}
aria-label={t('toggleWindowSideBar')}
onClick={toggleWindowSideBar}
className={ns('window-menu-btn')}
>
<MenuIcon />
</MiradorMenuButton>
)}
<WindowTopBarTitle
windowId={windowId}
/>
{allowTopMenuButton && (
<WindowTopMenuButton windowId={windowId} className={ns('window-menu-btn')} />
)}
<WindowTopBarPluginArea windowId={windowId} />
<WindowTopBarPluginMenu windowId={windowId} />
{allowMaximize && (
<MiradorMenuButton
aria-label={(maximized ? t('minimizeWindow') : t('maximizeWindow'))}
className={classNames(ns('window-maximize'), ns('window-menu-btn'))}
onClick={(maximized ? minimizeWindow : maximizeWindow)}
>
{(maximized ? <WindowMinIcon /> : <WindowMaxIcon />)}
</MiradorMenuButton>
)}
{allowFullscreen && (
<FullScreenButton className={ns('window-menu-btn')} />
)}
{allowClose && (
<MiradorMenuButton
aria-label={t('closeWindow')}
className={classNames(ns('window-close'), ns('window-menu-btn'))}
onClick={removeWindow}
>
<CloseIcon />
</MiradorMenuButton>
)}
</StyledToolbar>
</Root>
);
}
WindowTopBar.propTypes = {
allowClose: PropTypes.bool,
allowFullscreen: PropTypes.bool,
allowMaximize: PropTypes.bool,
allowTopMenuButton: PropTypes.bool,
allowWindowSideBar: PropTypes.bool,
component: PropTypes.elementType,
focused: PropTypes.bool, // eslint-disable-line react/no-unused-prop-types
focusWindow: PropTypes.func,
maximized: PropTypes.bool,
maximizeWindow: PropTypes.func,
minimizeWindow: PropTypes.func,
removeWindow: PropTypes.func.isRequired,
sideBarOpen: PropTypes.bool,
toggleWindowSideBar: PropTypes.func.isRequired,
windowDraggable: PropTypes.bool, // eslint-disable-line react/no-unused-prop-types
windowId: PropTypes.string.isRequired,
};