homepage/src/components/resolvedicon.jsx

38 lines
1.2 KiB
React
Raw Normal View History

import Image from "next/future/image";
2023-01-13 22:45:08 +01:00
export default function ResolvedIcon({ icon, width = 32, height = 32, alt = "logo" }) {
// direct or relative URLs
if (icon.startsWith("http") || icon.startsWith("/")) {
2023-01-13 22:45:08 +01:00
return <Image src={`${icon}`} width={width} height={height} alt={alt} />;
}
// mdi- prefixed, material design icons
if (icon.startsWith("mdi-")) {
const iconName = icon.replace("mdi-", "").replace(".svg", "");
return (
<div
style={{
2022-12-11 10:30:04 -08:00
width,
height,
2022-11-06 14:41:02 -08:00
maxWidth: '100%',
maxHeight: '100%',
background: "linear-gradient(180deg, rgb(var(--color-logo-start)), rgb(var(--color-logo-stop)))",
mask: `url(https://cdn.jsdelivr.net/npm/@mdi/svg@latest/svg/${iconName}.svg) no-repeat center / contain`,
WebkitMask: `url(https://cdn.jsdelivr.net/npm/@mdi/svg@latest/svg/${iconName}.svg) no-repeat center / contain`,
}}
/>
);
}
// fallback to dashboard-icons
const iconName = icon.replace(".png", "");
return (
<Image
src={`https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons/png/${iconName}.png`}
2022-12-11 10:30:04 -08:00
width={width}
height={height}
2023-01-13 22:45:08 +01:00
alt={alt}
/>
);
2023-01-13 22:45:08 +01:00
}