forked from 18xx-maker/18xx-maker
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Viewport.jsx
executable file
·56 lines (49 loc) · 1.75 KB
/
Viewport.jsx
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
import React, { useContext } from "react";
import Box from "@material-ui/core/Box";
import { needSideMenu } from "./nav/IfSideMenu";
import { useLocation } from "react-router-dom";
import { useTheme } from '@material-ui/core/styles';
import { useBooleanParam } from "./util/query";
import useMediaQuery from '@material-ui/core/useMediaQuery';
import GameContext from "./context/GameContext";
import { makeStyles } from '@material-ui/core/styles';
const useStyles = makeStyles((theme) => ({
viewport: {
transitionProperty: 'width, margin-left, margin-right',
transitionDuration: theme.transitions.duration.shorter,
transitionTimingFunction: theme.transitions.easing.sharp,
overflow: 'auto'
}
}));
const Viewport = ({sideNavOpen, children}) => {
const classes = useStyles();
const [print] = useBooleanParam('print');
const { game } = useContext(GameContext);
const location = useLocation();
const searchParams = new URLSearchParams(location.search);
const configOpen = searchParams.has('config');
const theme = useTheme();
const isSmall = useMediaQuery(theme.breakpoints.up('sm'));
const isMedium = useMediaQuery(theme.breakpoints.up('md'));
const isLarge = useMediaQuery(theme.breakpoints.up('lg'));
let marginLeft = '0px';
let marginRight = '0px';
if (!print) {
if (needSideMenu(location, game) && (isMedium || sideNavOpen)) {
marginLeft = '300px';
}
if (configOpen) {
if (isLarge) {
marginRight = '35%';
} else if(isSmall) {
marginRight = '50%';
}
}
}
let width = `calc(100% - ${marginLeft} - ${marginRight})`;
return <Box className={classes.viewport}
style={{ width, marginLeft, marginRight }}>
{children}
</Box>;
};
export default Viewport;