contrast-color icon indicating copy to clipboard operation
contrast-color copied to clipboard

TypeScript: Could not find a declaration file for module 'contrast-color', it implicitly has an 'any' type.

Open mykhailo-space44 opened this issue 4 years ago • 3 comments

mykhailo-space44 avatar Jun 23 '21 12:06 mykhailo-space44

Typings would be a great addition

Tyler-V avatar Sep 09 '21 03:09 Tyler-V

Anyone coming from the Angular realm, you can import this library at the top of your file using:

declare var require: any;
const ContrastColor = require('contrast-color');

Call it from your template using,

getContrastColor(bgColor: string) {
  return ContrastColor.contrastColor({ bgColor });
}
<div class="label" [style.backgroundColor]="label.color" [style.color]="getContrastColor(label.color)" *ngFor="let label of task.labels">
  {{ label.title }}
</div>

Tyler-V avatar Sep 09 '21 04:09 Tyler-V

Looks like typings were added at some point :)

https://www.npmjs.com/package/@types/contrast-color

import ContrastColor from 'contrast-color';

return ContrastColor.contrastColor({ bgColor });

Tyler-V avatar Jan 02 '24 22:01 Tyler-V