Browse Source

impl. mdi icons with the possibility for others

Ben Phelps 2 years ago
parent
commit
c95422b682
1 changed files with 29 additions and 13 deletions
  1. 29 13
      src/components/services/item.jsx

+ 29 - 13
src/components/services/item.jsx

@@ -9,19 +9,37 @@ import Docker from "widgets/docker/component";
 import { SettingsContext } from "utils/contexts/settings";
 import { SettingsContext } from "utils/contexts/settings";
 
 
 function resolveIcon(icon) {
 function resolveIcon(icon) {
-  if (icon.startsWith("http")) {
-    return icon;
+  // direct or relative URLs
+  if (icon.startsWith("http") || icon.startsWith("/")) {
+    return <Image src={`${icon}`} width={32} height={32} alt="logo" />;
   }
   }
 
 
-  if (icon.startsWith("/")) {
-    return icon;
-  }
-
-  if (icon.endsWith(".png")) {
-    return `https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons/png/${icon}`;
+  // mdi- prefixed, material design icons
+  if (icon.startsWith("mdi-")) {
+    const iconName = icon.replace("mdi-", "").replace(".svg", "");
+    return (
+      <div
+        style={{
+          width: 32,
+          height: 32,
+          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`,
+        }}
+      />
+    );
   }
   }
 
 
-  return `https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons/png/${icon}.png`;
+  // fallback to dashboard-icons
+  const iconName = icon.replace(".png", "");
+  return (
+    <Image
+      src={`https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons/png/${iconName}.png`}
+      width={32}
+      height={32}
+      alt="logo"
+    />
+  );
 }
 }
 
 
 export default function Item({ service }) {
 export default function Item({ service }) {
@@ -57,12 +75,10 @@ export default function Item({ service }) {
                 rel="noreferrer"
                 rel="noreferrer"
                 className="flex-shrink-0 flex items-center justify-center w-12 "
                 className="flex-shrink-0 flex items-center justify-center w-12 "
               >
               >
-                <Image src={resolveIcon(service.icon)} width={32} height={32} alt="logo" />
+                {resolveIcon(service.icon)}
               </a>
               </a>
             ) : (
             ) : (
-              <div className="flex-shrink-0 flex items-center justify-center w-12 ">
-                <Image src={resolveIcon(service.icon)} width={32} height={32} alt="logo" />
-              </div>
+              <div className="flex-shrink-0 flex items-center justify-center w-12 ">{resolveIcon(service.icon)}</div>
             ))}
             ))}
 
 
           {hasLink ? (
           {hasLink ? (