1.0.2 • Published 6 years ago

ngx-string-to-css-color v1.0.2

Weekly downloads
40
License
-
Repository
-
Last release
6 years ago

npm version Build Status

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:

npm.io

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

import { NgxStringToCssColorModule} from "ngx-string-to-css-color";

@NgModule({
  imports: [
    NgxStringToCssColorModule,
  ],
})
export class AppModule { }

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

import { StringToColorService} from 'ngx-string-to-css-color';
...
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

const color = this.stringToColorService.stringToColor("sample test");
console.log(color);

gives you

#4c52f6

which is

npm.io

You can change the shade by adding a second parameter:

const color = this.stringToColorService.stringToColor("sample test",'-0.2');
console.log(color);

obtaining the darker color

#3d42c5

npm.io

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

npm.io

Use the custom tag tag-with-background-from-text

The component tag-with-background-from-text can be used to obtain a chip tag that assings its background color from the text inside

<tag-with-background-from-text [text]="'sample test'"></tag-with-background-from-text>

npm.io

you can change the shade using also the directive applyShade="-0.2".

<tag-with-background-from-text [text]="'sample test'" applyShade="-0.2"></tag-with-background-from-text>```

npm.io

##More examples

npm.io

1.0.2

6 years ago

1.0.0

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago