helpers to * generate a color from a string consistently * generate a html tag for a tag * related css classes
Signed-off-by: Dominik Csapak <d.csa...@proxmox.com> --- src/Utils.js | 35 +++++++++++++++++++++++++++++ src/css/ext6-pmx.css | 52 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/src/Utils.js b/src/Utils.js index 6a03057..3130b2a 100644 --- a/src/Utils.js +++ b/src/Utils.js @@ -1272,6 +1272,41 @@ utilities: { .map(val => val.charCodeAt(0)), ); }, + + stringToRGB: function(string) { + let hash = 0; + if (!string) { + return hash; + } + string += 'prox'; // give short strings more variance + for (let i = 0; i < string.length; i++) { + hash = string.charCodeAt(i) + ((hash << 5) - hash); + hash = hash & hash; // to int + } + return [ + hash & 255, + (hash >> 8) & 255, + (hash >> 16) & 255, + 0.8, // make the colors a little lighter + ]; + }, + + rgbToCss: function(rgb) { + return `rgb(${rgb[0]}, ${rgb[1]}, ${rgb[2]}, ${rgb[3]})`; + }, + + rgbToLuminance: function(rgb) { + // https://en.wikipedia.org/wiki/Relative_luminance + return (0.2126 * rgb[0] + 0.7152*rgb[1] + 0.0722*rgb[2])/rgb[3]; + }, + + getTagElement: function(string, color_overrides) { + let rgb = color_overrides?.[string] || Proxmox.Utils.stringToRGB(string); + let bgcolor = Proxmox.Utils.rgbToCss(rgb); + let txtCls = Proxmox.Utils.rgbToLuminance(rgb) < 160 ? 'light' : 'dark'; + let cls = `proxmox-tag-${txtCls}`; + return `<span class="${cls}" style="background-color: ${bgcolor};">${string}</span>`; + }, }, singleton: true, diff --git a/src/css/ext6-pmx.css b/src/css/ext6-pmx.css index 1d815c6..7c01d2f 100644 --- a/src/css/ext6-pmx.css +++ b/src/css/ext6-pmx.css @@ -6,6 +6,58 @@ background-color: LightYellow; } +.proxmox-tags-full .proxmox-tag-light, +.proxmox-tags-full .proxmox-tag-dark { + border-radius: 9px; + padding: 1px 8px; + margin: 0px 1px; +} + +.proxmox-tags-circle .proxmox-tag-light, +.proxmox-tags-circle .proxmox-tag-dark { + margin: 0px 1px; + position: relative; + top: 2px; + border-radius: 6px; + height: 12px; + width: 12px; + display: inline-block; + color: transparent; + overflow: hidden; +} + +.proxmox-tags-none .proxmox-tag-light, +.proxmox-tags-none .proxmox-tag-dark { + display: none; +} + +.proxmox-tags-dense .proxmox-tag-light, +.proxmox-tags-dense .proxmox-tag-dark { + width: 5px; + display: inline-block; + color: transparent; + overflow: hidden; + vertical-align: bottom; +} + +.proxmox-tags-full .proxmox-tag-light { + color: #fff; + background-color: #383838; +} + +.proxmox-tags-full .proxmox-tag-light span::selection { + background-color: #000; +} + +.proxmox-tags-full .proxmox-tag-dark { + color: #000; + background-color: #f0f0f0; +} + +.proxmox-tags-full .proxmox-tag-dark span::selection { + background-color: #FFF; +} + .x-mask-msg-text { text-align: center; } -- 2.30.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel