Refactor custom color code
This commit is contained in:
parent
b7ea220118
commit
c20b8f3877
@ -36,21 +36,17 @@ export default function ResolvedIcon({ icon, width = 32, height = 32, alt = "log
|
|||||||
const prefix = icon.split("-")[0];
|
const prefix = icon.split("-")[0];
|
||||||
|
|
||||||
if (prefix in iconSetURLs) {
|
if (prefix in iconSetURLs) {
|
||||||
// check whether icon ends with color code
|
// default to theme setting
|
||||||
let iconName;
|
let iconName = icon.replace(`${prefix}-`, "").replace(".svg", "");
|
||||||
let iconColor;
|
let iconColor = settings.iconStyle === "theme" ?
|
||||||
const suffix = icon.split("-")[icon.split("-").length - 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)))";
|
||||||
|
|
||||||
if (!(suffix.match(`[#][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]`) == null)) {
|
// use custom hex color if provided
|
||||||
// set custom color code
|
const colorMatches = icon.match(/[#][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]$/i)
|
||||||
iconName = icon.replace(`${prefix}-`, "").replace(".svg", "").replace(`-${suffix}`, "");
|
if (colorMatches?.length) {
|
||||||
iconColor = `${suffix}`;
|
iconName = icon.replace(`${prefix}-`, "").replace(".svg", "").replace(`-${colorMatches[0]}`, "");
|
||||||
} else {
|
iconColor = `${colorMatches[0]}`;
|
||||||
// default to theme setting if no custom icon color code is provided
|
|
||||||
iconName = icon.replace(`${prefix}-`, "").replace(".svg", "");
|
|
||||||
iconColor = settings.iconStyle === "theme" ?
|
|
||||||
`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)))";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const iconSource = `${iconSetURLs[prefix]}${iconName}.svg`;
|
const iconSource = `${iconSetURLs[prefix]}${iconName}.svg`;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user