dappconnect-chat-sdk/packages/components/utils/get-color-with-opacity.ts
marcelines 36538591ce
[website] Custom tags (#409)
* feat: change tags component and add util to get color with opacity

* feat: change some tags for the example purpose

* fix: some issues and code organization

* feat: removes complexity from the code and uses css color-mix function
2023-06-06 13:46:54 +02:00

19 lines
610 B
TypeScript

/**
* Gets the color with opacity based on the original color and opacity value
* @param color - the original color
* @param opacity - the opacity value
* @returns the color with opacity
**/
function getColorWithOpacity(color: string, opacity: number): string {
// Ensure the opacity value is within the valid range of 0 to 1
const clampedOpacity = Math.max(0, Math.min(1, opacity)) * 100
// Construct the color string with opacity using CSS color-mix function
const newColor = `color-mix(in srgb, ${color} ${clampedOpacity}%, transparent);`
return newColor
}
export { getColorWithOpacity }