status-web/packages/components/utils/get-color-with-opacity.ts
Felicio Mununga 15b146fab6
use tamagui functional variants for Tag color (#453)
* use tamagui fn variant

* rm get-custom-styles.ts

* assert type

* add changeset

* add customisations colors

* u

* Update tag.tsx

Co-authored-by: Pavel Prichodko <14926950+prichodko@users.noreply.github.com>
2023-07-02 22:57:40 +01:00

19 lines
609 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 }