refactor(striker-ui): migrate MUI v4->5 on Display/Preview

main
Tsu-ba-me 3 years ago
parent 465894eb81
commit a887a03b33
  1. 121
      striker-ui/components/Display/Preview.tsx

@ -1,55 +1,72 @@
import { Dispatch, SetStateAction, useEffect, useState } from 'react'; import { Dispatch, SetStateAction, useEffect, useState } from 'react';
import { Box } from '@material-ui/core'; import { Box, IconButton, styled } from '@mui/material';
import { makeStyles } from '@material-ui/core/styles'; import {
import IconButton from '@material-ui/core/IconButton'; DesktopWindows as DesktopWindowsIcon,
import DesktopWindowsIcon from '@material-ui/icons/DesktopWindows'; PowerOffOutlined as PowerOffOutlinedIcon,
import PowerOffOutlinedIcon from '@material-ui/icons/PowerOffOutlined'; } from '@mui/icons-material';
import { Panel } from '../Panels';
import { BLACK, GREY, TEXT } from '../../lib/consts/DEFAULT_THEME'; import { BLACK, GREY, TEXT } from '../../lib/consts/DEFAULT_THEME';
import { Panel } from '../Panels';
import { HeaderText } from '../Text'; import { HeaderText } from '../Text';
interface PreviewProps { const PREFIX = 'Preview';
setMode: Dispatch<SetStateAction<boolean>>;
uuid: string; const classes = {
serverName: string | string[] | undefined; displayBox: `${PREFIX}-displayBox`,
} fullScreenButton: `${PREFIX}-fullScreenButton`,
fullScreenBox: `${PREFIX}-fullScreenBox`,
imageButton: `${PREFIX}-imageButton`,
powerOffIcon: `${PREFIX}-powerOffIcon`,
previewImage: `${PREFIX}-previewImage`,
};
const useStyles = makeStyles(() => ({ const StyledDiv = styled('div')(() => ({
displayBox: { [`& .${classes.displayBox}`]: {
padding: 0, padding: 0,
paddingTop: '.7em', paddingTop: '.7em',
width: '100%', width: '100%',
}, },
fullScreenButton: {
[`& .${classes.fullScreenButton}`]: {
borderRadius: 8, borderRadius: 8,
backgroundColor: TEXT, backgroundColor: TEXT,
'&:hover': { '&:hover': {
backgroundColor: TEXT, backgroundColor: TEXT,
}, },
}, },
fullScreenBox: {
[`& .${classes.fullScreenBox}`]: {
paddingLeft: '1em', paddingLeft: '1em',
padding: 0, padding: 0,
}, },
imageButton: {
[`& .${classes.imageButton}`]: {
padding: 0, padding: 0,
color: TEXT, color: TEXT,
}, },
powerOffIcon: {
[`& .${classes.powerOffIcon}`]: {
borderRadius: 8, borderRadius: 8,
padding: 0, padding: 0,
color: GREY, color: GREY,
width: '100%', width: '100%',
height: '100%', height: '100%',
}, },
previewImage: {
[`& .${classes.previewImage}`]: {
width: '100%', width: '100%',
height: '100%', height: '100%',
}, },
})); }));
interface PreviewProps {
setMode: Dispatch<SetStateAction<boolean>>;
uuid: string;
serverName: string | string[] | undefined;
}
const Preview = ({ setMode, uuid, serverName }: PreviewProps): JSX.Element => { const Preview = ({ setMode, uuid, serverName }: PreviewProps): JSX.Element => {
const classes = useStyles();
const [preview, setPreview] = useState<string>(); const [preview, setPreview] = useState<string>();
useEffect(() => { useEffect(() => {
@ -74,40 +91,42 @@ const Preview = ({ setMode, uuid, serverName }: PreviewProps): JSX.Element => {
return ( return (
<Panel> <Panel>
<Box flexGrow={1}> <StyledDiv>
<HeaderText text={`Server: ${serverName}`} /> <Box flexGrow={1}>
</Box> <HeaderText text={`Server: ${serverName}`} />
<Box display="flex" className={classes.displayBox}>
<Box>
<IconButton
className={classes.imageButton}
style={{ color: BLACK }}
component="span"
onClick={() => setMode(false)}
>
{!preview ? (
<PowerOffOutlinedIcon className={classes.powerOffIcon} />
) : (
<img
alt=""
key="preview"
src={`data:image/png;base64,${preview}`}
className={classes.previewImage}
/>
)}
</IconButton>
</Box> </Box>
<Box className={classes.fullScreenBox}> <Box display="flex" className={classes.displayBox}>
<IconButton <Box>
className={classes.fullScreenButton} <IconButton
style={{ color: BLACK }} className={classes.imageButton}
component="span" style={{ color: BLACK }}
onClick={() => setMode(false)} component="span"
> onClick={() => setMode(false)}
<DesktopWindowsIcon /> >
</IconButton> {!preview ? (
<PowerOffOutlinedIcon className={classes.powerOffIcon} />
) : (
<img
alt=""
key="preview"
src={`data:image/png;base64,${preview}`}
className={classes.previewImage}
/>
)}
</IconButton>
</Box>
<Box className={classes.fullScreenBox}>
<IconButton
className={classes.fullScreenButton}
style={{ color: BLACK }}
component="span"
onClick={() => setMode(false)}
>
<DesktopWindowsIcon />
</IconButton>
</Box>
</Box> </Box>
</Box> </StyledDiv>
</Panel> </Panel>
); );
}; };

Loading…
Cancel
Save