This repository has been archived on 2024-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
p61-project/presentation/presenters/utils/colors.ts

25 lines
578 B
TypeScript

interface GetColorRGBAFromHexOptions {
hexColor: string
opacity: number
}
export const getColorRGBAFromHex = (
options: GetColorRGBAFromHexOptions,
): string => {
const { hexColor, opacity } = options
let hex = hexColor.replace("#", "")
if (hex.length === 3) {
hex = hex
.split("")
.map((char) => {
return char + char
})
.join("")
}
const color = Number.parseInt(hex, 16)
const red = (color >> 16) & 255
const green = (color >> 8) & 255
const blue = color & 255
return `rgba(${red}, ${green}, ${blue}, ${opacity})`
}