mirror of
https://github.com/danbulant/dribbblish-dynamic-theme
synced 2026-06-05 07:41:48 +00:00
add ability to get icons as raw svg string without type annd stuff
This commit is contained in:
parent
25b5b771dd
commit
55e6ef0ca2
1 changed files with 17 additions and 8 deletions
|
|
@ -19,6 +19,22 @@ export default class Icons {
|
||||||
this.#icons = process.env.DRIBBBLISH_ICONS;
|
this.#icons = process.env.DRIBBBLISH_ICONS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRawSVG(name, style = "round") {
|
||||||
|
if (!this.#icons.hasOwnProperty(name)) throw new Error(`Icon "${name}" does not exist`);
|
||||||
|
|
||||||
|
if (typeof this.#icons[name] == "string") {
|
||||||
|
return this.#icons[name];
|
||||||
|
} else {
|
||||||
|
if (!this.#icons[name].hasOwnProperty(style)) {
|
||||||
|
const styles = Object.keys(this.#icons[name])
|
||||||
|
.map((s) => `"${s}"`)
|
||||||
|
.join(", ");
|
||||||
|
throw new Error(`Icon "${name}" does not have style "${style}". It is available in styles [${styles}].`);
|
||||||
|
}
|
||||||
|
return this.#icons[name][style];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {String} name icon name lowercase with dashes like `ac-unit`
|
* @param {String} name icon name lowercase with dashes like `ac-unit`
|
||||||
* @param {IconOptions} options
|
* @param {IconOptions} options
|
||||||
|
|
@ -36,14 +52,7 @@ export default class Icons {
|
||||||
};
|
};
|
||||||
options = { ...defaultOptions, ...options };
|
options = { ...defaultOptions, ...options };
|
||||||
|
|
||||||
if (!this.#icons.hasOwnProperty(name)) throw new Error(`Icon "${name}" does not exist`);
|
const svg = parseSVG(this.getRawSVG(name, options.style));
|
||||||
let svg;
|
|
||||||
if (typeof this.#icons[name] == "string") {
|
|
||||||
svg = parseSVG(this.#icons[name]);
|
|
||||||
} else {
|
|
||||||
if (!this.#icons[name].hasOwnProperty(options.style)) throw new Error(`Icon "${name}" does not have style "${options.style}"`);
|
|
||||||
svg = parseSVG(this.#icons[name][options.style]);
|
|
||||||
}
|
|
||||||
|
|
||||||
svg.attributes.type = "dribbblish-icon";
|
svg.attributes.type = "dribbblish-icon";
|
||||||
svg.attributes.fill = options.fill;
|
svg.attributes.fill = options.fill;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue