( name: string, convertColorFromTailwindToHex = true )
| 63 | * @returns |
| 64 | */ |
| 65 | export const callCssVariable = ( |
| 66 | name: string, |
| 67 | convertColorFromTailwindToHex = true |
| 68 | ) => { |
| 69 | const value = getComputedStyle(document.documentElement) |
| 70 | .getPropertyValue(name) |
| 71 | .trim(); |
| 72 | if (convertColorFromTailwindToHex) { |
| 73 | const matches = value.match(/^(\d+) (\d+) (\d+)$/); |
| 74 | if (matches) { |
| 75 | const r = parseInt(matches[1], 10); |
| 76 | const g = parseInt(matches[2], 10); |
| 77 | const b = parseInt(matches[3], 10); |
| 78 | return rgbToHex(r, g, b); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | return value; |
| 83 | }; |
no test coverage detected