ngx-string-to-css-color
An angular 2 library that lets you obtain css colors (hexadecimal code) from strings of text using hash functions. Different text inputs will give you different colors, which makes it a great tool to visualize different tags or text strings. It relies on the javascript library string-to-hex-code-color. Here is an example of what you can do:
Bug-reports or feature request as well as any other kind of feedback is highly welcome!
Check the live demo here!!
To install the package just use:
npm install ngx-string-to-css-color -S
And add it as a dependency to your main module
;
Using the library is easy. You can use the service StringToColorService
or the custom tags with the angular selector tag-with-background-from-text
.
Obtain an string with StringToColorService
If you inject the service
;...constructor public stringToColorService : StringToColorService
you will see that it transforms any string into a css color that you can later use in your code, For instance
;console.logcolor;
gives you
#4c52f6
which is
You can change the shade by adding a second parameter:
;console.logcolor;
obtaining the darker color
#3d42c5
If you change the input text, your the retrieved color will change, for instance this.stringToColorService.stringToColor("sample test22");
will give you ´´#c0868f´´ which is
tag-with-background-from-text
Use the custom tag The component tag-with-background-from-text can be used to obtain a chip tag that assings its background color from the text inside
you can change the shade using also the directive applyShade="-0.2"
.
```