mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
added rgb utils
This commit is contained in:
parent
7387fcfe20
commit
2dc5abd65f
11
packages/app/src/utils/hexToRGB/index.js
Normal file
11
packages/app/src/utils/hexToRGB/index.js
Normal 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})`
|
||||
}
|
16
packages/app/src/utils/rootVarHexToRGBValues/index.js
Normal file
16
packages/app/src/utils/rootVarHexToRGBValues/index.js
Normal 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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user