control the tag colors? - Pulse

Home Forums Pulse control the tag colors?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #111955

    M S
    Participant

    The formatting has a TAG option.
    Is there any way to control the colors used on a specific test string?

    #111957

    John Dempster
    Keymaster

    Hi,

    The colours are based on a hash of the text using the code below. We haven’t thought of a reasonable way to expose these tags for customization as they don’t use a palette. Your best option may be to generate a similar span tag yourself but setting your own colours programmatically.

    
    <span class='bp4-tag .modifier' style='background-color:" + stringToColour(value) + "'>" + value + "</span>"
    
     private static stringToColour(str: string) {
    	 let hash = 0;
    	 let i = 0;
    	 for (i = 0; i < str.length; i++) {
    		 hash = str.charCodeAt(i) + ((hash << 5) - hash);
    	 }
    	 let colour = '#';
    	 for (i = 0; i < 3; i++) {
    		 const value = (hash >> (i * 8)) & 0xFF;
    		 colour += ('00' + value.toString(16)).substr(-2);
    	 }
    	 return colour + "AA";
     }
     
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.