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

main
Tsu-ba-me 3 years ago
parent 26a64ecb2f
commit 3a1d7dc4b2
  1. 140
      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_DEFAULT_PROPS: Required<PreviewOptionalProps> = {
isShowControls: true,
setMode: null,
};
const Preview = ({ setMode, uuid, serverName }: PreviewProps): JSX.Element => { 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}`} />
</Box> </PanelHeader>
<Box display="flex" className={classes.displayBox}> <Box
sx={{
display: 'flex',
width: '100%',
'& > :not(:last-child)': {
marginRight: '1em',
},
}}
>
<Box> <Box>
<IconButton <MUIIconButton
className={classes.imageButton}
style={{ color: BLACK }}
component="span" component="span"
onClick={() => setMode(false)} onClick={() => setMode?.call(null, false)}
sx={{
color: GREY,
padding: 0,
}}
> >
{!preview ? ( {preview ? (
<PowerOffOutlinedIcon className={classes.powerOffIcon} /> <Box
) : (
<img
alt="" alt=""
key="preview" component="img"
src={`data:image/png;base64,${preview}`} src={`data:image/png;base64,${preview}`}
className={classes.previewImage} sx={{
height: '100%',
width: '100%',
}}
/>
) : (
<PowerOffOutlinedIcon
sx={{
height: '100%',
padding: 0,
width: '100%',
}}
/> />
)} )}
</IconButton> </MUIIconButton>
</Box> </Box>
<Box className={classes.fullScreenBox}> {isShowControls && (
<IconButton <Box>
className={classes.fullScreenButton} <IconButton onClick={() => setMode?.call(null, false)}>
style={{ color: BLACK }}
component="span"
onClick={() => setMode(false)}
>
<DesktopWindowsIcon /> <DesktopWindowsIcon />
</IconButton> </IconButton>
</Box> </Box>
)}
</Box> </Box>
</StyledDiv>
</Panel> </Panel>
); );
}; };
Preview.defaultProps = PREVIEW_DEFAULT_PROPS;
export default Preview; export default Preview;

Loading…
Cancel
Save