added rgb utils

This commit is contained in:
SrGooglo 2023-04-04 10:49:08 +00:00
parent 7387fcfe20
commit 2dc5abd65f
2 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,11 @@
export default (hex, alpha) => {
const r = parseInt(hex.slice(1, 3), 16)
const g = parseInt(hex.slice(3, 5), 16)
const b = parseInt(hex.slice(5, 7), 16)
if (alpha) {
return `rgba(${r}, ${g}, ${b}, ${alpha})`
}
return `rgb(${r}, ${g}, ${b})`
}

View File

@ -0,0 +1,16 @@
export default (rootVar) => {
const rootVarValue = getComputedStyle(document.documentElement).getPropertyValue(rootVar)
let result = rootVarValue
if (rootVarValue.startsWith("#")) {
// Convert hex to rgb values
const r = parseInt(rootVarValue.slice(1, 3), 16)
const g = parseInt(rootVarValue.slice(3, 5), 16)
const b = parseInt(rootVarValue.slice(5, 7), 16)
result = `${r}, ${g}, ${b}`
}
return result
}