2024-06-24 02:51:22 +01:00
|
|
|
import { Box } from '@mui/material';
|
|
|
|
|
import React from 'react';
|
|
|
|
|
import InputHeader from '../InputHeader';
|
|
|
|
|
import greyPattern from '@assets/grey-pattern.png';
|
2024-06-24 03:57:52 +01:00
|
|
|
import { globalInputHeight } from '../../config/uiConfig';
|
2024-06-24 02:51:22 +01:00
|
|
|
|
|
|
|
|
export default function ToolFileResult({
|
|
|
|
|
title = 'Result',
|
|
|
|
|
value
|
|
|
|
|
}: {
|
|
|
|
|
title?: string;
|
|
|
|
|
value: File | null;
|
|
|
|
|
}) {
|
|
|
|
|
const [preview, setPreview] = React.useState<string | null>(null);
|
|
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
|
if (value) {
|
|
|
|
|
const objectUrl = URL.createObjectURL(value);
|
|
|
|
|
setPreview(objectUrl);
|
|
|
|
|
|
|
|
|
|
return () => URL.revokeObjectURL(objectUrl);
|
|
|
|
|
} else {
|
|
|
|
|
setPreview(null);
|
|
|
|
|
}
|
|
|
|
|
}, [value]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box>
|
|
|
|
|
<InputHeader title={title} />
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
width: '100%',
|
2024-06-24 03:57:52 +01:00
|
|
|
height: globalInputHeight,
|
2024-06-24 02:51:22 +01:00
|
|
|
border: preview ? 0 : 1,
|
|
|
|
|
borderRadius: 2,
|
|
|
|
|
boxShadow: '5'
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{preview && (
|
|
|
|
|
<Box
|
|
|
|
|
width={'100%'}
|
|
|
|
|
height={'100%'}
|
|
|
|
|
sx={{
|
|
|
|
|
display: 'flex',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
backgroundImage: `url(${greyPattern})`
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<img
|
|
|
|
|
src={preview}
|
|
|
|
|
alt="Result"
|
2024-06-24 03:57:52 +01:00
|
|
|
style={{ maxWidth: '100%', maxHeight: globalInputHeight }}
|
2024-06-24 02:51:22 +01:00
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
}
|