@@ -2,6 +2,7 @@ import TagHashtagType from "discourse/lib/hashtag-types/tag";
22import { iconHTML } from "discourse/lib/icon-library" ;
33import { withPluginApi } from "discourse/lib/plugin-api" ;
44import { defaultRenderTag } from "discourse/lib/render-tag" ;
5+ import { contrastColor } from "../lib/colors" ;
56
67function iconTagRenderer ( tag , params ) {
78 // Get the rendered default tag markup.
@@ -19,7 +20,7 @@ function iconTagRenderer(tag, params) {
1920
2021 // Update the tag markup with an SVG icon, and inline-styles for the colors.
2122 if ( tagIconItem ) {
22- const [ , iconName , color1 , color2 ] = tagIconItem . split ( "," ) ;
23+ const [ , iconName , color ] = tagIconItem . split ( "," ) ;
2324
2425 const parser = new DOMParser ( ) ;
2526 const tagElement = parser . parseFromString ( renderedTag , "text/html" ) . body
@@ -31,8 +32,8 @@ function iconTagRenderer(tag, params) {
3132
3233 tagElement . prepend ( iconElement ) ;
3334 tagElement . classList . add ( "discourse-tag--tag-icons-style" ) ;
34- tagElement . style . setProperty ( "--color1" , color1 ?? "inherit " ) ;
35- tagElement . style . setProperty ( "--color2" , color2 ?? "inherit ") ;
35+ tagElement . style . setProperty ( "--color1" , color ?? "" ) ;
36+ tagElement . style . setProperty ( "--color2" , color ? contrastColor ( color ) : " ") ;
3637
3738 return tagElement . outerHTML ;
3839 }
@@ -56,7 +57,11 @@ class TagHashtagTypeWithIcon extends TagHashtagType {
5657 newIcon . classList . add ( "hashtag-tag-icon" ) ;
5758 newIcon . innerHTML = svgIcon ;
5859 if ( opt . color ) {
59- newIcon . style . color = opt . color ;
60+ newIcon . style . setProperty ( "--color1" , opt . color ?? "" ) ;
61+ newIcon . style . setProperty (
62+ "--color2" ,
63+ opt . color ? contrastColor ( opt . color ) : ""
64+ ) ;
6065 }
6166 return newIcon . outerHTML ;
6267 }
@@ -74,34 +79,30 @@ export default {
7479 withPluginApi ( ( api ) => {
7580 api . replaceTagRenderer ( iconTagRenderer ) ;
7681
77- /** @type {Record<string, { icon: string; color?: string; backgroundColor?: string; }? > } */
82+ /** @type {Record<string, { icon: string, color?: string } > } */
7883 const tagsMap = { } ;
7984
8085 const tagIconList = settings . tag_icon_list . split ( "|" ) ;
8186
8287 tagIconList . forEach ( ( tagIcon ) => {
83- const [ tagName , icon , color , backgroundColor ] = tagIcon . split ( "," ) ;
88+ const [ tagName , prefixValue , prefixColor ] = tagIcon . split ( "," ) ;
8489
85- if ( tagName && icon ) {
86- // Sidebar section links
90+ if ( tagName && prefixValue ) {
8791 if ( api . registerCustomTagSectionLinkPrefixIcon ) {
8892 api . registerCustomTagSectionLinkPrefixIcon ( {
8993 tagName,
90- prefixValue : icon ,
91- prefixColor : color ,
94+ prefixValue,
95+ prefixColor,
9296 } ) ;
9397 }
9498
95- // Everywhere else;
9699 tagsMap [ tagName ] = {
97- icon,
98- color,
99- backgroundColor,
100+ icon : prefixValue ,
101+ color : prefixColor ,
100102 } ;
101103 }
102104 } ) ;
103105
104- // Mentions.
105106 if ( api . registerHashtagType ) {
106107 api . registerHashtagType (
107108 "tag" ,
0 commit comments