Last active
November 16, 2020 08:39
-
-
Save mkhoussid/6998dc0a9424332d6c154c6143212f06 to your computer and use it in GitHub Desktop.
Convert Hex color to RGBA format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const hexToRgba = (rgbaColor: string, opacity: number): string => | |
`rgba(${parseInt(rgbaColor.substring(1, 3), 16)}, ${parseInt(rgbaColor.substring(3, 5), 16)}, ${parseInt( | |
rgbaColor.substring(5, 7), | |
16, | |
)}, ${opacity})`; | |
// example usage: | |
// hexToRgba(#FFFFFF, 0.5) -> 'rgba(255, 255, 255, 0.5)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment