Add utils for css-based icons

This commit is contained in:
Tom Najdek 2023-10-12 18:54:02 +02:00 committed by Dan Stillman
parent 1dd3812e00
commit 61f9d65552
2 changed files with 38 additions and 1 deletions

View file

@ -217,4 +217,18 @@ module.exports.getDOMElement = function (icon) {
div.innerHTML = renderToStaticMarkup(React.createElement(module.exports[icon]));
domElementCache[icon] = div.firstChild;
return domElementCache[icon].cloneNode(true);
}
};
let cssIconsCache = new Map();
module.exports.getCSSIcon = function (key) {
if (!cssIconsCache.has(key)) {
let iconEl = document.createElement('span');
iconEl.classList.add('icon');
iconEl.classList.add('icon-css');
iconEl.classList.add(key);
cssIconsCache.set(key, iconEl);
}
return cssIconsCache.get(key).cloneNode(true);
};

View file

@ -2,3 +2,26 @@
// Mixins
// --------------------------------------------------
@mixin svgicon($icon, $color, $size: "16", $prefix: false, $has2x: false) {
@if $has2x {
@if $prefix {
background-image: image-set(url('chrome://zotero/skin/#{$prefix}/#{$size}/#{$color}/#{$icon}.svg') 1x,
url('chrome://zotero/skin/#{$prefix}/#{$size}/#{$color}/#{$icon}@2x.svg') 2x);
}
@else {
background-image: image-set(url('chrome://zotero/skin/#{$size}/#{$color}/#{$icon}.svg') 1x,
url('chrome://zotero/skin/#{$size}/#{$color}/#{$icon}@2x.svg') 2x);
}
}
@else {
@if $prefix {
background-image: url('chrome://zotero/skin/#{$prefix}/#{$size}/#{$color}/#{$icon}.svg');
}
@else {
background-image: url('chrome://zotero/skin/#{$size}/#{$color}/#{$icon}.svg');
}
}
}