fix(striker-ui): restyle Preview for server list

main
Tsu-ba-me 2 years ago
parent 26a64ecb2f
commit 3a1d7dc4b2
  1. 156
      striker-ui/components/Display/Preview.tsx

@ -1,72 +1,37 @@
import { Dispatch, SetStateAction, useEffect, useState } from 'react'; import { Dispatch, FC, SetStateAction, useEffect, useState } from 'react';
import { Box, IconButton, styled } from '@mui/material'; import { Box, IconButton as MUIIconButton } from '@mui/material';
import { import {
DesktopWindows as DesktopWindowsIcon, DesktopWindows as DesktopWindowsIcon,
PowerOffOutlined as PowerOffOutlinedIcon, PowerOffOutlined as PowerOffOutlinedIcon,
} from '@mui/icons-material'; } from '@mui/icons-material';
import { BLACK, GREY, TEXT } from '../../lib/consts/DEFAULT_THEME'; import { GREY } from '../../lib/consts/DEFAULT_THEME';
import { Panel } from '../Panels'; import IconButton from '../IconButton';
import { Panel, PanelHeader } from '../Panels';
import { HeaderText } from '../Text'; import { HeaderText } from '../Text';
const PREFIX = 'Preview'; type PreviewOptionalProps = {
isShowControls?: boolean;
const classes = { setMode?: Dispatch<SetStateAction<boolean>> | null;
displayBox: `${PREFIX}-displayBox`,
fullScreenButton: `${PREFIX}-fullScreenButton`,
fullScreenBox: `${PREFIX}-fullScreenBox`,
imageButton: `${PREFIX}-imageButton`,
powerOffIcon: `${PREFIX}-powerOffIcon`,
previewImage: `${PREFIX}-previewImage`,
}; };
const StyledDiv = styled('div')(() => ({ type PreviewProps = PreviewOptionalProps & {
[`& .${classes.displayBox}`]: {
padding: 0,
paddingTop: '.7em',
width: '100%',
},
[`& .${classes.fullScreenButton}`]: {
borderRadius: 8,
backgroundColor: TEXT,
'&:hover': {
backgroundColor: TEXT,
},
},
[`& .${classes.fullScreenBox}`]: {
paddingLeft: '1em',
padding: 0,
},
[`& .${classes.imageButton}`]: {
padding: 0,
color: TEXT,
},
[`& .${classes.powerOffIcon}`]: {
borderRadius: 8,
padding: 0,
color: GREY,
width: '100%',
height: '100%',
},
[`& .${classes.previewImage}`]: {
width: '100%',
height: '100%',
},
}));
interface PreviewProps {
setMode: Dispatch<SetStateAction<boolean>>;
uuid: string; uuid: string;
serverName: string | string[] | undefined; serverName: string | string[] | undefined;
} };
const Preview = ({ setMode, uuid, serverName }: PreviewProps): JSX.Element => { const PREVIEW_DEFAULT_PROPS: Required<PreviewOptionalProps> = {
isShowControls: true,
setMode: null,
};
const Preview: FC<PreviewProps> = ({
isShowControls = PREVIEW_DEFAULT_PROPS.isShowControls,
serverName,
setMode,
uuid,
}) => {
const [preview, setPreview] = useState<string>(); const [preview, setPreview] = useState<string>();
useEffect(() => { useEffect(() => {
@ -91,44 +56,61 @@ const Preview = ({ setMode, uuid, serverName }: PreviewProps): JSX.Element => {
return ( return (
<Panel> <Panel>
<StyledDiv> <PanelHeader>
<Box flexGrow={1}> <HeaderText text={`Server: ${serverName}`} />
<HeaderText text={`Server: ${serverName}`} /> </PanelHeader>
<Box
sx={{
display: 'flex',
width: '100%',
'& > :not(:last-child)': {
marginRight: '1em',
},
}}
>
<Box>
<MUIIconButton
component="span"
onClick={() => setMode?.call(null, false)}
sx={{
color: GREY,
padding: 0,
}}
>
{preview ? (
<Box
alt=""
component="img"
src={`data:image/png;base64,${preview}`}
sx={{
height: '100%',
width: '100%',
}}
/>
) : (
<PowerOffOutlinedIcon
sx={{
height: '100%',
padding: 0,
width: '100%',
}}
/>
)}
</MUIIconButton>
</Box> </Box>
<Box display="flex" className={classes.displayBox}> {isShowControls && (
<Box> <Box>
<IconButton <IconButton onClick={() => setMode?.call(null, false)}>
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 className={classes.fullScreenBox}>
<IconButton
className={classes.fullScreenButton}
style={{ color: BLACK }}
component="span"
onClick={() => setMode(false)}
>
<DesktopWindowsIcon /> <DesktopWindowsIcon />
</IconButton> </IconButton>
</Box> </Box>
</Box> )}
</StyledDiv> </Box>
</Panel> </Panel>
); );
}; };
Preview.defaultProps = PREVIEW_DEFAULT_PROPS;
export default Preview; export default Preview;

Loading…
Cancel
Save