Skip to content

Commit eae5234

Browse files
committed
AssetRenderer component to include download icon and style customization
1 parent c38c3ac commit eae5234

File tree

1 file changed

+58
-4
lines changed

1 file changed

+58
-4
lines changed

llmstack/client/src/components/apps/renderer/AssetRenderer.jsx

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,63 @@
11
import { useEffect, useState } from "react";
2+
import { Box, IconButton } from "@mui/material";
3+
import { DownloadOutlined } from "@mui/icons-material";
24
import { axios } from "../../../data/axios";
35
import loadingImage from "../../../assets/images/loading.gif";
46

57
const Image = (props) => {
6-
const { url, alt } = props;
7-
return <img src={url} alt={alt || "Asset"} width={"100%"} />;
8+
const { url, alt, noDownload, styleJson } = props;
9+
const [showDownloadIcon, setShowDownloadIcon] = useState(false);
10+
11+
return (
12+
<Box
13+
onMouseEnter={() => setShowDownloadIcon(true)}
14+
onMouseLeave={() => setShowDownloadIcon(false)}
15+
sx={{ position: "relative" }}
16+
>
17+
{showDownloadIcon && !noDownload && url && (
18+
<Box
19+
sx={{
20+
display: "flex",
21+
borderRadius: "4px 0 0 0",
22+
justifyContent: "space-between",
23+
alignItems: "center",
24+
padding: "3px 0",
25+
position: "absolute",
26+
top: 0,
27+
left: 0,
28+
backgroundColor: "rgba(255, 255, 255, 0.8)",
29+
}}
30+
>
31+
<IconButton
32+
sx={{ color: "#333" }}
33+
onClick={() => {
34+
window.open(url, "_blank");
35+
}}
36+
>
37+
<DownloadOutlined fontSize="small" />
38+
</IconButton>
39+
</Box>
40+
)}
41+
<img
42+
src={url || loadingImage}
43+
alt={alt || "Asset"}
44+
style={{
45+
...{
46+
display: "block",
47+
objectFit: "contain",
48+
maxWidth: "100%",
49+
borderRadius: "4px",
50+
boxShadow: "0px 0px 4px 0px #7d7d7d",
51+
},
52+
...styleJson,
53+
}}
54+
/>
55+
</Box>
56+
);
857
};
958

1059
export const AssetRenderer = (props) => {
11-
const { url, type } = props;
60+
const { url, type, noDownload, styleJson } = props;
1261
const [file, setFile] = useState(null);
1362

1463
useEffect(() => {
@@ -30,7 +79,12 @@ export const AssetRenderer = (props) => {
3079

3180
if (type.startsWith("image")) {
3281
return (
33-
<Image url={file?.url || loadingImage} alt={file?.name || "Loading"} />
82+
<Image
83+
url={file?.url || loadingImage}
84+
alt={file?.name || "Loading"}
85+
noDownload={noDownload}
86+
styleJson={styleJson}
87+
/>
3488
);
3589
}
3690

0 commit comments

Comments
 (0)