Skip to content
Snippets Groups Projects
Commit 8a3a78bc authored by Chris Beer's avatar Chris Beer
Browse files

Use the minimal window as the mosaic drag preview; part of #1981

parent c0dd7a2c
Branches
Tags
No related merge requests found
import React from 'react'; import React from 'react';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import MinimalWindow from '../../../src/containers/MinimalWindow';
import { MosaicRenderPreview } from '../../../src/components/MosaicRenderPreview'; import { MosaicRenderPreview } from '../../../src/components/MosaicRenderPreview';
describe('MosaicRenderPreview', () => { describe('MosaicRenderPreview', () => {
...@@ -12,9 +13,9 @@ describe('MosaicRenderPreview', () => { ...@@ -12,9 +13,9 @@ describe('MosaicRenderPreview', () => {
/>, />,
); );
expect(wrapper.find('.mosaic-window-body').length).toBe(1); expect(wrapper.find(MinimalWindow).length).toBe(1);
expect( expect(
wrapper.find('.mosaic-window-body').children().text(), wrapper.find(MinimalWindow).prop('label'),
).toEqual('previewWindowTitle The Title Prop'); ).toEqual('previewWindowTitle The Title Prop');
}); });
}); });
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import MenuIcon from '@material-ui/icons/MenuSharp';
import cn from 'classnames'; import cn from 'classnames';
import Paper from '@material-ui/core/Paper'; import Paper from '@material-ui/core/Paper';
import AppBar from '@material-ui/core/AppBar'; import AppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar'; import Toolbar from '@material-ui/core/Toolbar';
import Typography from '@material-ui/core/Typography';
import CloseIcon from '@material-ui/icons/CloseSharp'; import CloseIcon from '@material-ui/icons/CloseSharp';
import MiradorMenuButton from '../containers/MiradorMenuButton'; import MiradorMenuButton from '../containers/MiradorMenuButton';
import ns from '../config/css-ns'; import ns from '../config/css-ns';
...@@ -14,6 +16,7 @@ export class MinimalWindow extends Component { ...@@ -14,6 +16,7 @@ export class MinimalWindow extends Component {
render() { render() {
const { const {
allowClose, allowClose,
allowWindowSideBar,
children, children,
classes, classes,
label, label,
...@@ -28,7 +31,7 @@ export class MinimalWindow extends Component { ...@@ -28,7 +31,7 @@ export class MinimalWindow extends Component {
elevation={1} elevation={1}
id={windowId} id={windowId}
className={ className={
cn(classes.window, ns('window'))} cn(classes.window, ns('placeholder-window'))}
aria-label={t('window', { label })} aria-label={t('window', { label })}
> >
<AppBar position="relative" color="default"> <AppBar position="relative" color="default">
...@@ -40,7 +43,18 @@ export class MinimalWindow extends Component { ...@@ -40,7 +43,18 @@ export class MinimalWindow extends Component {
)} )}
variant="dense" variant="dense"
> >
{allowClose && ( {allowWindowSideBar && (
<MiradorMenuButton
aria-label={t('toggleWindowSideBar')}
disabled
>
<MenuIcon />
</MiradorMenuButton>
)}
<Typography variant="h2" noWrap color="inherit" className={classes.title}>
{label}
</Typography>
{allowClose && removeWindow && (
<MiradorMenuButton <MiradorMenuButton
aria-label={t('closeWindow')} aria-label={t('closeWindow')}
className={cn(classes.button, ns('window-close'))} className={cn(classes.button, ns('window-close'))}
...@@ -59,17 +73,21 @@ export class MinimalWindow extends Component { ...@@ -59,17 +73,21 @@ export class MinimalWindow extends Component {
MinimalWindow.propTypes = { MinimalWindow.propTypes = {
allowClose: PropTypes.bool, allowClose: PropTypes.bool,
allowWindowSideBar: PropTypes.bool,
children: PropTypes.node, children: PropTypes.node,
classes: PropTypes.objectOf(PropTypes.string).isRequired, classes: PropTypes.objectOf(PropTypes.string),
label: PropTypes.string, label: PropTypes.string,
removeWindow: PropTypes.func.isRequired, removeWindow: PropTypes.func,
t: PropTypes.func, t: PropTypes.func,
windowId: PropTypes.string.isRequired, windowId: PropTypes.string.isRequired,
}; };
MinimalWindow.defaultProps = { MinimalWindow.defaultProps = {
allowClose: true, allowClose: true,
allowWindowSideBar: true,
children: null, children: null,
classes: {},
label: '', label: '',
removeWindow: () => {},
t: key => key, t: key => key,
}; };
import React from 'react'; import React from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classNames from 'classnames'; import MinimalWindow from '../containers/MinimalWindow';
/** /**
* MosaicRenderPreview is used to for the preview when dragging a mosaic window/tile * MosaicRenderPreview is used to for the preview when dragging a mosaic window/tile
*/ */
export function MosaicRenderPreview(props) { export function MosaicRenderPreview(props) {
const { const {
classes, t, title, t, title, windowId,
} = props; } = props;
return ( return (
<div className={classNames('mosaic-window-body', classes.preview)}> <MinimalWindow windowId={`${windowId}-preview`} label={t('previewWindowTitle', { title })} />
{t('previewWindowTitle', { title })}
</div>
); );
} }
MosaicRenderPreview.propTypes = { MosaicRenderPreview.propTypes = {
classes: PropTypes.objectOf(PropTypes.string),
t: PropTypes.func, t: PropTypes.func,
title: PropTypes.string, title: PropTypes.string,
windowId: PropTypes.string.isRequired, // eslint-disable-line react/no-unused-prop-types windowId: PropTypes.string.isRequired, // eslint-disable-line react/no-unused-prop-types
}; };
MosaicRenderPreview.defaultProps = { MosaicRenderPreview.defaultProps = {
classes: {},
t: k => k, t: k => k,
title: '', title: '',
}; };
...@@ -9,6 +9,7 @@ import { MinimalWindow } from '../components/MinimalWindow'; ...@@ -9,6 +9,7 @@ import { MinimalWindow } from '../components/MinimalWindow';
/** mapStateToProps */ /** mapStateToProps */
const mapStateToProps = (state, { windowId }) => ({ const mapStateToProps = (state, { windowId }) => ({
allowClose: state.config.window.allowClose, allowClose: state.config.window.allowClose,
allowWindowSideBar: state.config.window.allowWindowSideBar,
}); });
/** /**
...@@ -29,6 +30,11 @@ const styles = theme => ({ ...@@ -29,6 +30,11 @@ const styles = theme => ({
button: { button: {
marginLeft: 'auto', marginLeft: 'auto',
}, },
title: {
...theme.typography.h6,
flexGrow: 1,
paddingLeft: theme.spacing(0.5),
},
window: { window: {
backgroundColor: theme.palette.shades.dark, backgroundColor: theme.palette.shades.dark,
borderRadius: 0, borderRadius: 0,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment