-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathFileIcon.tsx
53 lines (48 loc) · 1.16 KB
/
FileIcon.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// @ts-ignore
import DOMPurify from "dompurify";
import { useMemo } from "react";
import { themeIcons } from "seti-file-icons";
export interface FileIconProps {
filename: string;
height: `${number}px`;
width: `${number}px`;
}
export default function FileIcon({ filename, height, width }: FileIconProps) {
const file = useMemo(() => {
if (filename.includes(" (")) {
const path = filename.split(" ");
path.pop();
return path.join(" ");
} else {
return filename;
}
}, [filename]);
const getIcon = themeIcons({
blue: "#268bd2",
grey: "#657b83",
"grey-light": "#839496",
green: "#859900",
orange: "#cb4b16",
pink: "#d33682",
purple: "#6c71c4",
red: "#dc322f",
white: "#fdf6e3",
yellow: "#b58900",
ignore: "#586e75",
});
// Sanitize the SVG string before rendering it
const { svg, color } = getIcon(file);
const sanitizedSVG = DOMPurify.sanitize(svg);
return (
<span
dangerouslySetInnerHTML={{ __html: sanitizedSVG }}
style={{
width: width,
height: height,
fill: color,
flexShrink: 0,
display: "block",
}}
/>
);
}