Add custom colors to resolvedicon.jsx
Enables appending a color code (e.g. "#123456") to all mdi and si icons, in order to change their color to a per-icon custom one.
This commit is contained in:
parent
f4fa098f6b
commit
50146dc08e
@ -33,13 +33,17 @@ export default function ResolvedIcon({ icon, width = 32, height = 32, alt = "log
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check mdi- or si- prefixed icons
|
// check mdi- or si- prefixed icons
|
||||||
const prefix = icon.split("-")[0]
|
const prefix = icon.split("-")[0];
|
||||||
|
const suffix = icon.split("-")[icon.split("-").length - 1];
|
||||||
|
|
||||||
if (prefix in iconSetURLs) {
|
|
||||||
// get icon source
|
// get icon source
|
||||||
const iconName = icon.replace(`${prefix}-`, "").replace(".svg", "");
|
if (prefix in iconSetURLs) {
|
||||||
const iconSource = `${iconSetURLs[prefix]}${iconName}.svg`;
|
// check whether icon ends with color code
|
||||||
|
if (!(suffix.match(`[#][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]`) == null)) {
|
||||||
|
|
||||||
|
const iconColor = `${suffix}`;
|
||||||
|
const iconName = icon.replace(`${prefix}-`, "").replace(".svg", "").replace(`-${suffix}`, "");
|
||||||
|
const iconSource = `${iconSetURLs[prefix]}${iconName}.svg`;
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
@ -47,16 +51,35 @@ export default function ResolvedIcon({ icon, width = 32, height = 32, alt = "log
|
|||||||
height,
|
height,
|
||||||
maxWidth: '100%',
|
maxWidth: '100%',
|
||||||
maxHeight: '100%',
|
maxHeight: '100%',
|
||||||
background: settings.iconStyle === "theme" ?
|
background: `${iconColor}`,
|
||||||
|
mask: `url(${iconSource}) no-repeat center / contain`,
|
||||||
|
WebkitMask: `url(${iconSource}) no-repeat center / contain`,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (suffix.match(`[#][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]`) == null) {
|
||||||
|
const iconColor = settings.iconStyle === "theme" ?
|
||||||
`rgb(var(--color-${ theme === "dark" ? 300 : 900 }) / var(--tw-text-opacity, 1))` :
|
`rgb(var(--color-${ theme === "dark" ? 300 : 900 }) / var(--tw-text-opacity, 1))` :
|
||||||
"linear-gradient(180deg, rgb(var(--color-logo-start)), rgb(var(--color-logo-stop)))",
|
"linear-gradient(180deg, rgb(var(--color-logo-start)), rgb(var(--color-logo-stop)))";
|
||||||
|
const iconName = icon.replace(`${prefix}-`, "").replace(".svg", "");
|
||||||
|
const iconSource = `${iconSetURLs[prefix]}${iconName}.svg`;
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
maxWidth: '100%',
|
||||||
|
maxHeight: '100%',
|
||||||
|
background: `${iconColor}`,
|
||||||
mask: `url(${iconSource}) no-repeat center / contain`,
|
mask: `url(${iconSource}) no-repeat center / contain`,
|
||||||
WebkitMask: `url(${iconSource}) no-repeat center / contain`,
|
WebkitMask: `url(${iconSource}) no-repeat center / contain`,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// fallback to dashboard-icons
|
// fallback to dashboard-icons
|
||||||
if (icon.endsWith(".svg")) {
|
if (icon.endsWith(".svg")) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user